#C6507. Max Sum in a Matrix

    ID: 50275 Type: Default 1000ms 256MiB

Max Sum in a Matrix

Max Sum in a Matrix

You are given an \(n \times n\) matrix filled with integers. Your task is to determine the maximum sum among any row, column, or diagonal. Specifically, you need to consider:

  • Rows and Columns: The sum of elements in each row and each column.
  • Main diagonal: The sum of elements where the row index equals the column index, i.e., \(\sum_{i=0}^{n-1} a_{i,i}\).
  • Anti-diagonal: The sum of elements where the row index and column index satisfy \(i+j=n-1\), i.e., \(\sum_{i=0}^{n-1} a_{i, n-1-i}\).

Note that the matrix may contain negative integers. Be sure to handle all cases appropriately.

inputFormat

The input is read from stdin and has the following format:

The first line contains an integer \(n\), representing the dimensions of the matrix.
Each of the next \(n\) lines contains \(n\) space-separated integers, representing a row of the matrix.

outputFormat

Output a single integer to stdout — the maximum sum among all rows, columns, and the two diagonals.

## sample
3
1 2 3
4 5 6
7 8 9
24