200622: [AtCoder]ARC062 E - Building Cubes with AtCoDeer

Memory Limit:256 MB Time Limit:4 S
Judge Style:Text Compare Creator:
Submit:0 Solved:0

Description

Score : $900$ points

Problem Statement

AtCoDeer the deer has $N$ square tiles. The tiles are numbered $1$ through $N$, and the number given to each tile is written on one side of the tile. Also, each corner of each tile is painted in one of the $1000$ colors, which are represented by the integers $0$ between $999$. The top-left, top-right, bottom-right and bottom-left corner of the tile with the number $i$ are painted in color $C_{i,0}, C_{i,1}, C_{i,2}$ and $C_{i,3}$, respectively, when seen in the direction of the number written on the tile (See Figure $1$).

Figure $1$: The correspondence between the colors of a tile and the input

AtCoDeer is constructing a cube using six of these tiles, under the following conditions:

  • For each tile, the side with the number must face outward.
  • For each vertex of the cube, the three corners of the tiles that forms it must all be painted in the same color.

Help him by finding the number of the different cubes that can be constructed under the conditions. Since each tile has a number written on it, two cubes are considered different if the set of the used tiles are different, or the tiles are used in different directions, even if the formation of the colors are the same. (Each tile can be used in one of the four directions, obtained by $90°$ rotations.) Two cubes are considered the same only if rotating one in the three dimensional space can obtain an exact copy of the other, including the directions of the tiles.

Figure $2$: The four directions of a tile

Constraints

  • $6≦N≦400$
  • $0≦C_{i,j}≦999 (1≦i≦N , 0≦j≦3)$

Input

The input is given from Standard Input in the following format:

$N$
$C_{1,0}$ $C_{1,1}$ $C_{1,2}$ $C_{1,3}$
$C_{2,0}$ $C_{2,1}$ $C_{2,2}$ $C_{2,3}$
$:$
$C_{N,0}$ $C_{N,1}$ $C_{N,2}$ $C_{N,3}$

Output

Print the number of the different cubes that can be constructed under the conditions.


Sample Input 1

6
0 1 2 3
0 4 6 1
1 6 7 2
2 7 5 3
6 4 5 7
4 0 3 5

Sample Output 1

1

The cube below can be constructed.


Sample Input 2

8
0 0 0 0
0 0 1 1
0 1 0 1
0 1 1 0
1 0 0 1
1 0 1 0
1 1 0 0
1 1 1 1

Sample Output 2

144

Sample Input 3

6
0 0 0 0
0 0 0 0
0 0 0 0
0 0 0 0
0 0 0 0
0 0 0 0

Sample Output 3

122880

Input

题意翻译

有N块瓷砖,编号从1到N,并且将这个编号写在瓷砖的正中央;瓷砖的四个角上分别有四种颜色(可能相等可能不想等),并且用$C_{i,0},C_{i,1},C_{i,2},C_{i,3}$分别表示左上、右上、右下、左下的颜色。颜色有1000种,编号从0到999。现在想知道,从这N块瓷砖中选出不同的6块,能围成多少本质不同的合法的立方体。 一个立方体被成为合法的,当且仅当瓷砖有编号的一侧在外面,并且立方体的每个顶点处的三个颜色相同。 注意,由于瓷砖的中间是写着编号的,因此将一个瓷砖旋转90度之后,这个瓷砖会发生变化。 也就是说一块瓷砖可以被用作四个方向(哪怕旋转后四个角的颜色对应相等)。 两个立方体被称作是本质相同的,当且仅当存在在空间中旋转地一个立方体的方式,使得其和第二个立方体一模一样(包括每面瓷砖上编号的方向)。

加入题单

算法标签: