Felix is on the top of a pyramid! He is trying to climb down to the lowest level, where Zihe is at.
At the top floor of the pyramid, there is way to get down, with a cost of . At the second highest floor of the pyramid, there are ways to get down, each with a cost of and , and so on. Unfortunately, he can only land on adjacent rooms in the floor below him. Can you minimize the cost Felix will take to get to the lowest floor?
For example, in the pyramid:
2
3 4
6 5 7
4 1 8 3
Felix will start at 2, then go to 3, then 5, and finally land on the lowest floor in the room with cost 1. This accumulates a total cost of 11.
Input Specification
The first line of input will contain an integer .
The next lines of input will contain integers, for .
Output Specification
Output a single integer followed by newline, the minimum path Felix will take to reach the bottom floor where Zihe is at.
Constraints
Subtask 1 [30%]
Subtask 2 [70%]
Sample Input 1
4
2
3 4
6 5 7
4 1 8 3
Sample Output 1
11
Comments