Science!

No attempts yetTime limit3sMemory limit128 MB

Problem

Welcome to Aperture Science. For the experiment we have gathered $n$ people and $n$ buttons.

In each round, every person must stand on exactly one button, and no two people may share a button — so a single round is a one-to-one assignment of people to buttons. A person may only stand on the buttons they are cleared for.

We want to repeat this as many times as possible. The one extra rule is that, across all rounds, no person may ever stand on the same button more than once. Given who is cleared for which button, determine the maximum number of rounds $k$ that can be performed.

Input

The input contains several test cases. The first line of each case contains an integer $n$ ($2 \le n \le 80$), the number of people (which equals the number of buttons). Each of the next $n$ lines contains $n$ characters. If the $j$-th character of the $i$-th line is Y, person $i$ is allowed to stand on button $j$; otherwise it is N. A line containing a single 0 terminates the input.

Output

For each test case, output a single line containing $k$: the maximum number of rounds that can be performed so that in every round each person stands on a button they are allowed to use, each button holds exactly one person, and no person ever stands on the same button in two different rounds. This value may be $0$.