cost of a lesson learned; price of a life lesson
Colloquial expression for the price paid (money, time, or trouble) for a valuable lesson, often from a mistake or failure.
I lost a lot of money in a scam, but I think it was a good price for a life lesson.
Think of failure as the cost of learning, and use it for next time.
Compound of 勉強 (study, learning) and 代 (cost, price). The figurative sense likely developed from the idea of paying for one's education through real-world experience.