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

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 Incubator { public:
	int maxMagicalGirls(vector <string> love)
	{
		const int N = love.size();
		vector< vector<int> > protects(N, vector<int>(N, false));
		for(int i=0; i<N; ++i)
		for(int j=0; j<N; ++j)
			protects[i][j] = (love[i][j] == 'Y');
		for(int k=0; k<N; ++k)
		for(int i=0; i<N; ++i)
		for(int j=0; j<N; ++j)
			protects[i][j] |= protects[i][k] & protects[k][j];

		int cand = N;

		graph G(N*2);
		for(int i=0; i<N; ++i)
			if(protects[i][i]) {
				--cand;
			} else {
				for(int j=0; j<N; ++j)
					if(protects[i][j] && !protects[j][j])
						G[i].push_back(N+j);
			}

		return cand - biMatch<512>(G, N);
	}
};

// 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(_, Incubator().maxMagicalGirls(love));}
int main(){

CASE(0)
	string love_[] = {"NY","NN"};
	  vector <string> love(love_, love_+sizeof(love_)/sizeof(*love_)); 
	int _ = 1; 
END
CASE(1)
	string love_[] = {"NYN", "NNY", "NNN"};
	  vector <string> love(love_, love_+sizeof(love_)/sizeof(*love_)); 
	int _ = 1; 
END
CASE(2)
	string love_[] = {"NNYNN","NNYNN","NNNYY","NNNNN","NNNNN"};
	  vector <string> love(love_, love_+sizeof(love_)/sizeof(*love_)); 
	int _ = 2; 
END
CASE(3)
	string love_[] = {"NNNNN","NYNNN","NYNYN","YNYNN","NNNNN"};
	  vector <string> love(love_, love_+sizeof(love_)/sizeof(*love_)); 
	int _ = 2; 
END
CASE(4)
	string love_[] = {"NNNNN","NNNNN","NNNNN","NNNNN","NNNNN"};
	  vector <string> love(love_, love_+sizeof(love_)/sizeof(*love_)); 
	int _ = 5; 
END
CASE(5)
	string love_[] = {"NNYNNNNN","NNNYNNNN","NNNNYNNN","NNYNNNNN","NNNNNYYN","NNNYNNNY","NNNNNNNN","NNNNNNNN"};
	  vector <string> love(love_, love_+sizeof(love_)/sizeof(*love_)); 
	int _ = 2; 
END
CASE(6)
	string love_[] = {"Y"};
	  vector <string> love(love_, love_+sizeof(love_)/sizeof(*love_)); 
	int _ = 0; 
END
CASE(7)
	string love_[] = {"NYNNN", "NNYNN", "NNYYY", "NNYYY", "NNYYY"};
	  vector <string> love(love_, love_+sizeof(love_)/sizeof(*love_)); 
	int _ = 1; 
END
CASE(8)
string love_[] = {"NNYYYYY", "NNYYYYY", "NNNNNNN", "NNNYYYY", "NNNYYYY", "NNNYYYY", "NNNYYYY"};
	  vector <string> love(love_, love_+sizeof(love_)/sizeof(*love_)); 
	int _ = 2; 
END
}
// END CUT HERE
