#abc227f. [abc227_f]Treasure Hunting
[abc227_f]Treasure Hunting
Problem Statement
We have a grid with horizontal rows and vertical columns. Let denote the square at the -th row from the top and -th column from the left. contains an integer .
Takahashi will depart and repeatedly move one square right or down until reaching . It is not allowed to exit the grid.
The cost of this travel is defined as:
the sum of the greatest integers among the integers written on the squares traversed.
Find the minimum possible cost.
Constraints
- All values in input are integers.
Input
Input is given from Standard Input in the following format:
Output
Print the answer.
Sample Input 1
Sample Output 1
There is only one way to travel, where the traversed squares contain the integers , , from largest to smallest, so we print .
Sample Input 2
Sample Output 2
The minimum cost is achieved by traversing , , in this order.