#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>
using namespace std;
typedef long long LL;
typedef long double LD;
typedef complex<LD> CMP;
class DancingFoxes { public:
int minimalDays(vector <string> friendship)
{
static const int INF = 0x1fffffff;
int N = friendship.size();
vector< vector<int> > M(N, vector<int>(N));
for(int i=0; i<N; ++i)
for(int k=0; k<N; ++k)
M[i][k] = (friendship[i][k]=='Y' ? 1 : INF);
for(int k=0; k<N; ++k)
for(int i=0; i<N; ++i)
for(int j=0; j<N; ++j)
M[i][j] = min(M[i][j], M[i][k]+M[k][j]);
if(M[0][1] == INF)
return -1;
int s = 0;
for(int d = M[0][1]; d>1; ++s)
d -= (d+1)/3;
return s;
}
};
// 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(_, DancingFoxes().minimalDays(friendship));}
int main(){
CASE(0)
string friendship_[] = {"NNY",
"NNY",
"YYN"};
vector <string> friendship(friendship_, friendship_+sizeof(friendship_)/sizeof(*friendship_));
int _ = 1;
END
CASE(1)
string friendship_[] = {"NNNNN",
"NNYYY",
"NYNYY",
"NYYNY",
"NYYYN"};
vector <string> friendship(friendship_, friendship_+sizeof(friendship_)/sizeof(*friendship_));
int _ = -1;
END
CASE(2)
string friendship_[] = {"NNYYNN",
"NNNNYY",
"YNNNYN",
"YNNNNY",
"NYYNNN",
"NYNYNN"};
vector <string> friendship(friendship_, friendship_+sizeof(friendship_)/sizeof(*friendship_));
int _ = 2;
END
CASE(3)
string friendship_[] = {"NNYNNNNYN",
"NNNNYNYNN",
"YNNYNYNNN",
"NNYNYNYYN",
"NYNYNNNNY",
"NNYNNNYNN",
"NYNYNYNNN",
"YNNYNNNNY",
"NNNNYNNYN"};
vector <string> friendship(friendship_, friendship_+sizeof(friendship_)/sizeof(*friendship_));
int _ = 3;
END
CASE(4)
string friendship_[] = {"NY",
"YN"};
vector <string> friendship(friendship_, friendship_+sizeof(friendship_)/sizeof(*friendship_));
int _ = 0;
END
CASE(5)
string friendship_[] = {
"NNYNNNNNN",
"NNNNNNNNY",
"YNNYNNNNN",
"NNYNYNNNN",
"NNNYNYNNN",
"NNNNYNYNN",
"NNNNNYNYN",
"NNNNNNYNY",
"NYNNNNNYN"
};
vector <string> friendship(friendship_, friendship_+sizeof(friendship_)/sizeof(*friendship_));
int N = friendship.size();
int idx[] = {0,8,1,2,3,4,5,6,7};
for(int y=0; y<N; ++y, cout<<endl)
for(int x=0; x<N; ++x) {
cout << friendship[idx[y]][idx[x]];
}
int _ = -1;
END
/*
CASE(6)
string friendship_[] = ;
vector <string> friendship(friendship_, friendship_+sizeof(friendship_)/sizeof(*friendship_));
int _ = ;
END
*/
}
// END CUT HERE