#C13089. Diagonal Sum of a Square Matrix
Diagonal Sum of a Square Matrix
Diagonal Sum of a Square Matrix
You are given a square matrix of integers. The task is to calculate the sum of both the primary diagonal and the secondary diagonal of the matrix. In the primary diagonal, the elements are those where the row index equals the column index; in the secondary diagonal, the elements are those where the column index equals \(n-1-i\), where \(n\) is the order of the matrix and \(i\) is the row index (0-based). Note that if the matrix is 1×1, the single element should be counted twice.
Input: The first line contains an integer \(n\) representing the size of the matrix. Each of the following \(n\) lines contains \(n\) space-separated integers, representing the rows of the matrix.
Output: Output a single integer which is the sum of the primary and secondary diagonals.
inputFormat
The first line contains a single integer \(n\) (\(1 \leq n \leq 100\)), indicating the size of the square matrix. The next \(n\) lines each contain \(n\) space-separated integers, where each integer is between \(-10^9\) and \(10^9\).
outputFormat
Output a single integer, the sum of the two diagonals of the matrix.
## sample3
1 2 3
4 5 6
7 8 9
30