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: Wrong Answer)

#include<bits/stdc++.h>
#define X first
#define Y second
#define pb emplace_back
#define FOR(i,a,b) for(int (i)=(a);i<(b);++(i))
#define EFOR(i,a,b) for(int (i)=(a);i<=(b);++(i))
#define rep(X,Y) for (int (X) = 0;(X) < (Y);++(X))
#define REP rep
#define rrep(X,Y) for (int (X) = (Y)-1;(X) >=0;--(X))
#define all(X) (X).begin(),(X).end()
#define eb emplace_back

using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef ll LL;
typedef pii PII;
typedef pll PLL;
const ll MOD=1e9+7;

#define rall(X) (X).rbegin(),(X).rend()
#define UNIQUE(X) (X).erase(unique(all(X)),(X).end())
#define reps(X,S,Y) for (int (X) = S;(X) < (Y);++(X))
#define rreps(X,S,Y) for (int (X) = (Y)-1;(X) >= (S);--(X))
template<class T> inline bool MX(T &l,const T &r){return l<r?l=r,1:0;}
template<class T> inline bool MN(T &l,const T &r){return l>r?l=r,1:0;}

using Event = pair<int, pii>;

int N;
int A[2145][2145];
bool used[2145];
vector<int> es[2145];
vector<Event> fs;
bool dp[2145][2][2145];
int mx[2145][2];

//bitset<2000> mat[2000];


signed main(){
  //ios_base::sync_with_stdio(false);
  //cout<<fixed<<setprecision(0);

  scanf("%d", &N);
  //cin >> N;
  reps(i, 1, N) {
    rep(j, i) {
      int w;
      scanf("%01d", &w);
      //cin >> w;
      if (w) {
        fs.eb(Event(i-j, pii(i, j)));
      } else {
        fs.eb(Event(i-j, pii(j, i)));
      }
      //A[i][j] = w;
      //A[j][i] = !w;
      //mat[i][j] = 1;
    }
  }
  sort(all(fs));

  rep(v, N) {
    rep(i, 2) {
      dp[v][i][0] = true;
    }
  }

  rep(g, 1) {
    for (auto &e : fs) {
      int l = e.X;
      int u = e.Y.X;
      int v = e.Y.Y;
      if (u < v) {
        if (mx[u][1]+mx[v][0]+1 >= l) {
          dp[u][1][l] = true;
          MX(mx[u][1], l);
          dp[u][1][l+mx[v][1]] = true;
          MX(mx[u][1], l+mx[v][1]);
        } 


        if (dp[v][0][l-1] || dp[u][1][l-1]) {
          dp[u][1][l] = true;
          MX(mx[u][1], l);
          dp[u][1][l+mx[v][1]] = true;
          MX(mx[u][1], l+mx[v][1]);
        }
      } else {
        if (mx[u][0]+mx[v][1]+1 >= l) {
          dp[u][0][l] = true;
          MX(mx[u][0], l);
          dp[u][0][l+mx[v][0]] = true;
          MX(mx[u][0], l+mx[v][0]);
        }

        if (dp[v][1][l-1] || dp[u][0][l-1]) {
          dp[u][0][l] = true;
          MX(mx[u][0], l);
          dp[u][0][l+mx[v][0]] = true;
          MX(mx[u][0], l+mx[v][0]);
        }
      }
    }
  }


  int ans = 0;
  rep(v, N) {
    if (dp[v][0][v] && dp[v][1][N-1-v]) ans++;
  }
  cout << ans << endl;
}