Problem:
Score : 1000 points

Problem Statement

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

If A_{i,j} = 0, Person j defeats Person i.

If A_{i,j} = 1, Person i defeats Person j.

The tournament proceeds as follows:

We will arrange the N participants in a row, in the order Person 1, Person 2, \ldots, Person N 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 N-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

1 \leq N \leq 2000

A_{i,j} is 0 or 1.

Input

Input is given from Standard Input in the following format:

N
A_{2,1}
A_{3,1}A_{3,2}
:
A_{N,1}\ldotsA_{N,N-1}

Output

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

Sample Input 1

3
0
10

Sample Output 1

2

Person 1 defeats Person 2, Person 2 defeats Person 3 and Person 3 defeats Person 1.
If Person 1 and Person 2 play the first match, Person 3 will become the champion.
If Person 2 and Person 3 play the first match, Person 1 will become the champion.

Sample Input 2

6
0
11
111
1111
11001

Sample Output 2

3

Solution in C++14 (GCC 5.4.1) (judge verdict: Accepted)

// #define _GLIBCXX_DEBUG // for STL debug (optional)
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>
using namespace std;

#define debug(...) fprintf(stderr, __VA_ARGS__)

template<typename T> void chmax(T &a, T b) {a = max(a, b);}
template<typename T> void chmin(T &a, T b) {a = min(a, b);}
template<typename T> void chadd(T &a, T b) {a = a + b;}
 
typedef pair<int, int> pii;
typedef long long ll;
 
int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
const ll INF = 1001001001001001LL;
const ll MOD = 1000000007LL;

bitset<2020> win[2020];
bitset<2020> dp[2][2020];
signed main() {
    int N; scanf("%d", &N);
    
    for(int i=0; i<N; i++) {
        for(int j=0; j<i; j++) {
            char c; scanf(" %c", &c);
            bool p = c - '0';
            win[i][j] = p;
            win[j][i] = !p;
        }
    }

    for(int i=0; i<N; i++) dp[0][i][i] = dp[1][i][i] = true;
    for(int d=1; d<N; d++) {
        for(int i=0; i<N-d; i++) {
            int j = i + d;
            bool f1 = (dp[0][j] & dp[1][i+1] & win[i])._Find_next(i  ) <= j;
            bool f2 = (dp[1][i] & dp[0][j-1] & win[j])._Find_next(i-1) <= j-1;
            dp[0][j][i] = f1, dp[1][i][j] = f2;
        }
    }

    int ans = 0;
    for(int i=0; i<N; i++) ans += (dp[0][N-1][i] & dp[1][0][i]);
    printf("%d\n", ans);
    return 0;
}