#P11566. Red and Blue Rectangular XOR Puzzle

    ID: 13657 Type: Default 1000ms 256MiB

Red and Blue Rectangular XOR Puzzle

Red and Blue Rectangular XOR Puzzle

There is an \(n \times m\) chessboard initially filled with zeros. Two types of moves are allowed:

  • Red move: Choose a cell \((i,j)\) such that a rectangle of size \(a \times b\) with its top‐left corner at \((i,j)\) lies entirely inside the board. Then, for every cell in that rectangle, toggle its value (i.e. perform an XOR with 1).
  • Blue move: Choose a cell \((i,j)\) such that a rectangle of size \(c \times d\) with its top‐left corner at \((i,j)\) lies entirely inside the board. Then, for every cell in that rectangle, toggle its value.

You may apply these moves arbitrarily many times (in any order, and possibly repeating moves). Two sequences of moves are considered equivalent if they produce the same final board configuration. Your task is to determine how many different board configurations can be obtained using these moves. Since the answer can be quite large, output it modulo \(10^9+7\).

Hint: The moves are performed over \(\mathbb{F}_2\) (i.e. modulo 2), so the effect of a sequence of moves is equivalent to a sum (XOR) of the individual moves. It turns out that using only red moves one can obtain exactly \(2^{(n-a+1)(m-b+1)}\) distinct boards, and using only blue moves one can obtain \(2^{(n-c+1)(m-d+1)}\) distinct boards. Their combined effect produces a subspace of dimension
\( (n-a+1)(m-b+1) + (n-c+1)(m-d+1) - (n-\max(a,c)+1)(m-\max(b,d)+1) \). Thus, the answer is

\(2^{(n-a+1)(m-b+1) + (n-c+1)(m-d+1) - (n-\max(a,c)+1)(m-\max(b,d)+1)} \mod (10^9+7)\).

inputFormat

The input consists of a single line containing six space‐separated integers:

  1. \(n\) and \(m\): the dimensions of the board.
  2. \(a\) and \(b\): the dimensions of the red rectangle.
  3. \(c\) and \(d\): the dimensions of the blue rectangle.

You can assume that \(1 \le a, c \le n\) and \(1 \le b, d \le m\) so that the moves are always defined.

outputFormat

Output a single integer: the number of distinct board configurations that can be obtained, modulo \(10^9+7\).

sample

2 2 1 1 1 1
16