<pre>import java.awt.List;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Collections;
import java.util.LinkedList;


public class Jump {
	
	public static int pole[];
    public static int indexy[];
public static void main(String[] args) throws IOException {
		
		BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
		
		String line = &quot;&quot;;

		boolean pop = true;
		
		while(!(line = in.readLine()).equals(&quot;0&quot;)) {
			
			line = in.readLine();
			
			String split[] = line.split(&quot; &quot;);
			
			pole = new int[split.length];
			
			for (int i = 0; i &lt; pole.length; i++) {
				pole[i] = Integer.parseInt(split[i]);
			}
			

			indexy = new int[pole.length];
			rekur(0);
			
			
			
			for (int i = indexy.length -1; i &gt; 0; i--) {
				if (indexy[i] == 1) {
					System.out.println(i);
					break;
				}
			}
			
		}
	}

	public static void rekur(int index)
	{
		if (index == -1 || indexy[index] == 1)
			return;
		indexy[index] = 1;
		
	    for (int i = index +1; i &lt; pole.length; i++)
	    	if (pole[index] + pole[i] ==  i - index &amp;&amp; indexy[i] == 0)
	    		rekur(i);
	            
		for (int i = index -1; i &gt; 0; i--) {
			if (pole[index] + pole[i] == Math.abs(index - i) &amp;&amp; indexy[i] == 0) {
				rekur(i);
	        }
	    }
	}

}
</pre>
