Adjacent Squares

AtCoder
IDabc250_a
Time2000ms
Memory256MB
Difficulty
There is a grid with $H$ horizontal rows and $W$ vertical columns. Let $(i,j)$ denote the square at the $i$\-th row from the top and the $j$\-th column from the left. Find the number of squares that share a side with Square $(R, C)$. Here, two squares $(a,b)$ and $(c,d)$ are said to share a side if and only if $|a-c|+|b-d|=1$ (where $|x|$ denotes the absolute value of $x$). ## Constraints * All values in input are integers. * $1 \le R \le H \le 10$ * $1 \le C \le W \le 10$ ## Input Input is given from Standard Input in the following format: $H$ $W$ $R$ $C$ [samples]
Samples
Input #1
3 4
2 2
Output #1
4

We will describe Sample Inputs/Outputs $1,2$, and $3$ at once below Sample Output $3$.
Input #2
3 4
1 3
Output #2
3
Input #3
3 4
3 4
Output #3
2

When $H=3$ and $W=4$, the grid looks as follows.

*   For Sample Input $1$, there are $4$ squares adjacent to Square $(2,2)$.
*   For Sample Input $2$, there are $3$ squares adjacent to Square $(1,3)$.
*   For Sample Input $3$, there are $2$ squares adjacent to Square $(3,4)$.

![image](https://img.atcoder.jp/abc250/abc250a-fig1.png)
Input #4
1 10
1 5
Output #4
2
Input #5
8 1
8 1
Output #5
1
Input #6
1 1
1 1
Output #6
0
API Response (JSON)
{
  "problem": {
    "name": "Adjacent Squares",
    "description": {
      "content": "There is a grid with $H$ horizontal rows and $W$ vertical columns. Let $(i,j)$ denote the square at the $i$\\-th row from the top and the $j$\\-th column from the left.   Find the number of squares that",
      "description_type": "Markdown"
    },
    "platform": "AtCoder",
    "limit": {
      "time_limit": 2000,
      "memory_limit": 262144
    },
    "difficulty": "None",
    "is_remote": true,
    "is_sync": true,
    "sync_url": null,
    "sign": "abc250_a"
  },
  "statements": [
    {
      "statement_type": "Markdown",
      "content": "There is a grid with $H$ horizontal rows and $W$ vertical columns. Let $(i,j)$ denote the square at the $i$\\-th row from the top and the $j$\\-th column from the left.  \nFind the number of squares that...",
      "is_translate": false,
      "language": "English"
    }
  ]
}
Full JSON Raw Segments