Happy Danylo
Limits: 2 sec., 256 MiB
Danylo has just finished his classes. He is very tired today, so he wants to leave the university as soon as possible and go for a walk to a park.
The university can be imagined as an \(n \times m\) matrix. Danylo is in the upper left corner and the exit is in the lower right one. As Danylo wants to escape from the university, he moves only right and down.
Danylo has many friends and lecturers he knows in the university. When he meets them in cell \((i, j)\) he gets \(a_{i j}\) points of happiness.
Danylo finds making more than \(k\) consecutive steps to the same direction boring.
How happy can Danylo be after leaving the university provided he doesn’t make more than \(k\) consecutive steps to the same direction?
Input
The first line contains three integers \(n\), \(m\), \(k\) — number of rows and columns in the matrix and maximum number of consecutive steps to the same direction.
The next \(n\) lines contain \(m\) integers each — how many happiness points Danylo gets if visits this part of university.
Output
In the single line print the only integer — maximum happiness.
Constraints
\(1 \le n, m, k \le 10^3\),
\(|a_{i j}| \le 10^9\),
it is guaranteed that at least one valid path exists.
Samples
| Input (stdin) | Output (stdout) |
|---|---|
| 5 5 2 1 4 2 5 3 4 1 3 2 4 15 2 3 4 5 1 3 4 6 -5 -2 4 5 1 3 | 39 |
Notes
Some lecturers are pretty boring so when he meets them his happiness can decrease.
| Element Type | Created | Who | Problem | Compiler | Result | Time (sec.) | Memory (MiB) | # | Actions |
|---|