Domino on Torus
Time limit2sMemory limit1024 MB
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 along the grid lines. All squares are numbered from 1 to . From this rectangle, cut another rectangle of size along the grid lines, so that the sides of length are parallel to the sides of length . Then glue the sides of length together, and finally glue the sides of length together. The result is a torus with a rectangular hole of 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:
- at least one square of the torus is white in one tiling and black in the other;
- at least one square is covered by a domino whose other square is in one tiling and in the other, with .
Input
The first line of input contains four integers , , and (, , , all numbers are even).
Output
Output the number of tilings.
Hint
The following picture shows one of the possible tilings in the given example.
