Rectangle Coloring

Count the black-or-white colorings of an N by M grid where every X by Y subrectangle contains both colors.

Hard8Dynamic programmingCombinatoricsBit manipulationNo attempts yetTime limit2sMemory limit512 MB

Problem

You have an N×MN \times M grid of 1×11 \times 1 cells. You color every cell black or white. No rectangle of XX rows and YY columns may end up in a single color, so every X×YX \times Y rectangle cut from the grid has to contain at least one black cell and at least one white cell.

Write a program that counts the colorings satisfying this rule.

Input

The first line contains NN, MM, XX, and YY, separated by spaces (1X31 \le X \le 3, 2YM2 \le Y \le M).

The ranges of NN and MM depend on XX.

  • X=1X = 1: 2N1,000,0002 \le N \le 1{,}000{,}000, 2M1,0002 \le M \le 1{,}000
  • X=2X = 2: 2N1,000,0002 \le N \le 1{,}000{,}000, 2M72 \le M \le 7
  • X=3X = 3: 3N83 \le N \le 8, 2M52 \le M \le 5

Output

Print the number of colorings modulo 1,000,000,007 on the first line.