SDE Path

Trace of a Matrix

Easy

Trace of a Matrix

Compute the trace, the sum of the main diagonal of a square grid.

Input format

The first line has two integers R and C (with R = C, a square matrix). Each of the next R lines has C space-separated integers describing one row.

Output format

Print the trace of the matrix: the sum of the elements on the main diagonal.

Constraints

  • Values fit in a 64-bit signed integer
  • Trailing whitespace and a trailing newline are ignored by the judge

Read from stdin, write to stdout. Sample cases below show the exact format.

Sample cases

Example 1
Input
2 2
5 1
1 5
Expected output
10
Example 2
Input
3 3
2 0 0
0 3 0
0 0 4
Expected output
9