|Little Romeo likes cosmic amoebas a lot. He has a colony of all kinds of amoebas. Recently he received a rectangular table as a gift from his mother. He decided to place one of his amoebas on it. The table is a grid of square 1x1 cells, and each cell is occupied by either matter or antimatter. The usual shape of a cosmic amoeba is a convex set of cells (see explanation below). Romeo can place it on the table as long as every cell of the table is either completely covered by part of the amoeba or completely uncovered, and no part of the amoeba lies outside of the table. It is a well-known fact that cosmic amoebas cannot lie on top of matter, so every cell of the table covered by the amoeba must only contain antimatter. |
A set of cells is called connected if there exists a path between each two cells from the set which satisfies the following restrictions:
A set is called convex if it is satisfies the following conditions:
- All cells in the path belong to this set.
- Each pair of neighboring cells in the path shares a common edge.
- It is connected.
- If any two cells in the set lie in the same row then all cells in that row between them also belong to the set.
- If any two cells in the set lie in the same column then all cells in that column between them also belong to the set.
You are given a String table containing only lowercase hexadecimal digits. Numbers 0-9 are represented by characters '0'-'9', and numbers 10-15 are represented by characters 'a'-'f'.
Each digit in table represents a 2x2 section of the table. For each digit table[i][j], let n be its 4-digit binary representation. From this, you can determine the contents of the following cells:
row 2*i, column 2*j: n
row 2*i, column 2*j+1: n
row 2*i+1, column 2*j: n
row 2*i+1, column 2*j+1: n
where 0 represents antimatter, and 1 represents matter. For example, if table = '5', then its 4-digit binary representation is "0101" (bits are numerated from right to left), and that section of the table looks like this:
| column 0 | column 1 |
row 0 | matter | antimatter |
row 1 | matter | antimatter |
Now Romeo wonders how many ways there are to place a single amoeba on the table. Return this number modulo 1000000007. Two ways are considered different if and only if there is a table cell that is covered in one but not the other.