#B2101. Matrix Boundary Sum

    ID: 11183 Type: Default 1000ms 256MiB

Matrix Boundary Sum

Matrix Boundary Sum

Given an integer matrix, compute the sum of the boundary elements. The boundary elements are defined as the elements in the first row, the last row, and the first and last columns of the matrix.

Note: In case the matrix has only one row or one column, consider all elements as boundary elements.

inputFormat

The first line contains two integers m and n (number of rows and columns respectively).

The next m lines each contain n integers separated by spaces, representing the matrix.

outputFormat

Output a single integer: the sum of the boundary elements of the matrix.

sample

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