#include <bits/stdc++.h>
using namespace std;
const double eps = 1e-9;
const long long P = 1e17 + 3;
const int N = 18 + 2, K = 128 + 2, H = 23;
double w[4] = {1. / 6, 1. / 6, 1. / 3, 1. / 3};
unordered_map<long long, double> mp;
long long h, pwr[K] = {1};
int n, a[N][3], ted[N];
void _sum(long long &a, long long b) {
  if ((a += b) < 0) a += P;
  if (a >= P) a -= P;
}
long long get_hash(int p) {
  int h = min(a[p][0], a[p][2]) + 4 * a[p][1] + 16 * max(a[p][0], a[p][2]);
  return p < n - 1 ? !a[p][1] || ted[p] < 2 ? 0 : pwr[h] : pwr[64 + h];
}
double bt() {
  if (mp.count(h)) return mp[h];
  bool t = ted[n - 1] > 2;
  double p[4] = {K, K, K, K};
  double cur = 1, expect = 1;
  _sum(h, -get_hash(n - 1)), n += t, ted[n - 1]++;
  if (t) _sum(h, get_hash(n - 2));
  for (int i = 0; i < n - t - 1; i++)
    for (int j = 0; j < 3; j++)
      if (a[i][j] && (ted[i] > 2 || (a[i][1] && j ^ 1))) {
        int x = a[i][j];
        _sum(h, -get_hash(i)), ted[i]--, a[i][j] = 0, _sum(h, get_hash(i));
        for (int k = 0; k < 3; k++)
          if (!a[n - 1][k]) {
            a[n - 1][k] = x, _sum(h, get_hash(n - 1)), p[x] = min(p[x], bt());
            _sum(h, -get_hash(n - 1)), a[n - 1][k] = 0;
          }
        _sum(h, -get_hash(i)), ted[i]++, a[i][j] = x, _sum(h, get_hash(i));
      }
  if (t) _sum(h, -get_hash(n - 2));
  ted[n - 1]--, n -= t, _sum(h, get_hash(n - 1));
  for (int i = 0; i < 4; i++)
    p[i] + eps < K ? expect += w[i] * p[i] : cur -= w[i];
  return mp[h] = cur > eps ? expect / cur : 0;
}
int main() {
  cin >> n;
  for (int i = 1; i < K; i++) pwr[i] = 1LL * pwr[i - 1] * H % P;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < 3; j++) {
      char c;
      cin >> c;
      if (c == 'R') a[i][j] = 1;
      if (c == 'G') a[i][j] = 2;
      if (c == 'B') a[i][j] = 3;
    }
    ted[i] = 3, _sum(h, get_hash(i));
  }
  cout << fixed << bt();
}
