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 <class T>
using vec = vector<T>;
template <typename Iter>
ostream &_IterOutput_(ostream &o, Iter b, Iter e, const string ss = "",
                      const string se = "") {
  o << ss;
  for (auto it = b; it != e; it++) o << (it == b ? "" : ", ") << *it;
  return o << se;
}
template <typename T1, typename T2>
ostream &operator<<(ostream &o, const pair<T1, T2> &pair) {
  return o << "(" << pair.first << ", " << pair.second << ")";
}
template <typename T>
ostream &operator<<(ostream &o, const vector<T> &vec) {
  return _IterOutput_(o, begin(vec), end(vec), "[", "]");
}
template <typename T>
ostream &operator<<(ostream &o, const set<T> &st) {
  return _IterOutput_(o, begin(st), end(st), "{", "}");
}
template <typename T, size_t N>
ostream &operator<<(ostream &o, const array<T, N> &arr) {
  return _IterOutput_(o, begin(arr), end(arr), "|", "|");
}
template <typename T1, typename T2>
ostream &operator<<(ostream &o, const map<T1, T2> &mp) {
  o << "{";
  for (auto it = mp.begin(); it != mp.end(); it++) {
    o << (it == mp.begin() ? "" : ", ") << it->first << ":" << it->second;
  }
  o << "}";
  return o;
}
using A3 = array<long long, 3>;
inline long long get(long long x, long long i) {
  return (x & (63LL << (i * 6))) >> (i * 6);
}
inline long long se(long long x, long long i, long long w) {
  long long sh = (i * 6);
  (x &= ~(63LL << sh)) ^= w << sh;
  return x;
}
inline long long del(long long x, long long i) {
  long long sh = i * 6;
  long long rm = x & ((1LL << sh) - 1);
  ((x >>= sh + 6) <<= sh) |= rm;
  return x;
}
A3 dec(long long x) { return {x & 3, (x >> 2) & 3, (x >> 4) & 3}; }
inline long long enc(A3 a) {
  if (a[2] > a[0]) swap(a[2], a[0]);
  return a[0] + (a[1] << 2) + (a[2] << 4);
}
unordered_map<long long, double> mem;
const double INF = 1e9;
long long norm(long long x) {
  static long long Z[30];
  long long i = 1, p;
  for (; p = get(x, i); i++) {
    Z[i] = p;
  }
  sort(Z + 1, Z + i);
  for (long long j = 1; j < i; j++) {
    x = se(x, j, Z[j]);
  }
  return x;
}
long long zz = 0;
double dp(long long st) {
  if (mem.count(st)) return mem[st];
  double ex[4] = {0, INF, INF, INF};
  for (long long i = 1, p; p = get(st, i); i++) {
    auto a = dec(p);
    if (!a[1] or (!a[0] and !a[2])) continue;
    for (long long j = 0; j < 3; j++) {
      if (!a[j]) continue;
      if (a[2] == 0 and j == 1) continue;
      long long cl = a[j];
      auto b = a;
      b[j] = 0;
      long long nx;
      if (!b[1] or (!b[0] and !b[2])) {
        nx = del(st, i);
      } else {
        nx = se(st, i, enc(b));
      }
      long long top = get(nx, 0);
      auto c = dec(top);
      if (c[0] and c[1] and c[2]) {
        top <<= 6;
        nx <<= 6;
        c = dec(top);
      }
      for (long long k = 0; k < 3; k++)
        if (!c[k]) {
          auto d = c;
          d[k] = cl;
          long long fn = norm(se(nx, 0, enc(d)));
          ex[cl] = min(ex[cl], dp(fn));
        }
    }
  }
  if (ex[1] >= INF and ex[2] >= INF and ex[3] >= INF) {
    return (mem[st]) = 0;
  } else {
    double zzprob = 1.0 / 6;
    if (ex[1] == INF) zzprob += 1.0 / 6, ex[1] = 0;
    if (ex[2] == INF) zzprob += 2.0 / 6, ex[2] = 0;
    if (ex[3] == INF) zzprob += 2.0 / 6, ex[3] = 0;
    (mem[st]) = (ex[1] * 1.0 / 6 + ex[2] * 2.0 / 6 + ex[3] * 2.0 / 6 + 1) /
                (1.0 - zzprob);
    return (mem[st]);
  }
}
int32_t main() {
  do {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
  } while (0);
  long long N;
  cin >> N;
  cout << fixed << setprecision(10);
  long long t = 0;
  for (long long i = 0; i < N; i++) {
    string s;
    cin >> s;
    A3 a;
    for (long long j = 0; j < 3; j++) {
      long long z = s[j] == 'R' ? 1 : s[j] == 'G' ? 2 : 3;
      a[j] = z;
    }
    (t <<= 6) += enc(a);
  }
  cout << dp(t) << endl;
  return 0;
}