Problem: Cold winter evenings in Tomsk are very boring — nobody wants be on the streets at such a time. Residents of Tomsk while away the time sitting in warm apartments, inventing a lot of different games. One of such games is 'Colored Jenga'.

This game requires wooden blocks of three colors: red, green and blue. A tower of n levels is made from them. Each level consists of three wooden blocks. The blocks in each level can be of arbitrary colors, but they are always located close and parallel to each other. An example of such a tower is shown in the figure.

<image>

The game is played by exactly one person. Every minute a player throws a special dice which has six sides. Two sides of the dice are green, two are blue, one is red and one is black. The dice shows each side equiprobably.

If the dice shows red, green or blue, the player must take any block of this color out of the tower at this minute so that the tower doesn't fall. If this is not possible, the player waits until the end of the minute, without touching the tower. He also has to wait until the end of the minute without touching the tower if the dice shows the black side. It is not allowed to take blocks from the top level of the tower (whether it is completed or not).

Once a player got a block out, he must put it on the top of the tower so as to form a new level or finish the upper level consisting of previously placed blocks. The newly constructed levels should have all the same properties as the initial levels. If the upper level is not completed, starting the new level is prohibited.

For the tower not to fall, in each of the levels except for the top, there should be at least one block. Moreover, if at some of these levels there is exactly one block left and this block is not the middle block, the tower falls.

The game ends at the moment when there is no block in the tower that you can take out so that the tower doesn't fall.

Here is a wonderful game invented by the residents of the city of Tomsk. I wonder for how many minutes can the game last if the player acts optimally well? If a player acts optimally well, then at any moment he tries to choose the block he takes out so as to minimize the expected number of the game duration.

Your task is to write a program that determines the expected number of the desired amount of minutes.

Input

The first line of the input contains the only integer n (2 ≤ n ≤ 6) — the number of levels in the tower.

Then n lines follow, describing the levels of the tower from the bottom to the top (the first line is the top of the tower). Each level is described by three characters, the first and the third of them set the border blocks of the level and the second one is the middle block. The character that describes the block has one of the following values 'R' (a red block), 'G' (a green block) and 'B' (a blue block).

Output

In the only line of the output print the sought mathematical expectation value. The answer will be considered correct if its relative or absolute error doesn't exceed 10 - 6.

Examples

Input

6
RGB
GRG
BBB
GGR
BRG
BRB


Output

17.119213696601992

Solution (in CPP):

Solution:
#include <bits/stdc++.h>
using namespace std;
void _fill_int(int* p, int val, int rep) {
  int i;
  for (i = 0; i < rep; i++) p[i] = val;
}
signed long long GETi() {
  signed long long i;
  scanf("%lld", &i);
  return i;
}
int N;
map<vector<int>, double> M[64];
int st[64], num[64];
double dodo(int top, vector<int> V) {
  int otop, i, x, y, z, ng = 0;
  otop = top = st[top];
  sort(V.begin(), V.end());
  vector<int> VV = V;
  if (M[top].find(V) != M[top].end()) return M[top][V];
  if (num[top] == 3) V.push_back(top), top = 0, ng = 1;
  double ma[4] = {0, 1e15, 1e15, 1e15};
  int pre = -1;
  for (i = 0; i < V.size() - ng; i++) {
    if (pre == V[i]) continue;
    pre = V[i];
    x = V[i] % 4;
    y = V[i] / 4 % 4;
    z = V[i] / 16;
    vector<int> V2 = V;
    V2.erase(V2.begin() + i);
    if (x && y && z) {
      if (top % 4 == 0) ma[y] = min(ma[y], dodo(top + y * 1, V2));
      if (top / 4 % 4 == 0) ma[y] = min(ma[y], dodo(top + y * 4, V2));
      if (top / 16 == 0 && top % 4) ma[y] = min(ma[y], dodo(top + y * 16, V2));
    }
    if (z && y) {
      if (x) {
        V[i] = 4 + x;
        if (top % 4 == 0) ma[z] = min(ma[z], dodo(top + z * 1, V));
        if (top / 4 % 4 == 0) ma[z] = min(ma[z], dodo(top + z * 4, V));
        if (top / 16 == 0 && top % 4) ma[z] = min(ma[z], dodo(top + z * 16, V));
      } else {
        if (top % 4 == 0) ma[z] = min(ma[z], dodo(top + z * 1, V2));
        if (top / 4 % 4 == 0) ma[z] = min(ma[z], dodo(top + z * 4, V2));
        if (top / 16 == 0 && top % 4)
          ma[z] = min(ma[z], dodo(top + z * 16, V2));
      }
    }
    if (y && x) {
      if (z) {
        V[i] = z + 4;
        if (top % 4 == 0) ma[x] = min(ma[x], dodo(top + x * 1, V));
        if (top / 4 % 4 == 0) ma[x] = min(ma[x], dodo(top + x * 4, V));
        if (top / 16 == 0 && top % 4) ma[x] = min(ma[x], dodo(top + x * 16, V));
      } else {
        if (top % 4 == 0) ma[x] = min(ma[x], dodo(top + x * 1, V2));
        if (top / 4 % 4 == 0) ma[x] = min(ma[x], dodo(top + x * 4, V2));
        if (top / 16 == 0 && top % 4)
          ma[x] = min(ma[x], dodo(top + x * 16, V2));
      }
    }
    V[i] = pre;
  }
  int sum = 1;
  if (ma[1] >= 1e15) ma[1] = 0, sum += 1;
  if (ma[2] >= 1e15) ma[2] = 0, sum += 2;
  if (ma[3] >= 1e15) ma[3] = 0, sum += 2;
  if (sum == 6) return M[otop][VV] = 0;
  M[otop][VV] = (1 + ma[1] / 6 + ma[2] / 3 + ma[3] / 3) / (1 - sum / 6.0);
  return M[otop][VV] =
             (1 + ma[1] / 6 + ma[2] / 3 + ma[3] / 3) / (1 - sum / 6.0);
}
void solve() {
  int f, i, j, k, l, x, y, x2, y2, z;
  cin >> N;
  string S;
  for (i = 0; i < 64; i++) {
    x = i % 4;
    y = i / 4 % 4;
    z = i / 16;
    st[i] = (z > x) ? (x * 16 + y * 4 + z) : i;
    num[i] = (x > 0) + (y > 0) + (z > 0);
  }
  vector<int> V;
  for (i = 0; i < N; i++) {
    cin >> S;
    x = 0;
    for (y = 0; y < 3; y++) {
      if (S[y] == 'R') x += 1 << (y * 2);
      if (S[y] == 'G') x += 2 << (y * 2);
      if (S[y] == 'B') x += 3 << (y * 2);
    }
    if (i < N - 1) V.push_back(st[x]);
  }
  (void)printf("%.12lf\n", dodo(st[x], V));
}
int main(int argc, char** argv) {
  string s;
  if (argc == 1) ios::sync_with_stdio(false);
  for (int i = 1; i < argc; i++) s += argv[i], s += '\n';
  for (int i = s.size() - 1; i >= 0; i--) ungetc(s[i], stdin);
  solve();
  return 0;
}