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;
const int NN = 10000000, HashL = 3333331;
double f[NN + 3], ans;
long long e[NN + 3];
int t[NN + 3], last[HashL + 3], en;
int Bh[300], a[300], n, ls;
char s[10][3];
inline int It(int x, int y) {
  if (!y) return x >> 4;
  if (y == 1) return (x >> 2) & 3;
  return x & 3;
}
inline bool check(int x) {
  if (It(x, 1) && !It(x, 0) && !It(x, 2)) return 1;
  if (!It(x, 1) && It(x, 0) && It(x, 2)) return 1;
  return 0;
}
inline bool Can(int x, int y) {
  if (y == 1) {
    if (!It(x, 0)) return 0;
    if (!It(x, 2)) return 0;
    return 1;
  }
  return It(x, 1);
}
inline int Jia(int x, int y, int yy) {
  if (!y) yy <<= 4;
  if (y == 1) yy <<= 2;
  return x | yy;
}
inline int Jian(int x, int y, int yy) {
  if (!y) yy <<= 4;
  if (y == 1) yy <<= 2;
  return x ^ yy;
}
inline int Get() {
  for (int i = 1; i <= ls; i++) {
    int x1 = It(a[i], 0), x2 = It(a[i], 2);
    if (x1 > x2) {
      a[i] = Jian(a[i], 0, x1);
      a[i] = Jia(a[i], 0, x2);
      a[i] = Jian(a[i], 2, x2);
      a[i] = Jia(a[i], 2, x1);
    }
  }
  for (int i = 1; i < ls; i++)
    if (check(a[i])) a[i] = 0;
  sort(a + 1, a + ls);
  long long _s = 0;
  for (int i = 1; i <= ls; i++) _s = _s * 70 + a[i];
  int w = abs(_s) % HashL;
  for (int i = last[w]; i; i = t[i])
    if (e[i] == _s) return i;
  e[++en] = _s;
  t[en] = last[w];
  last[w] = en;
  return en;
}
inline double dfs() {
  double &x = f[Get()];
  if (x > 0) return x;
  int _s = 0;
  for (int i = 1; i < ls; i++) _s += a[i];
  if (!_s) return x = 0;
  int pa[20], pls = ls;
  pa[ls + 1] = 0;
  for (int i = 1; i <= ls; i++) pa[i] = a[i];
  if (It(a[ls], 0) && It(a[ls], 1) && It(a[ls], 2)) a[++ls] = 0;
  double yuan = 1. / 6, other = 0, Min1 = 2e16, Min2 = 2e16, Min3 = 2e16;
  bool cc[3];
  for (int i = 0; i < 3; i++) cc[i] = !It(pa[ls], i);
  for (int i = 1; i < pls; i++)
    if (a[i])
      for (int j = 0; j < 3; j++) {
        int x = It(pa[i], j);
        if (!x) continue;
        if (!Can(pa[i], j)) continue;
        if (x == 1) {
          for (int k = 0; k < 3; k++)
            if (cc[k]) {
              for (int l = 1; l < ls; l++) a[l] = pa[l];
              a[i] = Jian(pa[i], j, x);
              a[ls] = Jia(pa[ls], k, 1);
              Min1 = min(Min1, dfs());
            }
        }
        if (x == 2) {
          for (int k = 0; k < 3; k++)
            if (cc[k]) {
              for (int l = 1; l < ls; l++) a[l] = pa[l];
              a[i] = Jian(pa[i], j, x);
              a[ls] = Jia(pa[ls], k, 2);
              Min2 = min(Min2, dfs());
            }
        }
        if (x == 3) {
          for (int k = 0; k < 3; k++)
            if (cc[k]) {
              for (int l = 1; l < ls; l++) a[l] = pa[l];
              a[i] = Jian(pa[i], j, x);
              a[ls] = Jia(pa[ls], k, 3);
              Min3 = min(Min3, dfs());
            }
        }
      }
  ls = pls;
  for (int i = 1; i <= ls; i++) a[i] = pa[i];
  if (Min1 == 2e16)
    yuan += 1. / 6;
  else
    other += Min1 / 6;
  if (Min2 == 2e16)
    yuan += 1. / 3;
  else
    other += Min2 / 3;
  if (Min3 == 2e16)
    yuan += 1. / 3;
  else
    other += Min3 / 3;
  x = (other + 1) / (1 - yuan);
  return x;
}
int main() {
  scanf("%d", &n);
  if (n == 1) {
    puts("0");
    return 0;
  }
  Bh['R'] = 1;
  Bh['G'] = 2;
  Bh['B'] = 3;
  for (int i = 1; i <= n; i++) {
    scanf("%s", s[i]);
    if (Bh[s[i][0]] > Bh[s[i][2]]) swap(s[i][0], s[i][2]);
    a[i] = Bh[s[i][0]] * 16 + Bh[s[i][1]] * 4 + Bh[s[i][2]];
  }
  ls = n;
  ans = dfs();
  printf("%.6lf", ans);
}