#K65567. Matrix Diagonal Sum
Matrix Diagonal Sum
Matrix Diagonal Sum
Given a square matrix \( A \) of size \( n \times n \), your task is to compute the sum of the elements on its main diagonal. The main diagonal of a matrix consists of the elements \( A_{i,i} \) for \( i = 1, 2, \dots, n \).
Example:
Input: 3 1 2 3 4 5 6 7 8 9</p>Output: 15
In the above example, the main diagonal elements are 1, 5, and 9, and their sum is \( 1+5+9=15 \).
inputFormat
The input is read from standard input and has the following format:
- The first line contains a single integer \( n \) which represents the size of the matrix.
- The next \( n \) lines each contain \( n \) space-separated integers representing the rows of the matrix.
outputFormat
Print a single integer to standard output, which is the sum of the elements along the main diagonal of the matrix.
## sample3
1 2 3
4 5 6
7 8 9
15