#include <stdio.h>
#include <stdlib.h>
#include <vector>

#define ABS(X) ( ((X) < (0)) ? -(X) : (X) )

using namespace std;

typedef struct peb{
	int spots;				// number of spots on this pebble
	bool visited;			// visited? TRUE/FALSE	
	vector<int> next;				// array of indexes of reachable pebbles (zero means end)
} PEB;

int main(){
	int N;
	PEB *p = NULL; 

	
	while(scanf("%d", &N)){
		if (N == 0) break; //test-case input is terminated by zero

		free(p);
		p = (PEB *) calloc(1000000, sizeof(PEB));

		// read input
		for (int i = 0; i < N; ++i)
			scanf("%d", &(p[i].spots));

		// pre-calculate reachable pebbles
		for (int i = 0; i < N; ++i){
			for (int j = 0; j < N; ++j){
				if (i==j) continue;
				if ( (ABS(i-j)) == (p[i].spots + p[j].spots) )	
					p[i].next.push_back(j);
			}
		}

		// search the tree (widely), remember MAX reached
		int max = -1;
		vector<int> stack;	// indexes of pebbles to be visited
		stack.push_back(0);	// push starting pebbl

		// for every to be visited
		while(stack.size() > 0){
			int cur = stack.back(); 
			stack.pop_back();

//			printf("cur = %d\n", cur); 

			p[cur].visited=true;
			
			while(p[cur].next.size()>0){
				int n = p[cur].next.back();
				p[cur].next.pop_back();
				if (p[n].visited == false) stack.push_back(n);
			}
			
			if (cur > max) max = cur;
		}
		// print result		
		printf("%d\n", max);

	}


	return 0;
}