cho.sh
Notes
Loading...

Lego

Time limit

1s

Memory limit

128 MB

Problem

You are training an artificial vision system with Lego blocks. Given two pictures of a Lego construction taken from two directions, determine how many different constructions can produce exactly those pictures.

There is only one kind of block in this problem: a block with 2 x 2 studs. Each block has one of three colors: white (W), gray (G), or black (B). There are infinitely many blocks of every color. The base is a square board with 6 x 6 studs. Every block must have its edges parallel to the edges of the base, and no block may extend outside the base. Every block must also be supported by a block below it or by the base.

The left picture shows a valid way to place a block on top of another block. The center picture is invalid because the upper block hangs in the air. The right picture is invalid because the upper block extends outside the base.

Input

The first line contains the height H of the construction. (1 <= H <= 6)

Then H lines follow. Each line has length 6 and describes the construction as seen from one side, direction A in the figure. The j-th character on the i-th line from the top describes what is visible in the j-th vertical column at the i-th height from the top. Each character is one of W, G, B, or .. The letters mean that a block of that color is visible, and . means that no block is visible at that position. Since depth cannot be determined from one direction, a visible color may belong to a block near the front edge or to a block farther back, as long as no other block blocks the view.

After that, another H lines are given in the same format. They show the construction from the direction reached by moving the observer 90 degrees counterclockwise around the construction, direction B in the figure.

Output

Output one line containing the number of different Lego constructions that satisfy both pictures. Even if two different possible constructions can be transformed into each other by rotation or reflection, count them separately when their positions and directions in the input are different. The answer always fits in a signed 64-bit integer.

Hint

One possible construction that satisfies the provided visible test.