Time limit
2s
Memory limit
128 MB
There is a square N×N game board. Each cell contains one integer. The top-left cell has coordinates (1, 1), and the bottom-right cell has coordinates (N, N). The first coordinate is the column number, and the second coordinate is the row number.
You want to choose two different cells and place one rook on each of them.
A cell is attacked if at least one rook is in the same row or the same column as that cell. However, a cell that contains a rook is not considered attacked.
Given the numbers on the board, place the two rooks so that the sum of the numbers in all attacked cells is as large as possible. Write a program that computes this maximum sum.
The first line contains an integer N (2 ≤ N ≤ 300).
Each of the next N lines contains N integers, separated by spaces, representing the board. Every number is an integer between 0 and 1,000, inclusive.
Print the maximum possible sum of the numbers in the cells attacked by the two rooks.