#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 <cstring>
using namespace std;

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

static const int NV = 100;
int biMatch( graph& G, int L ) // [0,L):left, [L,?):right
{
	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 PeopleYouMayKnow { public:
	int maximalScore(vector <string> friends, int personA, int personB) 
	{
		int removed = 0;

		// A-C-B : C must be removed
		int N = friends.size();
		int A = personA, B = personB;
		for(int C=0; C<N; ++C) if(C!=A && C!=B)
			if( friends[A][C]=='Y' && friends[C][B]=='Y' ) {
				removed ++;
				for(int D=0; D<N; ++D)
					friends[C][D] = friends[D][C] = 'N';
			}

		// A-A1, B1-B : A1-B1 must be disconnected
		vector<int> A1;
		for(int C=0; C<N; ++C) if(C!=A && C!=B)
			if( friends[A][C]=='Y' )
				A1.push_back(C);
		vector<int> B1;
		for(int C=0; C<N; ++C) if(C!=A && C!=B)
			if( friends[C][B]=='Y' )
				B1.push_back(C);

		// == bimatch
		graph G(A1.size()+B1.size());
		for(int a=0; a<A1.size(); ++a)
			for(int b=0; b<B1.size(); ++b)
				if( friends[A1[a]][B1[b]]=='Y' )
					G[a].push_back( A1.size()+b );
		return removed + biMatch(G, A1.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(_, PeopleYouMayKnow().maximalScore(friends, personA, personB));}
int main(){

CASE(0)
	string friends_[] = {"NN"
,"NN"};
	  vector <string> friends(friends_, friends_+sizeof(friends_)/sizeof(*friends_)); 
	int personA = 0; 
	int personB = 1; 
	int _ = 0; 
END
CASE(1)
	string friends_[] = {"NYNN"
,"YNYN"
,"NYNY"
,"NNYN"};
	  vector <string> friends(friends_, friends_+sizeof(friends_)/sizeof(*friends_)); 
	int personA = 0; 
	int personB = 3; 
	int _ = 1; 
END
CASE(2)
	string friends_[] = {"NYNYYYN"
,"YNYNNYY"
,"NYNNNNY"
,"YNNNNNN"
,"YNNNNYN"
,"YYNNYNY"
,"NYYNNYN"};
	  vector <string> friends(friends_, friends_+sizeof(friends_)/sizeof(*friends_)); 
	int personA = 2; 
	int personB = 3; 
	int _ = 1; 
END
CASE(3)
	string friends_[] = {"NYYYYNNNN"
,"YNNNNYYYN"
,"YNNNNNNYN"
,"YNNNNNNYN"
,"YNNNNNNNY"
,"NYNNNNNNY"
,"NYNNNNNNY"
,"NYYYNNNNY"
,"NNNNYYYYN"};
	  vector <string> friends(friends_, friends_+sizeof(friends_)/sizeof(*friends_)); 
	int personA = 8; 
	int personB = 0; 
	int _ = 3; 
END

}
// END CUT HERE
