kule | 프로그래밍의 벗 PivotOJ
PivotOJ

kule

시간 제한: 2000ms메모리 제한: 128MB출처: CHC 2006 National Competition #1 - JuniorsBOJ 1609

문제

Two rooks are to be placed on a chess-like NxN game board. Each square contains a single nonnegative integer. The rooks must be placed on different squares. 

We say that some square on the board is attacked if that square is in the same row or in the same column as one of the rooks. Squares containing the rooks themselves are not considered attacked. 

We want to place our rooks so that the total sum of the numbers on all attacked squares is as large as possible. 

Write a program that will find this maximum sum.

입력

The first line of input contains an integer N, 2 ≤ N ≤ 300. 

Each of the following N lines contains N integers. Each number will be greater than or equal to 0 and less than or equal to 1000. These are the numbers on the board. 

출력

The first and only line of output should contain a single integer – the maximum sum from the task description. 

예제

예제 1

입력
3
0 1 4
3 0 2
1 4 1
출력
15

예제 2

입력
4
0 1 1 1
1 0 4 3
0 1 3 5
0 0 2 5
출력
23

예제 3

입력
5
4 2 2 3 3
4 2 1 4 0
1 3 4 0 1
4 3 0 2 3
0 0 3 0 4
출력
40
코드를 제출하려면 로그인하세요.