#include <bits/stdc++.h>
using namespace std;

int n;
map<array<int, 4>, int> mp;

int same(array<int, 4> a, array<int, 4> b) {
  int res = 0;
  if (a == array<int, 4>{b[0], b[1], b[2], b[3]}) res++;
  if (a == array<int, 4>{b[1], b[2], b[3], b[0]}) res++;
  if (a == array<int, 4>{b[2], b[3], b[0], b[1]}) res++;
  if (a == array<int, 4>{b[3], b[0], b[1], b[2]}) res++;
  return res;
}

int main() {
  ios::sync_with_stdio(0);
  cin.tie(0), cout.tie(0);

  cin >> n;
  vector<array<int, 4>> up;
  long long ans = 0;

  for (int i = 0; i < n; i++) {
    array<int, 4> c;
    for (int j = 0; j < 4; j++) {
      cin >> c[j];
    }

    for (auto &d : up) {
      array<int, 4> w = {d[0], d[3], c[0], c[3]};
      array<int, 4> x = {d[3], d[2], c[1], c[0]};
      array<int, 4> y = {d[2], d[1], c[2], c[1]};
      array<int, 4> z = {d[1], d[0], c[3], c[2]};

      long long cur = 1;
      cur *= 1ll * mp[w] - same(d, w);
      cur *= 1ll * mp[x] - same(w, x) - same(d, x);
      cur *= 1ll * mp[y] - same(w, y) - same(x, y) - same(d, y);
      cur *= 1ll * mp[z] - same(w, z) - same(x, z) - same(y, z) - same(d, z);
      ans += cur;
    }

    up.push_back({c[0], c[1], c[2], c[3]}); mp[up.back()]++;
    up.push_back({c[1], c[2], c[3], c[0]}); mp[up.back()]++;
    up.push_back({c[2], c[3], c[0], c[1]}); mp[up.back()]++;
    up.push_back({c[3], c[0], c[1], c[2]}); mp[up.back()]++;
  }

  cout << ans << "\n";
  return 0;

}

### Prompt

Create a solution in Cpp for the following problem:

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).

<image>

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.

<image>

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.

Examples

Input

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


Output

1


Input

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


Output

144


Input

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


Output

122880

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;

int n;
map<array<int, 4>, int> mp;

int same(array<int, 4> a, array<int, 4> b) {
  int res = 0;
  if (a == array<int, 4>{b[0], b[1], b[2], b[3]}) res++;
  if (a == array<int, 4>{b[1], b[2], b[3], b[0]}) res++;
  if (a == array<int, 4>{b[2], b[3], b[0], b[1]}) res++;
  if (a == array<int, 4>{b[3], b[0], b[1], b[2]}) res++;
  return res;
}

int main() {
  ios::sync_with_stdio(0);
  cin.tie(0), cout.tie(0);

  cin >> n;
  vector<array<int, 4>> up;
  long long ans = 0;

  for (int i = 0; i < n; i++) {
    array<int, 4> c;
    for (int j = 0; j < 4; j++) {
      cin >> c[j];
    }

    for (auto &d : up) {
      array<int, 4> w = {d[0], d[3], c[0], c[3]};
      array<int, 4> x = {d[3], d[2], c[1], c[0]};
      array<int, 4> y = {d[2], d[1], c[2], c[1]};
      array<int, 4> z = {d[1], d[0], c[3], c[2]};

      long long cur = 1;
      cur *= 1ll * mp[w] - same(d, w);
      cur *= 1ll * mp[x] - same(w, x) - same(d, x);
      cur *= 1ll * mp[y] - same(w, y) - same(x, y) - same(d, y);
      cur *= 1ll * mp[z] - same(w, z) - same(x, z) - same(y, z) - same(d, z);
      ans += cur;
    }

    up.push_back({c[0], c[1], c[2], c[3]}); mp[up.back()]++;
    up.push_back({c[1], c[2], c[3], c[0]}); mp[up.back()]++;
    up.push_back({c[2], c[3], c[0], c[1]}); mp[up.back()]++;
    up.push_back({c[3], c[0], c[1], c[2]}); mp[up.back()]++;
  }

  cout << ans << "\n";
  return 0;

}

```