#C11638. Diagonal Difference

    ID: 40976 Type: Default 1000ms 256MiB

Diagonal Difference

Diagonal Difference

You are given a square matrix of size \( N \times N \). Your task is to compute the absolute difference between the sums of its primary and secondary diagonals.

The primary diagonal of a matrix \( A \) is defined as the set of elements \( A_{i,i} \) with \( i=0,1,\dots,N-1 \), and the secondary diagonal is defined as \( A_{i, N-i-1} \). The goal is to calculate and output the value \( |\sum_{i=0}^{N-1}A_{i,i} - \sum_{i=0}^{N-1}A_{i,N-i-1}| \).

Read the input from standard input (stdin) and write the result to standard output (stdout).

inputFormat

The input is provided via standard input (stdin) and has the following format:

  • The first line contains a single integer ( N ) denoting the size of the matrix.
  • Each of the next ( N ) lines contains ( N ) space-separated integers representing the rows of the matrix.

outputFormat

Output a single integer: the absolute difference between the sum of the primary diagonal and the sum of the secondary diagonal.## sample

3
11 2 4
4 5 6
10 8 -12
15