Sum of neighbors
Execution time limit is 1 second
Runtime memory usage limit is 128 megabytes
In a square area of size , cells are numbered sequentially from to from the top row to the bottom, from left to right in each row.
Nyasyr stands in the cell with number in this area and wants to find the sum of the numbers of all neighboring cells. Help Nyasyr with this task.
Note that each cell can have no more than neighbors directly above, below, to the left, and to the right.
Below is an example with and .
Here Nyasyr stands on the cell with number , and neighboring cells are marked with circles. In this case, there is no neighbor on the right.
Input
Two integers and .
Output
Print the sum of the numbers of all neighboring cells of the given cell.
Examples
Input #1
Answer #1
Input #2
Answer #2
Submissions 853
Acceptance rate 38%