World Cup Nominations

No attempts yetTime limit1sMemory limit128 MB

Problem

The football World Cup is held every four years, and hosting it is an honor worth a fierce campaign. The host is chosen by a vote.

The candidate countries are C1,C2,,CnC_1, C_2, \dots, C_n. Two of the countries still in the race are picked and put to a head to head vote, and the loser drops out. This repeats until one country is left, and that country becomes the host.

A poll has already been run. For any two countries we know which one wins their duel, and there are no ties. The same pair always ends the same way, no matter when the two meet.

Given the poll, count the countries that still have a chance of becoming the host. A country has a chance when some order of picking pairs leaves it as the last one standing.

Input

The input holds several test cases.

The first line of each test case contains the number of candidate countries nn (0<n10000 < n \le 1000). The next nn lines give the poll. The ii-th of them is a string of nin - i characters, each 0 or 1, whose jj-th character is 1 if CiC_i beats Ci+jC_{i+j} and 0 if Ci+jC_{i+j} beats CiC_i. The nn-th line of every test case is therefore empty.

The last line of the input contains a single 0.

Output

For each test case, print on one line the number of countries that can become the host according to the poll.