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++ (GCC 9.2.1) (judge verdict: Wrong Answer)

#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <set>
#include <map>
#include <queue>
#include <random>
#include <chrono>
#include <tuple>
#include <random>
#include <cmath>
#include <bitset>

using namespace std;

#define fastInp cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(0);

typedef long long ll;
typedef long double ld;

const ll SZ = 2010;

ll n;
bitset<SZ> grid[SZ];
bitset<SZ> sv[SZ], sv2[SZ];
vector<ll> wn[SZ];

bool find(int l, int r) {
	if (l == r - 1) return 1;
	if (sv[l][r] != -1) return sv[l][r];

	int ind = lower_bound(wn[l].begin(), wn[l].end(), l) - wn[l].begin();
	while (ind < wn[l].size() && wn[l][ind] < r) {
		int i = wn[l][ind];
		bool fl1 = find(l, i);
		if (fl1) {
			if (find(i, r)) {
				sv[l][r] = 1;
				return 1;
			}
		}
		ind++;
	}

	ind = lower_bound(wn[r].begin(), wn[r].end(), l) - wn[r].begin();
	while (ind < wn[r].size() && wn[r][ind] < r) {
		int i = wn[r][ind];
		bool fl1 = find(l, i);
		if (fl1) {
			if (find(i, r)) {
				sv[l][r] = 1;
				return 1;
			}
		}
		ind++;
	}

	sv[l][r] = 0;
	return 0;
}

int main()
{
	fastInp;

	cin >> n;

	for (int i = 1; i <= n + 1; i++) {
		sv[i - 1][i] = 1;
		sv2[i][i - 1] = 1;
	}
	for (int i = 1; i < n; i++) {
		string s;
		cin >> s;
		for (int j = 0; j < s.size(); j++) {
			if (s[j] == '1') {
				grid[i][j] = 1;
			}
			else {
				grid[j][i] = 1;
			}
		}
	}

	for (int i = 2; i <= n + 1; i++) {
		for (int j = 0; j <= n; j++) {
			ll lft = j, rt = j + i;
			if (rt <= n + 1) {
				if ((sv[lft] & grid[lft]) != 0 || (sv2[rt] & grid[rt]) != 0) {
					sv[lft][rt] = 1;
					sv2[rt][lft] = 1;
				}
			}
		}
	}

	ll ans = 0;
	for (int i = 1; i <= n; i++) {
		if (sv[0][i] && sv[i][n + 1]) {
			ans++;
		}
	}

	cout << ans;

	return 0;
}