Sum of N * N

Replay of 20th IUT Comput...
Limits 1s, 512 MB

You are given a matrix with size N * N. You need to print the summation for each of the rows, followed by each of the columns, followed by the two diagonals (among the diagonals, print major diagonal first, and then minor diagonal), and finally the sum of all values in the matrix.

The problem looks very straightforward, doesn't it? But as you all know that Dr. Bari doesn't like straightforward problems, he makes the problem a bit difficult.

Instead of taking numbers as input, you will be taking English letters (a-z, A-Z) as input to each cell of the matrix. For computation, you will consider the first letter of the English alphabet 'a' or 'A' having the value 1. Subsequent letters will have value 2, 3, ..., 26. (e.g.: 'b' or 'B' as 2, 'c' or 'C' as 3, ..., 'z' or 'Z' as 26).

Input

First line of input will contain the value N (0 < N <100). Following N lines will contain N characters on each line denoting each row of the matrix.

Output

First print the summation for each of the N rows, followed by each of the N columns, followed by the two diagonals (major diagonal sum should be followed by minor diagonal), and finally the sum of all values in the matrix. Each result should be separated by a newline.

Sample

InputOutput
2
b a
r i

3
27
20
10
11
19
30

Input Explanation
2 1
18 9

Output Explanation
2+1 -> 3
18 + 9 -> 27
2 + 18 -> 20
1 + 9 -> 10
2 + 9 -> 11
1 + 18 -> 19
2+ 1 + 18 + 9 -> 30

Submit

Login to submit.

Statistics

90% Solution Ratio
StarscreamEarliest, Oct '19
dip_BRURFastest, 0.0s
StarscreamLightest, 131 kB
mdvirusShortest, 364B
Toph uses cookies. By continuing you agree to our Cookie Policy.