Octahedron And Dominoes#1922

Octahedron And Dominoes

1 second
64 megabytes
Easy

Andrew has invented a new puzzle: an octahedron with each triangular face split into n^2 smaller triangles by 3(n-1) lines, n-1 parallel to each side. Some of the small triangles are black, and some are white. The goal is to cover all the white triangles with triangular dominoes (each domino being two adjacent small triangles sharing a side), without overlapping, and to leave all black triangles uncovered.

A domino can cover one small triangle on a face and another on an adjacent face; i.e., it may bend around the edge of the octahedron. Each domino must cover exactly two white small triangles. You cannot cover part of a white triangle with one domino and the rest with another.

How many ways are there to do this?

Input

The first line contains an integer (1 \leq n \leq 4). The next lines describe which small triangles are black or white. Picture the octahedron standing on a vertex, with another vertex pointing at you. The small triangles are organized in horizontal layers. The topmost layer contains triangles (one for each face ending at the top vertex). The next layer contains triangles (three per face), and so on. Each layer increases by triangles, up to 8n - 4 in the middle. The next layer is again 8n - 4 triangles (switching from the upper four faces to the lower four), and then each subsequent layer decreases by triangles, until the bottommost layer has just triangles. The octahedron is given layer by layer, each starting from the leftmost visible triangle (on the four "front" faces), proceeding left to right along the visible portion, then switching to the invisible portion and proceeding back from right to left. Each small triangle is denoted by a dot ('.') for white, or an asterisk ('*') for black.

Output

Output one integer — the number of ways to cover all white triangles of the octahedron with triangular dominoes.

Examples

Example 1

Loading
Loading