| 10 | using namespace std; |
| 11 | |
| 12 | int main() { |
| 13 | int H, W, ans = 0; |
| 14 | cin >> H >> W; |
| 15 | int A[H][W]; |
| 16 | |
| 17 | for(int i = 0; i < H; i++) |
| 18 | for(int j = 0; j < W; j++) |
| 19 | cin >> A[i][j]; |
| 20 | |
| 21 | // Adding all the left and right surfaces |
| 22 | for(int i = 0; i < H; i++) { |
| 23 | ans += A[i][0]; |
| 24 | for(int j = 0; j < W; j++) { |
| 25 | if(j == W-1) |
| 26 | ans += A[i][j]; |
| 27 | else |
| 28 | ans += abs(A[i][j] - A[i][j+1]); |
| 29 | } |
| 30 | } |
| 31 | |
| 32 | // Adding all the front and back surfaces |
| 33 | for(int j = 0; j < W; j++) { |
| 34 | ans += A[0][j]; |
| 35 | for(int i = 0; i < H; i++) { |
| 36 | if(i == H-1) |
| 37 | ans += A[i][j]; |
| 38 | else |
| 39 | ans += abs(A[i][j] - A[i+1][j]); |
| 40 | } |
| 41 | } |
| 42 | |
| 43 | // Adding the top and bottom surfaces |
| 44 | ans += 2 * (H * W); |
| 45 | |
| 46 | cout << ans << endl; |
| 47 | return 0; |
| 48 | } |