atcoder#MSOLUTIONS2019F. Random Tournament

Random Tournament

Score : 10001000 points

Problem Statement

We will host a rock-paper-scissors tournament with NN people. The participants are called Person 11, Person 22, \ldots, Person NN. For any two participants, the result of the match between them is determined in advance. This information is represented by positive integers Ai,jA_{i,j} ( 1j<iN1 \leq j < i \leq N ) as follows:

  • If Ai,j=0A_{i,j} = 0, Person jj defeats Person ii.
  • If Ai,j=1A_{i,j} = 1, Person ii defeats Person jj.

The tournament proceeds as follows:

  • We will arrange the NN participants in a row, in the order Person 11, Person 22, \ldots, Person NN from left to right.
  • We will randomly choose two consecutive persons in the row. They will play a match against each other, and we will remove the loser from the row. We will repeat this process N1N-1 times, and the last person remaining will be declared the champion.

Find the number of persons with the possibility of becoming the champion.

Constraints

  • 1N20001 \leq N \leq 2000
  • Ai,jA_{i,j} is 00 or 11.

Input

Input is given from Standard Input in the following format:

NN

A2,1A_{2,1}

A3,1A_{3,1}A3,2A_{3,2}

::

AN,1A_{N,1}\ldotsAN,N1A_{N,N-1}

Output

Print the number of persons with the possibility of becoming the champion.

3
0
10
2

Person 11 defeats Person 22, Person 22 defeats Person 33 and Person 33 defeats Person 11. If Person 11 and Person 22 play the first match, Person 33 will become the champion. If Person 22 and Person 33 play the first match, Person 11 will become the champion.

6
0
11
111
1111
11001
3