G - AtCoder Wallpaper Editorial /

Time Limit: 2 sec / Memory Limit: 1024 MiB

配点 : 450

問題文

AtCoder 社の壁紙の模様を xy 平面上に表現すると、以下のようになります。

  • 以下の 3 種類の直線で領域が分割されている。
    • x = n (n は整数)
    • y = n (n は偶数)
    • x + y = n (n は偶数)
  • 各領域は白もしくは黒で塗られている。いずれかの直線で隣接する 2 領域は異なる色で塗られている。
  • (0.5, 0.5) を含む領域は黒で塗られている。

下の図は、模様の一部を表したものです。

整数 A, B, C, D が与えられます。各辺が x, y 軸に平行で、左下の頂点が (A, B) にあり右上の頂点が (C, D) にあるような長方形を考えます。この長方形の内側に存在する黒で塗られた領域の面積を求め、それを 2 倍したものを出力してください。

出力する値は整数になることが証明できます。

制約

  • -10^9 \leq A, B, C, D \leq 10^9
  • A < C かつ B < D
  • 入力はすべて整数

入力

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

A B C D

出力

答えを一行に出力せよ。


入力例 1

0 0 3 3

出力例 1

10

求めるのは、以下の正方形で囲われた領域内の黒く塗られた領域の面積です。

これは 5 なので、 2 倍した 10 を出力します。


入力例 2

-1 -2 1 3

出力例 2

11

面積は 5.5 と小数になりますが、出力するべき値は整数になります。


入力例 3

-1000000000 -1000000000 1000000000 1000000000

出力例 3

4000000000000000000

これは長方形が最大のケースですが、出力は 64bit 符号付き整数の範囲に収まります。

Score : 450 points

Problem Statement

The pattern of AtCoder's wallpaper can be represented on the xy-plane as follows:

  • The plane is divided by the following three types of lines:
    • x = n (where n is an integer)
    • y = n (where n is an even number)
    • x + y = n (where n is an even number)
  • Each region is painted black or white. Any two regions adjacent along one of these lines are painted in different colors.
  • The region containing (0.5, 0.5) is painted black.

The following figure shows a part of the pattern.

You are given integers A, B, C, D. Consider a rectangle whose sides are parallel to the x- and y-axes, with its bottom-left vertex at (A, B) and its top-right vertex at (C, D). Calculate the area of the regions painted black inside this rectangle, and print twice that area.

It can be proved that the output value will be an integer.

Constraints

  • -10^9 \leq A, B, C, D \leq 10^9
  • A < C and B < D.
  • All input values are integers.

Input

The input is given from Standard Input in the following format:

A B C D

Output

Print the answer on a single line.


Sample Input 1

0 0 3 3

Sample Output 1

10

We are to find the area of the black-painted region inside the following square:

The area is 5, so print twice that value: 10.


Sample Input 2

-1 -2 1 3

Sample Output 2

11

The area is 5.5, which is not an integer, but the output value is an integer.


Sample Input 3

-1000000000 -1000000000 1000000000 1000000000

Sample Output 3

4000000000000000000

This is the case with the largest rectangle, where the output still fits into a 64-bit signed integer.