#K86042. Diagonal Difference
Diagonal Difference
Diagonal Difference
Given a square matrix of integers, your task is to compute the absolute difference between the sum of its primary diagonal and the sum of its secondary diagonal.
The primary diagonal of a matrix \(A\) of size \(n \times n\) is defined as \(\sum_{i=0}^{n-1} A_{i,i}\). The secondary diagonal is defined as \(\sum_{i=0}^{n-1} A_{i,n-1-i}\). Your goal is to calculate \(\left|\sum_{i=0}^{n-1} A_{i,i} - \sum_{i=0}^{n-1} A_{i,n-1-i}\right|\).
For example, given the matrix:
1 2 3 4 5 6 7 8 9
the primary diagonal sum is \(1+5+9=15\) and the secondary diagonal sum is \(3+5+7=15\). Thus, the output is \(|15-15| = 0\).
inputFormat
The first line contains a single integer \(n\) representing the number of rows and columns in the square matrix. Each of the following \(n\) lines contains \(n\) space-separated integers representing a row of the matrix.
outputFormat
Output a single integer which is the absolute difference between the sum of the primary diagonal and the sum of the secondary diagonal.
## sample3
1 2 3
4 5 6
7 8 9
0