#C11786. Sum of Matrix Diagonals

    ID: 41140 Type: Default 1000ms 256MiB

Sum of Matrix Diagonals

Sum of Matrix Diagonals

Given an (N \times N) matrix, compute the sum of the elements on its two diagonals. The primary diagonal consists of elements (a_{i,i}) and the secondary diagonal consists of elements (a_{i,N-i+1}). If an element belongs to both diagonals (which occurs when (N) is odd), count it only once.

For example, consider the matrix:

( \begin{pmatrix} 1 & 2 & 3\ 4 & 5 & 6\ 7 & 8 & 9 \end{pmatrix})

The sum is computed as (1 + 5 + 9) from the primary diagonal and (3 + 5 + 7) from the secondary diagonal. Since the center element (5) is common to both, it is counted only once. Thus, the final sum is (1 + 5 + 9 + 3 + 7 = 25).

inputFormat

The first line contains an integer (N) representing the dimension 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 which is the sum of the elements on both the primary and secondary diagonals.## sample

3
1 2 3
4 5 6
7 8 9
25