IntermediateRating 1200
Falling Path
In an n × n grid, start anywhere in the top row. Each step goes down to the cell directly below or diagonally below-left or below-right. Print the smallest sum of a path to the bottom row.
Input
n, then n rows.
Output
One integer.
Sample 1
Input
3 2 1 3 6 5 4 7 8 9
Output
13
Sample 2
Input
2 -19 57 -40 -5
Output
-59
Output appears here