#C6459. Special Matrix Sum

    ID: 50221 Type: Default 1000ms 256MiB

Special Matrix Sum

Special Matrix Sum

You are given an ( m \times n ) matrix. Your task is to compute the sum of all the elements in the matrix for which the row and column indices (0-indexed) are either both even or both odd. In other words, if an element is located at row ( i ) and column ( j ), include it in the sum if (i \equiv j ; (\mathrm{mod}; 2)).

For instance, in the matrix below:

( \begin{bmatrix} 1 & 2 & 3 \ 4 & 5 & 6 \ 7 & 8 & 9 \end{bmatrix} )

The positions that satisfy the condition are ((0,0)), ((0,2)), ((1,1)), ((2,0)), and ((2,2)), and the sum of these elements is (1 + 3 + 5 + 7 + 9 = 25).

inputFormat

The first line contains two integers ( m ) and ( n ) representing the number of rows and columns of the matrix, respectively. This is followed by ( m ) lines, each containing ( n ) integers separated by spaces, representing the rows of the matrix.

outputFormat

Output a single integer which is the sum of all elements in the matrix where the row and column indices have the same parity (i.e. both even or both odd).## sample

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