#include <iostream>
#include <vector>
#include <array>
#include <stack>
using namespace std;

struct Node {
	int val;
	vector<int> points;
};
Node nodes[1000000];
array<bool,1000000> hits;

int rec(int top);
int rec(int top) {
	int max = top;
	if(!hits[top]) {
		hits[top] = true;
		for(int a : nodes[top].points) {
			if(!hits[a]) {
				int tmp = rec(a);
				if(tmp > max) max = tmp;
			}
		}
	}
	return max;
}

int main() {
	int k;
	while(cin >> k) {
		if(k==0) break;
		
		for(int i = 0; i<k; i++) {
			int m;
			cin >> m;
			nodes[i].val = m;
			nodes[i].points.clear();
			int a = i-m;
			for(int l = 0; l<=a; l++) {
				if(i-l == nodes[l].val+nodes[i].val) {
					nodes[i].points.push_back(l);
					nodes[l].points.push_back(i);
				}
			}
		}
		hits.fill(false);
		cout << rec(0) << endl;
	}
	return 0;
}