A hostel corridor has
Find the minimum total painting cost.
The twist: choosing the cheapest color for the current room may block a better choice for the next room.
The first line contains an integer KaTeX can only parse string typed expression — the number of rooms.
Each of the next KaTeX can only parse string typed expression lines contains three integers KaTeX can only parse string typed expression, KaTeX can only parse string typed expression, and KaTeX can only parse string typed expression — the cost of painting room KaTeX can only parse string typed expression red, green, and blue.
Print a single integer — the minimum total painting cost.
Input
3
17 2 17
16 16 5
14 3 19Output10ExplanationPaint room 1 green, room 2 blue, and room 3 green.
Example 2:
Input
4
7 6 2
5 8 6
7 3 4
9 2 7Output12