#C2990. Minimum Delivery Cost

    ID: 46367 Type: Default 1000ms 256MiB

Minimum Delivery Cost

Minimum Delivery Cost

You are given an \( n \times n \) grid where each cell has a cost associated with it. You need to compute the minimum cost to travel from the top-left cell (i.e., \( (1,1) \)) to the bottom-right cell (i.e., \( (n,n) \)). At each step, you can either move right or down. The recurrence relation used for dynamic programming is given by:

\( dp[i][j] = \min(dp[i-1][j],\; dp[i][j-1]) + grid[i][j] \)

Your task is to implement a program that reads input from stdin and outputs the minimum delivery cost to stdout.

inputFormat

The first line of input contains an integer \( n \) representing the size of the grid. The next \( n \) lines each contains \( n \) space-separated integers representing the cost at each cell of the grid.

outputFormat

Output a single integer which is the minimum cost to travel from the top-left to the bottom-right cell of the grid.

## sample
3
1 3 1
1 5 1
4 2 1
7