A - Adjacent Squares 解説 /

実行時間制限: 2 sec / メモリ制限: 1024 MB

配点 : 100

問題文

H 行、横 W 列のマス目があり、このうち上から i 個目、左から j 個目のマスを (i,j) と呼びます。
このとき、マス (R,C) に辺で隣接するマスの個数を求めてください。

ただし、ある 2 つのマス (a,b),(c,d) が辺で隣接するとは、 |a-c|+|b-d|=1 (|x|x の絶対値とする) であることを言います。

制約

  • 入力は全て整数
  • 1 \le R \le H \le 10
  • 1 \le C \le W \le 10

入力

入力は以下の形式で標準入力から与えられる。

H W
R C

出力

答えを整数として出力せよ。


入力例 1

3 4
2 2

出力例 1

4

入出力例 1,2,3 に対する説明は、出力例 3 の下にまとめて示します。


入力例 2

3 4
1 3

出力例 2

3

入力例 3

3 4
3 4

出力例 3

2

H=3,W=4 のとき、マス目は以下のようになります。

  • 入力例 1 について、マス (2,2) に隣接するマスは 4 つです。
  • 入力例 2 について、マス (1,3) に隣接するマスは 3 つです。
  • 入力例 3 について、マス (3,4) に隣接するマスは 2 つです。


入力例 4

1 10
1 5

出力例 4

2

入力例 5

8 1
8 1

出力例 5

1

入力例 6

1 1
1 1

出力例 6

0

Score : 100 points

Problem Statement

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

Output

Print the answer as an integer.


Sample Input 1

3 4
2 2

Sample Output 1

4

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


Sample Input 2

3 4
1 3

Sample Output 2

3

Sample Input 3

3 4
3 4

Sample 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).


Sample Input 4

1 10
1 5

Sample Output 4

2

Sample Input 5

8 1
8 1

Sample Output 5

1

Sample Input 6

1 1
1 1

Sample Output 6

0