#31 - Matrix Diagonal Sum

You are given a square matrix mat of size n x n. Your task is to calculate the sum of the integers on both diagonals of the matrix.

Example 1

Input

mat = 
[
    [1, 2, 3],
    [4, 5, 6],
    [7, 8, 9]
]

Output

25

Example 2

Input

mat = 
[
    [1, 1, 1, 1],
    [1, 1, 1, 1],
    [1, 1, 1, 1],
    [1, 1, 1, 1],
]

Output

8

Last updated