~/algor $ cat problems/matritsa-chetki-elementlar-yigindisi
Sum of border elements
Easy
1000 ms
128 MB
29%
An integer matrix of size $n \times m$ is given. Compute the sum of the elements on its border (in the first and last rows and in the first and last columns). Every element is counted once.
Input
The first line contains two positive integers $n$ and $m$. Each of the next $n$ lines contains $m$ integers.
Output
One integer — the sum of the border elements.
Note
$1 \le n, m \le 200$
$-1000 \le a_{i,j} \le 1000$
Examples
Input #1
3 3 1 2 3 4 5 6 7 8 9
Output #1
40
Input #2
1 3 1 2 3
Output #2
6