#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);
}
