<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 LinkedList&lt;Integer&gt; 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;)) {
			int pocet = Integer.parseInt(line);
			
			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 LinkedList&lt;Integer&gt;();
			rekur(0, indexy);
			
			Collections.sort(indexy);
			
			
			System.out.println(indexy.getLast());
			
		}
	}

	public static void rekur(int index, LinkedList&lt;Integer&gt; list)
	{
		if (index == -1 || list.contains(index))
			return;
		list.add(index);
		//System.out.println(index);
	            for (int i = index +1; i &lt; pole.length; i++)
	                if (pole[index] + pole[i] ==  i - index &amp;&amp; !indexy.contains(i))
	                    rekur(i, list);
	            
		for (int i = index -1; i &gt; 0; i--) {
			if (pole[index] + pole[i] == Math.abs(index - i) &amp;&amp; !indexy.contains(i)) {
	                        rekur(i, list);
	                    }
	            }
	}

}
</pre>
