/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package Jump;

import java.util.Scanner;

/**
 *
 * @author cteam032
 */
public class Jump {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        Jump jump = new Jump();
        jump.start();
    }
    
    void start() {
        boolean go = true;
        int pebbles;
        int[] spots;
        int[] keys;
        int k;
        int point;
        boolean[] way;
        Scanner scan = new Scanner(System.in);
        while(true) {
            k = 0;
            point = 0;
            pebbles = scan.nextInt();
            if(pebbles == 0) {
                break;
            }
            keys = new int[pebbles];
            spots = new int[pebbles];
            way = new boolean[pebbles];
            for(int i = 0; i < pebbles;i++) {
                spots[i] = scan.nextInt();
            }
            keys[0] = 0;
            way[0] = true;
            k++;          
            do{
                for(int i=0;i<pebbles;i++) {
                    if(!way[i]) {
                        if(spots[i]+spots[keys[point]] == Math.abs(keys[point]-i)) {
                            way[i] = true;
                            keys[k] = i;
                            k++;
                        }
                    }
                }
                point++;
            }while(point < pebbles && keys[point]!=0); 
            int max = 0;
            for(int i = 0; i<point;i++) {
                if(keys[i]>max) {
                    max = keys[i];
                }
            }           
            System.out.println(max);
        }
    }
    
}