All tasks
Mediumarraysloops

Matrix Diagonal Sums

Time limit 2 s · Memory 64 MBAcceptance: —Solved by: 0

Statement

The first line contains n. Each of the next n lines contains n integers — an n×n matrix. Print two numbers on one line separated by a space: the sum of the main diagonal (top-left to bottom-right) and the sum of the anti-diagonal (top-right to bottom-left).

Examples

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

Constraints

  • 1 ≤ n ≤ 300
  • -10^9 ≤ element ≤ 10^9
Solve this task to unlock the editorial.

AI tutor

Stuck? Get a nudge — the tutor explains the idea, it never hands you the solution.