106. Diagonal Sum of a Square Board

Acceptance — 0 accepted 0 submissions

Easy
Matrix
No companies listed
On a square game board, special points sit on both diagonals: the main diagonal (top-left to bottom-right) and the other diagonal (top-right to bottom-left).

Find the sum of all cells on both diagonals. If n is odd, the centre cell lies on both, so count it only once.

Input Format
The first line has n.
Each of the next n lines has n integers.

Output Format
Print the diagonal sum.

Constraints
• 1 ≤ n ≤ 100
• -1000 ≤ value ≤ 1000

Example 1

Input
3
1 2 3
4 5 6
7 8 9
Output
25

Explanation 1 + 5 + 9 + 3 + 7 = 25. The centre 5 is counted once.

Example 2

Input
2
1 2
3 4
Output
10

Explanation 1 + 4 + 2 + 3 = 10.

Example 3

Input
1
7
Output
7

Explanation A single cell is on both diagonals, counted once.

Acceptance —
Accepted 0
Submissions 0
Auto-save
Saved Ln 1, Col 1
Submit a solution to see its status here.
Input
Expected Output
25
No results yet
Run your code to test it against the sample cases.
Problem List