Principal Jang Hong-jun of Daegu Science High School is holding a seminar for the tenth anniversary of his appointment. To run it smoothly he splits the students who attend into two groups.
The principal has always treated communication between students as important, so he never puts two students who dislike each other in the same group. On top of that, all attending students of one grade have to go into the same group.
Dislike happens only between two students of different grades. Two students in the same grade never dislike each other.
After many attempts the principal found that keeping both rules while the whole school attends is impossible. He now wants as many students as possible to come while both rules still hold. A student who does not attend joins neither group, so the two rules say nothing about that student.
Write a program that finds the largest number of students that can attend the seminar.
The first line contains the number of students N. (1≤N≤50)
The second line contains the grade of each student with no spaces. The i-th character is the grade Gi of student i. (1≤Gi≤3)
Each of the next N lines contains the relations with no spaces. The j-th character on line i+2 is 'Y' when student i and student j dislike each other, and 'N' otherwise. The table is symmetric about its diagonal, and the diagonal positions and the positions for two students of the same grade are always 'N'.
Print the largest number of students that can attend the seminar.