Splitting the Seminar into Two Groups

No attempts yetTime limit1sMemory limit128 MB

Problem

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.

Input

The first line contains the number of students NN. (1N501 \le N \le 50)

The second line contains the grade of each student with no spaces. The ii-th character is the grade GiG_i of student ii. (1Gi31 \le G_i \le 3)

Each of the next NN lines contains the relations with no spaces. The jj-th character on line i+2i+2 is 'Y' when student ii and student jj 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'.

Output

Print the largest number of students that can attend the seminar.