Under construction

Still being built. Things may change

Domino on Torus

Time limit2sMemory limit1024 MB

Summary
Count the valid white-black domino tilings of the outer surface of an A by B torus with a C by D rectangular hole cut out.
Level

Hard8 of 10

Topics
Combinatorics, Math
Solved
No attempts yet

Problem

Imagine a stretchable square paper. Cut a rectangle of size A×BA \times B along the grid lines. All squares are numbered from 1 to A⋅BA \cdot B. From this rectangle, cut another rectangle of size C×DC \times D along the grid lines, so that the sides of length CC are parallel to the sides of length AA. Then glue the sides of length BB together, and finally glue the sides of length AA together. The result is a torus with a rectangular hole of C×DC \times D squares. (A torus is the surface of a bagel.)

The squares of the torus are considered different if they have different numbers.

We now tile the external surface of the torus with the hole using stretchable dominoes. Each domino consists of two squares of two different colors, one white and one black, that share a common side.

The tiling must satisfy this condition: if two squares of the torus that are adjacent by side belong to different dominoes, they must be the same color, both white or both black.

Two tilings are different if at least one of the following holds:

  1. at least one square of the torus is white in one tiling and black in the other;
  2. at least one square is covered by a domino whose other square is Y1Y_1 in one tiling and Y2Y_2 in the other, with Y1≠Y2Y_1 \ne Y_2.

Input

The first line of input contains four integers AA, BB, CC and DD (4≤A,B≤1094 \le A, B \le 10^9, 2≤C<A2 \le C < A, 2≤D<B2 \le D < B, all numbers are even).

Output

Output the number of tilings.

Hint

The following picture shows one of the possible tilings in the given example.

Examples1

  1. Example 1

    Input
    4 6 2 4
    
    Expected output
    4