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;
template <typename T, typename U>
inline void amin(T &x, U y) {
  if (y < x) x = y;
}
template <typename T, typename U>
inline void amax(T &x, U y) {
  if (x < y) x = y;
}
const int S = 3 * 3 * 3 + 3, T = (S + 4 + 3) / 4 * 4;
int nextst[S][3][3];
void calcnextst() {
  memset(nextst, -1, sizeof(nextst));
  int cs[3];
  for (cs[0] = 0; cs[0] < 3; cs[0]++)
    for (cs[1] = 0; cs[1] < 3; cs[1]++)
      for (cs[2] = 0; cs[2] < 3; cs[2]++) {
        for (int(c) = 0; (c) < (int)(3); ++(c)) {
          int s = cs[0] * 9 + cs[1] * 3 + cs[2];
          if (cs[0] == c) nextst[s][c][0] = 27 + cs[2];
          if (cs[1] == c) nextst[s][c][1] = -2;
          if (cs[2] == c) nextst[s][c][2] = 27 + cs[0];
        }
      }
  for (int(cc) = 0; (cc) < (int)(3); ++(cc)) {
    for (int(c) = 0; (c) < (int)(3); ++(c)) {
      int s = 27 + cc;
      if (cc == c) nextst[s][c][0] = -2;
    }
  }
}
template <typename T>
inline size_t &hash_combine(size_t &x, const T &y) {
  return x ^= hash<T>()(y) + 0x9e3779b9 + (x << 6) + (x >> 2);
}
struct StateHash {
  size_t operator()(const vector<char> &num) const {
    unsigned *p = (unsigned *)&num[0];
    size_t h = 0;
    for (int(i) = 0; (i) < (int)(T / 4); ++(i)) hash_combine(h, p[i]);
    return h;
  }
};
double rec(vector<char> num, char topcnt, char top1, char top2, char top3);
inline double recnext(vector<char> num, char topst, char top1, char top2,
                      char top3, char col) {
  double r = 1e99;
  if (topst == 4) {
    int s = top1 * 9 + top2 * 3 + top3;
    ++num[s];
    amin(r, rec(num, 0, col, 0, 0));
    amin(r, rec(num, 1, 0, col, 0));
    --num[s];
  } else if (topst == 0) {
    amin(r, rec(num, 2, top1, col, 0));
    amin(r, rec(num, 3, top1, 0, col));
  } else if (topst == 1) {
    amin(r, rec(num, 2, col, top2, 0));
  } else if (topst == 2) {
    amin(r, rec(num, 4, top1, top2, col));
  } else if (topst == 3) {
    amin(r, rec(num, 4, top1, col, top3));
  }
  return r;
}
unordered_map<vector<char>, double, StateHash> memo;
double rec(vector<char> num, char topst, char top1, char top2, char top3) {
  if (top1 < top3) swap(top1, top3);
  num[S] = topst, num[S + 1] = top1, num[S + 2] = top2, num[S + 3] = top3;
  auto it = memo.find(num);
  if (it != memo.end()) {
    if (it->second == -1) cerr << "loop!!!!" << endl;
    return it->second;
  }
  double r = 0;
  double &rr = memo[num];
  rr = -1;
  r = 0;
  int waitp = 1;
  for (int(col) = 0; (col) < (int)(3); ++(col)) {
    double x = 1e99;
    for (int(i) = 0; (i) < (int)(S); ++(i))
      if (num[i] > 0)
        for (int(k) = 0; (k) < (int)(3); ++(k)) {
          int j = nextst[i][col][k];
          if (j != -1) {
            --num[i];
            if (j != -2) ++num[j];
            amin(x, 1 + recnext(num, topst, top1, top2, top3, col));
            ++num[i];
            if (j != -2) --num[j];
          }
        }
    int p = col == 0 ? 1 : 2;
    if (x == 1e99)
      waitp += p;
    else
      r += x * p / 6;
  }
  if (waitp == 6)
    r = 0;
  else
    r = (r + waitp / 6.) / (1 - waitp / 6.);
  return rr = r;
}
int getci(char c) { return c == 'R' ? 0 : c == 'G' ? 1 : 2; }
int main() {
  calcnextst();
  vector<char> num(T, 0);
  int n;
  scanf("%d", &n);
  char topst = -1, top1 = -1, top2 = -1, top3 = -1;
  for (int(i) = 0; (i) < (int)(n); ++(i)) {
    static char buf[4];
    scanf("%s", buf);
    if (getci(buf[0]) > getci(buf[2])) swap(buf[0], buf[2]);
    if (i == n - 1) {
      topst = 4;
      top1 = getci(buf[0]);
      top2 = getci(buf[1]);
      top3 = getci(buf[2]);
    } else {
      int s;
      if (buf[0] == '.')
        s = 27 + getci(buf[2]);
      else
        s = getci(buf[0]) * 9 + getci(buf[1]) * 3 + getci(buf[2]);
      num[s]++;
    }
  }
  memo.clear();
  double ans = rec(num, topst, top1, top2, top3);
  printf("%.10f\n", ans);
  return 0;
}