Mirko drew a
On each square, he inscribed an integer denoting the value of that square. In the middle of the first row (columns
For instance, if X
) at their starting positions (denoted by L
) are as follows:
OOLLOO
OXXXXO
XXOOXX
XOOOOX
OOOOOO
OOOOOO
In a limited number of moves, Mirko tries to gain the maximum score by the following strategy:
- Before making any moves, Mirko calculates the sum of the values on squares within the lines of sight of the two bishops. That is Mirko's initial score.
- On each turn, Mirko chooses one of the bishops and moves it to a square within its line of sight.
- In its new position, the bishop can now see new squares. The sum of those squares, previously unseen by any of the bishops from the start of the game, is now added to Mirko's score.
Write a program which calculates the maximum score that Mirko can achieve in
Input Specification
The first line of input contains two integers
The following
Output Specification
In a single line of output, print the maximum score that Mirko can achieve.
Scoring
In test cases worth a total of
Sample Input 1
2 0
0 -9 -9 0
0 1 1 0
1 0 0 1
0 0 6 0
Sample Output 1
4
Sample Input 2
2 1
0 -9 -9 0
0 1 1 0
1 0 0 1
0 0 6 0
Sample Output 2
1
Comments