P6762 [BalticOI 2010] Lego (Day1)

Description

You are given some $2 \times 2$ LEGO blocks, each of which is colored white (W), gray (G), or black (B). You need to place the blocks onto a $6 \times 6$ baseboard. The placement must not go outside the $6 \times 6$ baseboard, and there must not be any completely floating block (i.e., the four unit squares of that block all have nothing underneath to support them). Now you are given a sketch of one side of the baseboard after all blocks have been placed, and a sketch of the side obtained by rotating this side counterclockwise by $90^\circ$. Compute how many different ways there are to place the blocks.

Input Format

The first line contains an integer $H$, representing the height of the construction. The next $H$ lines each contain six characters, describing the sketch as seen from this side. The next $H$ lines each contain six characters, describing the sketch as seen from the side obtained by rotating the previous side counterclockwise by $90^\circ$. You can only view from the front, back, left, and right sides, and you cannot view from the top or bottom.

Output Format

Output one integer, representing the answer. The answer is guaranteed to fit in a 64-bit signed integer.

Explanation/Hint

#### Explanation for Sample 1 As shown in the figure: ![](https://cdn.luogu.com.cn/upload/image_hosting/njr2rk9l.png) The first one is the sketch observed from side $A$. The second one is the sketch observed from side $B$ (side $A$ rotated counterclockwise by $90^\circ$). Below are these $6$ cases (thanks to Vonov for the pictures!): ![](https://cdn.luogu.com.cn/upload/image_hosting/wymozlif.png) ![](https://cdn.luogu.com.cn/upload/image_hosting/1vw0fu3t.png) ![](https://cdn.luogu.com.cn/upload/image_hosting/umn2hync.png) ![](https://cdn.luogu.com.cn/upload/image_hosting/pykojvay.png) ![](https://cdn.luogu.com.cn/upload/image_hosting/9z9wvzxp.png) ![](https://cdn.luogu.com.cn/upload/image_hosting/hkp3tjfp.png) #### Constraints For $100\%$ of the testdata, $1 \le H \le 6$. #### Note Translated from [BalticOI 2010 Day1 B Lego](https://boi.cses.fi/files/boi2010_day1.pdf)。 Translated by ChatGPT 5