func_code_string: #include <bits/stdc++.h>   using namespace std;   long long gcd(long long u, long long v) {     while (v != 0) {       long long r = u % v;       u = v;       v = r;     }     return u;   }   typedef struct State {     char cnt[21];     char top[3];   } State;   inline bool operator<(const State &a, const State &b) {     return memcmp(&a, &b, sizeof(State)) < 0;   }   int nways[3];   int need[3][16], gain[3][16];   char color[3] = { B ,  G ,  R };   char name[21][4] = { B ,    G ,    R ,    BBB ,  BBG ,  BBR ,  BGB ,                        BGG ,  BGR ,  BRB ,  BRG ,  BRR ,  GBG ,  GBR ,                        GGG ,  GGR ,  GRG ,  GRR ,  RBR ,  RGR ,  RRR };   void init() {     memset(nways, 0, sizeof(nways));     for (int i = (0); i < (3); ++i) {       int x = name[i][0] ==  B  ? 0 : name[i][0] ==  G  ? 1 : 2;       need[x][nways[x]] = i;       gain[x][nways[x]] = -1;       ++nways[x];     }     for (int i = (3); i < (21); ++i)       for (int j = (0); j < (3); ++j) {         if (j == 2 && name[i][0] == name[i][2]) continue;         int x = name[i][j] ==  B  ? 0 : name[i][j] ==  G  ? 1 : 2;         int y = name[i][2 - j] ==  B  ? 0 : name[i][2 - j] ==  G  ? 1 : 2;         need[x][nways[x]] = i;         gain[x][nways[x]] = j == 1 ? -1 : y;         ++nways[x];       }     for (int i = (0); i < (3); ++i) assert(nways[i] == 16);   }   int encode(char s[3]) {     for (int i = (3); i < (21); ++i)       if (s[0] == name[i][0] && s[1] == name[i][1] && s[2] == name[i][2])         return i;     assert(false);     return -1;   }   map<State, double> mem;   double go(State &s) {     map<State, double>::iterator retit = mem.find(s);     if (retit != mem.end()) return retit->second;     char oldtop[3];     int gaintop = -1;     bool fulltop = true;     for (int k = (0); k < (3); ++k)       if (s.top[k] ==  ? ) fulltop = false;     if (fulltop) {       for (int k = (0); k < (3); ++k) oldtop[k] = s.top[k];       gaintop = encode(s.top);       for (int k = (0); k < (3); ++k) s.top[k] =  ? ;     }     int nwait = 1;     double sum = 0;     for (int i = (0); i < (3); ++i) {       int times = i == 2 ? 1 : 2;       bool any = false;       double best = -1;       for (int j = (0); j < (nways[i]); ++j)         if (s.cnt[need[i][j]] > 0)           for (int k = (0); k < (3); ++k) {             if (s.top[k] !=  ?  || k == 2 && s.top[0] ==  ? ) continue;             s.top[k] = color[i];             bool swaptop = false;             if (k == 2 && s.top[0] > s.top[2]) {               swaptop = true;               swap(s.top[0], s.top[2]);             }             --s.cnt[need[i][j]];             if (gain[i][j] != -1) ++s.cnt[gain[i][j]];             if (gaintop != -1) ++s.cnt[gaintop];             double cur = go(s);             if (!any || cur < best) any = true, best = cur;             if (gaintop != -1) --s.cnt[gaintop];             if (gain[i][j] != -1) --s.cnt[gain[i][j]];             ++s.cnt[need[i][j]];             if (swaptop) swap(s.top[0], s.top[2]);             s.top[k] =  ? ;           }       if (!any)         nwait += times;       else         sum += times * best;     }     if (fulltop) {       for (int k = (0); k < (3); ++k) s.top[k] = oldtop[k];     }     double ret = nwait == 6 ? 0.0 : (6 + sum) / (6 - nwait);     return mem[s] = ret;   }   char sinit[6][3];   void run() {     int n;     scanf( %d , &n);     for (int i = (0); i < (n); ++i)       for (int j = (0); j < (3); ++j) scanf(  %c , &sinit[i][j]);     for (int i = (0); i < (n); ++i)       if (sinit[i][0] > sinit[i][2]) swap(sinit[i][0], sinit[i][2]);     State init;     for (int j = (0); j < (21); ++j) init.cnt[j] = 0;     for (int i = (0); i < (n - 1); ++i) init.cnt[encode(sinit[i])]++;     for (int k = (0); k < (3); ++k) init.top[k] = sinit[n - 1][k];     double ret = go(init);     printf( %.9lf n , ret);   }   int main() {     init();     run();     return 0;   }   