Time limit
2s
Memory limit
128 MB
Sejun is playing a new game where each level asks him to move through a map and collect treasure. The map has N rows and M columns, and each cell contains a number: the amount of treasure in that cell. The top-left cell always contains 0 treasure.
Sejun starts in the top-left cell and completes the following three stages in order.
When Sejun visits a cell for the first time, he collects all treasure in that cell. If he visits the same cell again later, he collects nothing from it. Find the maximum total amount of treasure he can collect across the three stages.
The first line contains two integers N and M, the number of rows and columns of the map. Each of the next N lines contains M integers, where each integer is the amount of treasure in that cell.
N and M are positive integers not greater than 50. Each cell value is a nonnegative integer not greater than 1,000.
Print the maximum total amount of treasure that can be collected. The answer is less than or equal to 2147483647.