<pre>import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

/**
 *
 * @author kuric10
 */
public class Jump {
    
    private static int pole[] = new int [1000001];
    private static int mnz[] = new int [1000001];
    private static int n;
    private static boolean b;
    private static int counter, a;
    
    
    public static void main(String[] args) throws IOException{
        
        BufferedReader input = new BufferedReader(new InputStreamReader(System.in));
        String line;
        String poleS[];
        int kt;
        int first;
        
        n = Integer.parseInt(input.readLine());
        while(n!=0){
            
            
            poleS = input.readLine().split(&quot; &quot;);
            for (int i = 0; i &lt; n; i++) {
                pole[i] = Integer.parseInt(poleS[i]);
                mnz[i] = -1;
                
            }
            
            spracuj();
            
            
            first = mnz[0];
            kt = 0;
            for (int i = 0; i &lt; n; i++) {
                if(mnz[i]==first)kt = i;
                //System.out.println(&quot;-&quot;+mnz[i]);
            }
            System.out.println(kt);
            
            n = Integer.parseInt(input.readLine());
        }
    }

    private static void spracuj() {
        int suc;
        for (int i = 0; i &lt; n; i++) {
            
            
            if(mnz[i]==-1){
                suc = counter++;
                mnz[i]= suc;
            }else{
                suc = mnz[i];
            }
                
                for (int j = i+pole[i]; j &lt; n; j++) {
                    if(j==i+pole[i]+pole[j]){
                        
                        if(mnz[j]!=-1){
                            prekresli(mnz[j], suc);
                        }else{
                            mnz[j] = suc;
                        }
                        
                    }
                }
                
            /*
            
            System.out.println(i+&quot; &quot;+pole[i]);
            for (int j = 0; j &lt; n; j++) {
                
                System.out.print(mnz[j]+&quot; &quot;);
            }System.out.println(&quot;&quot;);
            */
        }
    }

    private static void prekresli(int old, int suc) {
        
        for (int i = 0; i &lt; n; i++) {
            if(mnz[i]==old)mnz[i] = suc;
        }
    }
}
</pre>
