Problem2302--Adjacent Squares

2302: Adjacent Squares

[Creator : ]
Time Limit : 1.000 sec  Memory Limit : 128 MB

Description

Time Limit: 2 sec / Memory Limit: 1024 MB

Score : 100100 points

Problem Statement

There is a grid with HH horizontal rows and WW vertical columns. Let (i,j)(i,j) denote the square at the ii-th row from the top and the jj-th column from the left.
Find the number of squares that share a side with Square (R, C)(R,C).
Here, two squares (a,b)(a,b) and (c,d)(c,d) are said to share a side if and only if |a-c|+|b-d|=1ac+bd=1 (where |x|x denotes the absolute value of xx).

Constraints

  • All values in input are integers.
  • 1 \le R \le H \le 101RH10
  • 1 \le C \le W \le 101CW10

Input

Input is given from Standard Input in the following format:
HHWWRRCC

Output

Print the answer as an integer.

Sample Input Copy

3 4
2 2

Sample Output Copy

4

HINT

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

  • For Sample Input 11, there are 44 squares adjacent to Square (2,2)(2,2).
  • For Sample Input 22, there are 33 squares adjacent to Square (1,3)(1,3).
  • For Sample Input 33, there are 22 squares adjacent to Square (3,4)(3,4).


Source/Category