Skip to main content
Tuesday (24.11.2026) at 20:00: ALGOR Contest: Round #4 (Special Challenge) starts!

~/algor $ cat problems/matritsa-yordamchi-diagonal-yigindisi

Anti-diagonal sum

Easy 1000 ms 128 MB 28%
Share

A square matrix of size $n \times n$ is given. Compute the sum of the elements on its anti-diagonal (secondary diagonal):

$$S = \sum_{i=1}^{n} a_{i, n - i + 1}$$

The sum of the anti-diagonal elements of a square matrix

Input

The first line contains two equal positive integers $n$ and $n$. Each of the next $n$ lines contains $n$ integers.

Output

One integer — the sum of the anti-diagonal elements.

Note

$1 \le n \le 200$
$-1000 \le a_{i,j} \le 1000$

Examples

Input #1
3 3
1 2 3
4 5 6
7 8 9
Output #1
15
Input #2
2 2
1 2
3 4
Output #2
5

Sign in to submit a solution

Signing up is free and takes a minute.