#include <bits/stdc++.h>
using namespace std;
#pragma comment(linker, "/STACK:64000000")
const int maxn = 18;
const int maxm = 110;
const int maxmask = (1 << maxn) - 1;
const int infi = 1e9 + 7;
const long long infl = 1e18;
const double eps = 1e-6;
const int mod = 1e9 + 7;
int n, m, i, j, k;
vector<pair<int, int> > per[30];
string sost[30] = {"",    "R",   "B",   "G",   "RRR", "RRB", "RRG", "RBB",
                   "RBG", "RGG", "BRR", "BRB", "BRG", "BBB", "BBG", "BGG",
                   "GRR", "GRB", "GRG", "GBB", "GBG", "GGG"};
long long st[30];
bool comp(char a, char b) {
  if (a == 'R') {
    return 1;
  }
  if (b == 'R') {
    return 0;
  }
  if (a == 'B') {
    return 1;
  }
  if (b == 'B') {
    return 0;
  }
  return 0;
}
void srt(string &a) {
  swap(a[0], a[1]);
  if (comp(a[2], a[1])) {
    swap(a[1], a[2]);
  }
  return;
}
vector<int> per1[50][4];
string sosth[50] = {"",    "RRR", "RRB", "RRG", "RBB", "RBG", "RGG", "BRR",
                    "BRB", "BRG", "BBB", "BBG", "BGG", "GRR", "GRB", "GRG",
                    "GBB", "GBG", "GGG", "_R_", "_B_", "_G_", "_RR", "_RB",
                    "_RG", "_BB", "_BG", "_GG", "R__", "RR_", "RB_", "RG_",
                    "B__", "BR_", "BB_", "BG_", "G__", "GR_", "GB_", "GG_"};
map<pair<int, long long>, long double> q;
void pereb(pair<int, long long> a) {
  if (q.count(a)) {
    return;
  }
  if (a.second == 0) {
    q.insert(make_pair(a, 0));
    return;
  }
  long double res[4];
  res[1] = res[2] = res[3] = infi + 1;
  for (int i = 1; i <= 21 && st[i] <= a.second; ++i) {
    if ((a.second / st[i]) % (st[i + 1] / st[i])) {
      for (int j = 0; j < per[i].size(); ++j) {
        long long to = a.second - st[i];
        if (per[i][j].first) {
          to += st[per[i][j].first];
        }
        if (a.first <= 18) {
          to += st[a.first + 3];
        }
        for (int k = 0; k < per1[a.first][per[i][j].second].size(); ++k) {
          int p1 = per1[a.first][per[i][j].second][k];
          pereb(make_pair(p1, to));
          res[per[i][j].second] =
              min(res[per[i][j].second], q.find(make_pair(p1, to))->second);
        }
      }
    }
  }
  long double b = 5.0 / 6.0;
  long double res1 = 1;
  if (res[1] >= (long double)infi) {
    b -= (long double)1.0 / (long double)6.0;
  } else {
    res1 += res[1] / (long double)6.0;
  }
  if (res[2] >= (long double)infi) {
    b -= (long double)1.0 / (long double)3.0;
  } else {
    res1 += res[2] / (long double)3.0;
  }
  if (res[3] >= (long double)infi) {
    b -= (long double)1.0 / (long double)3.0;
  } else {
    res1 += res[3] / (long double)3.0;
  }
  if (b == 0) {
    q.insert(make_pair(a, 0));
    return;
  }
  res1 /= b;
  q.insert(make_pair(a, res1));
  return;
}
int main() {
  char b[4] = {' ', 'R', 'B', 'G'};
  per[1].push_back(make_pair(0, 1));
  per[2].push_back(make_pair(0, 2));
  per[3].push_back(make_pair(0, 3));
  for (i = 4; i <= 21; ++i) {
    for (j = 1; j <= 3; ++j) {
      if (b[j] == sost[i][0]) {
        per[i].push_back(make_pair(0, j));
        break;
      }
    }
    for (j = 1; j <= 3; ++j) {
      if (b[j] == sost[i][1]) {
        for (k = 1; k <= 3; ++k) {
          if (b[k] == sost[i][2]) {
            per[i].push_back(make_pair(j, k));
            if (j != k) {
              per[i].push_back(make_pair(k, j));
            }
          }
        }
      }
    }
  }
  for (i = 1; i <= 18; ++i) {
    per1[i][1].push_back(28);
    per1[i][1].push_back(19);
    per1[i][2].push_back(20);
    per1[i][2].push_back(32);
    per1[i][3].push_back(36);
    per1[i][3].push_back(21);
  }
  for (i = 19; i <= 39; ++i) {
    for (j = 1; j <= 3; ++j) {
      if (sosth[i][0] == '_') {
        string ar = sosth[i];
        ar[0] = b[j];
        for (k = 1; k <= 39; ++k) {
          if (ar == sosth[k]) {
            per1[i][j].push_back(k);
            break;
          }
        }
      }
      if (sosth[i][1] == '_') {
        string ar = sosth[i];
        ar[1] = b[j];
        for (k = 1; k <= 39; ++k) {
          if (ar == sosth[k]) {
            per1[i][j].push_back(k);
            break;
          }
        }
      }
      if (sosth[i][2] == '_' && sosth[i][1] != '_') {
        string ar = sosth[i];
        ar[2] = b[j];
        if (comp(ar[2], ar[1])) {
          swap(ar[1], ar[2]);
        }
        for (k = 1; k <= 39; ++k) {
          if (ar == sosth[k]) {
            per1[i][j].push_back(k);
            break;
          }
        }
      }
    }
  }
  string ar;
  long long g = 729;
  st[1] = 1;
  st[2] = 9;
  st[3] = 81;
  for (i = 4; i <= 22; ++i) {
    st[i] = g;
    g *= 6LL;
  }
  int a;
  long long arz = 0;
  cin >> n;
  for (i = 0; i < n; ++i) {
    cin >> ar;
    srt(ar);
    for (j = 4; j <= 21; ++j) {
      if (ar == sost[j]) {
        a = j;
        break;
      }
    }
    if (i != n - 1) {
      arz += st[a];
    }
  }
  pereb(make_pair(a - 3, arz));
  cout.precision(9);
  cout << fixed;
  cout << q.find(make_pair(a - 3, arz))->second;
  return 0;
}
