#include <iostream>
#include <sstream>
#include <iomanip>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <algorithm>
#include <numeric>
#include <iterator>
#include <functional>
#include <complex>
#include <queue>
#include <stack>
#include <cmath>
#include <cassert>
#include <tuple>
using namespace std;
typedef long long LL;
typedef complex<double> CMP;
typedef int vert;
typedef vert edge;
typedef vector<edge> edges;
typedef vector<edges> graph;
bool augment( graph& G, int v, vector<vert>& matchTo, bool visited[] )
{
for(int i=0; i<G[v].size(); ++i) {
vert u = G[v][i];
if( visited[u] ) continue;
visited[u] = true;
if( matchTo[u]<0 || augment(G, matchTo[u], matchTo, visited) )
{ matchTo[v]=u, matchTo[u]=v; return true; }
}
return false;
}
template<int NV>
int biMatch( graph& G, int L ) // [0,L):left, [L,?):right
// only left->right edges are used during computation
{
vector<vert> matchTo(G.size(), -1);
int ans = 0;
for(vert v=0; v<L; ++v) {
bool visited[NV] = {};
if( augment(G, v, matchTo, visited) )
++ans;
}
return ans;
}
class GearsDiv1 { public:
int getmin(string color, vector <string> graph)
{
vector<int> r, g, b;
for(int i=0; i<color.size(); ++i)
(color[i]=='R' ? r : color[i]=='G' ? g : b).push_back(i);
int rg = calc(graph, r, g);
int gb = calc(graph, g, b);
int br = calc(graph, b, r);
return min(rg, min(gb, br));
}
int calc(const vector<string>& G, const vector<int>& A, const vector<int>& B)
{
if(A.empty() || B.empty())
return 0;
graph gr(A.size() + B.size());
for(int a=0; a<A.size(); ++a)
for(int b=0; b<B.size(); ++b)
{
if(G[A[a]][B[b]] == 'Y')
gr[a].push_back(A.size()+b);
}
return biMatch<256>(gr, A.size());
}
};
// BEGIN CUT HERE
#include <ctime>
double start_time; string timer()
{ ostringstream os; os << " (" << int((clock()-start_time)/CLOCKS_PER_SEC*1000) << " msec)"; return os.str(); }
template<typename T> ostream& operator<<(ostream& os, const vector<T>& v)
{ os << "{ ";
for(typename vector<T>::const_iterator it=v.begin(); it!=v.end(); ++it)
os << '\"' << *it << '\"' << (it+1==v.end() ? "" : ", "); os << " }"; return os; }
void verify_case(const int& Expected, const int& Received) {
bool ok = (Expected == Received);
if(ok) cerr << "PASSED" << timer() << endl; else { cerr << "FAILED" << timer() << endl;
cerr << "\to: \"" << Expected << '\"' << endl << "\tx: \"" << Received << '\"' << endl; } }
#define CASE(N) {cerr << "Test Case #" << N << "..." << flush; start_time=clock();
#define END verify_case(_, GearsDiv1().getmin(color, graph));}
int main(){
CASE(0)
string color = "RGB";
string graph_[] = {"NYY","YNY","YYN"};
vector <string> graph(graph_, graph_+sizeof(graph_)/sizeof(*graph_));
int _ = 1;
END
CASE(1)
string color = "RGBR";
string graph_[] = {"NNNN","NNNN","NNNN","NNNN"};
vector <string> graph(graph_, graph_+sizeof(graph_)/sizeof(*graph_));
int _ = 0;
END
CASE(2)
string color = "RGBR";
string graph_[] = {"NYNN","YNYN","NYNY","NNYN"};
vector <string> graph(graph_, graph_+sizeof(graph_)/sizeof(*graph_));
int _ = 1;
END
CASE(3)
string color = "RRRRRGRRBGRRGBBGGGBRRRGBRGRRGG";
string graph_[] = {"NNNNNYNNNYNNYNNNYNNNNNNNNYNNYY",
"NNNNNNNNYNNNYNYNNYNNNNYNNYNNYY",
"NNNNNYNNNNNNNNNNNNYNNNNNNYNNNY",
"NNNNNNNNNYNNYNNYYYNNNNYNNYNNNN",
"NNNNNNNNNYNNYNNYYYNNNNYNNNNNNN",
"YNYNNNYYYNNYNYYNNNNNYYNYNNYYNN",
"NNNNNYNNNNNNNNNYYYNNNNYNNYNNYY",
"NNNNNYNNNNNNNNNYNNNNNNNNNNNNYN",
"NYNNNYNNNYNNYNNYYYNNNNYNNYNNYY",
"YNNYYNNNYNNNNYYNNNYNYYNYNNNNNN",
"NNNNNNNNNNNNYNNYNYNNNNYNNNNNNY",
"NNNNNYNNNNNNYNNYYYNNNNNNNNNNYN",
"YYNYYNNNYNYYNYYNNNYNYNNYNNNNNN",
"NNNNNYNNNYNNYNNYYYNNNNYNNYNYYY",
"NYNNNYNNNYNNYNNYYYNNNNYNNYNNYY",
"NNNYYNYYYNYYNYYNNNYNYNNYYNYYNN",
"YNNYYNYNYNNYNYYNNNYNNNNYYNNYNN",
"NYNYYNYNYNYYNYYNNNNYYNNYYNYNNN",
"NNYNNNNNNYNNYNNYYNNNNNYNNYNNNY",
"NNNNNNNNNNNNNNNNNYNNNNYNNYNNNY",
"NNNNNYNNNYNNYNNYNYNNNNYNNNNNYY",
"NNNNNYNNNYNNNNNNNNNNNNYNNNNNNN",
"NYNYYNYNYNYNNYYNNNYYYYNYYNYNNN",
"NNNNNYNNNYNNYNNYYYNNNNYNNNNNNY",
"NNNNNNNNNNNNNNNYYYNNNNYNNYNNYY",
"YYYYNNYNYNNNNYYNNNYYNNNNYNYYNN",
"NNNNNYNNNNNNNNNYNYNNNNYNNYNNYN",
"NNNNNYNNNNNNNYNYYNNNNNNNNYNNYY",
"YYNNNNYYYNNYNYYNNNNNYNNNYNYYNN",
"YYYNNNYNYNYNNYYNNNYYYNNYYNNYNN"};
vector <string> graph(graph_, graph_+sizeof(graph_)/sizeof(*graph_));
int _ = 3;
END
/*
CASE(4)
string color = ;
string graph_[] = ;
vector <string> graph(graph_, graph_+sizeof(graph_)/sizeof(*graph_));
int _ = ;
END
CASE(5)
string color = ;
string graph_[] = ;
vector <string> graph(graph_, graph_+sizeof(graph_)/sizeof(*graph_));
int _ = ;
END
*/
}
// END CUT HERE