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 inf = 2000000000;
static inline int Rint() {
  struct X {
    int dig[256];
    X() {
      for (int i = '0'; i <= '9'; ++i) dig[i] = 1;
      dig['-'] = 1;
    }
  };
  static X fuck;
  int s = 1, v = 0, c;
  for (; !fuck.dig[c = getchar()];)
    ;
  if (c == '-')
    s = 0;
  else if (fuck.dig[c])
    v = c ^ 48;
  for (; fuck.dig[c = getchar()]; v = v * 10 + (c ^ 48))
    ;
  return s ? v : -v;
}
template <typename T>
static inline void cmax(T& a, const T& b) {
  if (b > a) a = b;
}
template <typename T>
static inline void cmin(T& a, const T& b) {
  if (b < a) a = b;
}
unordered_map<unsigned long long, double> mem;
int same[64][64];
int tran[64];
void init() {
  for (int i = 0; i < 64; ++i) {
    int dig[3] = {0};
    for (int j = 0, k = i; j < 3; ++j) dig[j] = k % 4, k /= 4;
    int another = dig[0] * 16 + dig[1] * 4 + dig[2];
    same[another][i] = same[i][another] = 1;
  }
  int av = 0;
  for (int i = 0; i < 64; ++i) {
    int best = i;
    for (int j = 0; j < i; ++j)
      if (same[i][j]) {
        best = j;
        break;
      }
    tran[i] = best;
    av += best == i;
  }
}
int curr[205];
static inline unsigned long long hash_value(int* input, int n) {
  int orz[205];
  copy(input, input + n, orz);
  sort(orz, orz + n - 1);
  unsigned long long ret = 0;
  for (int i = 0; i < n; ++i) ret = ret * 31415927 + orz[i];
  return ret;
}
double dfs(const int n) {
  unsigned long long key = hash_value(curr, n);
  unordered_map<unsigned long long, double>::iterator where = mem.find(key);
  if (where != mem.end()) return where->second;
  int dig[3];
  for (int i = 0, v = curr[n - 1]; i < 3; ++i) dig[i] = v & 3, v >>= 2;
  const int old_top_value = curr[n - 1];
  int t = n;
  if (dig[0] != 0 && dig[1] != 0 && dig[2] != 0) {
    dig[0] = dig[1] = dig[2] = 0;
    ++t;
  }
  const int nn = t;
  double ans[4] = {0, 2000000, 2000000, 2000000};
  for (int i = 0; i < n - 1; ++i) {
    if (i > 0 && curr[i] == curr[i - 1]) continue;
    int dig1[3];
    for (int j = 0, v = curr[i]; j < 3; ++j) dig1[j] = v & 3, v >>= 2;
    if (!!dig1[0] + !!dig1[1] + !!dig1[2] == 1) continue;
    const int ov = curr[i];
    for (int p = 0; p < 3; ++p)
      if (dig1[p] != 0) {
        if (p == 0)
          if (!dig1[1]) continue;
        if (p == 2)
          if (!dig1[1]) continue;
        if (p == 1)
          if (!dig1[0] || !dig1[2]) continue;
        if (!!dig1[0] + !!dig1[1] + !!dig1[2] == 2 && (p == 1 || !dig1[1]))
          continue;
        const int value = dig1[p];
        dig1[p] = 0;
        curr[i] = tran[dig1[0] | dig1[1] << 2 | dig1[2] << 4];
        if (!!dig1[0] + !!dig1[1] + !!dig1[2] == 1 || dig1[1] == 0) curr[i] = 0;
        for (int q = 0; q < 3; ++q)
          if (dig[q] == 0) {
            dig[q] = value;
            curr[nn - 1] = tran[dig[0] | dig[1] << 2 | dig[2] << 4];
            double temp = dfs(nn);
            if (temp < ans[value]) ans[value] = temp;
            dig[q] = 0;
          }
        dig1[p] = value;
      }
    curr[i] = ov;
  }
  curr[n - 1] = old_top_value;
  if (ans[1] == 2000000 && ans[2] == 2000000 && ans[3] == 2000000)
    return mem[key] = 0;
  double used = 0;
  double ret = 0;
  if (ans[1] < 2000000) used += 1. / 6, ret += 1. / 6 * (1 + ans[1]);
  if (ans[2] < 2000000) used += 1. / 3, ret += 1. / 3 * (1 + ans[2]);
  if (ans[3] < 2000000) used += 1. / 3, ret += 1. / 3 * (1 + ans[3]);
  return mem[key] = (ret + 1 - used) / used;
}
char line[8];
int main() {
  init();
  int n = Rint();
  for (int i = 0; i < n; ++i) {
    scanf("%s", line);
    int val[3];
    int v = 0;
    for (int i = 0; i < 3; ++i) {
      int t = 1;
      if (line[i] == 'G')
        t = 2;
      else if (line[i] == 'B')
        t = 3;
      v = v * 4 + t;
      val[i] = t;
    }
    curr[i] = tran[v];
  }
  sort(curr, curr + n - 1);
  int start = clock();
  printf("%.16f\n", dfs(n));
  cerr << clock() - start << endl;
  return 0;
}