/*
 * 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 wintadd;

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.TreeMap;

/**
 *
 * @author olesnanik2
 */
public class Yoshi {
    static public int pebbles;
    static public boolean[] reached = new boolean[1000000];
    static public LinkedList<Integer> queue = new LinkedList<>();
    
    static public int[] pluses = new int[1000000];
    static public int[] minuses = new int[1000000];
    
    static public int nextAvailable = 0;
    static public int[][] array = new int[2000000][3];
    static public HashMap<Integer, int[]> mapPlus = new HashMap<>();
    static public HashMap<Integer, int[]> mapMinus = new HashMap<>();
    
    /*static public HashSet<Integer> reachedPluses = new HashSet<>();
    static public HashSet<Integer> reachedMinuses = new HashSet<>();*/
    
    public static void map(HashMap<Integer, int[]> map, int k, int v) {
        if (!map.containsKey(k)) {
            map.put(v, array[nextAvailable]);
            array[nextAvailable][0] = k;
            array[nextAvailable][1] = -1;
            array[nextAvailable][2] = nextAvailable;
        } else {
            int[] orig = map.get(k);
            map.put(v, array[nextAvailable]);
            array[nextAvailable][0] = k;
            array[nextAvailable][1] = orig[2];
            array[nextAvailable][2] = nextAvailable;
        }
        
        nextAvailable++;
    }
    
    public static void main(String [] arguments) throws Exception {
        BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
        
        while(true) {
            nextAvailable = 0;
            mapPlus.clear();
            mapMinus.clear();
            
            pebbles = nextInt(reader);
            if (pebbles == 0) {
                break;
            }
            for (int p=0; p<pebbles; p++) {
                int spots = nextInt(reader);
                reached[p] = false;
                map(mapPlus, p, spots+p);
                map(mapMinus, p, spots-p);
                pluses[p] = spots+p;
                minuses[p] = spots-p;
            }
            
            queue.clear();
            queue.add(0);
            
            int maximalReach = 0;
            
            while(!queue.isEmpty()) {
                int item = queue.removeFirst();
                maximalReach = Math.max(maximalReach, item);
                reached[item] = true;
                
                int plus = pluses[item];
                int minus = minuses[item];
                
                /*reachedPluses.add(plus);
                reachedMinuses.add(minus);*/
                
                // going right
                int[] ar = mapMinus.get(-plus);
                while(ar != null) {
                    process(item, ar[0]);
                    break;
                    /*if (ar[1] == -1) {
                        break;
                    } else {
                        ar = array[ar[1]];
                    }*/
                }
                
                ar = mapPlus.get(-minus);
                while(ar != null) {
                    process(item, ar[0]);
                    break;
                    /*if (ar[1] == -1) {
                        break;
                    } else {
                        ar = array[ar[1]];
                    }*/
                }
            }
            
            System.out.println(maximalReach);
        }
    }
    
    public static void process(int item, int nextItem) {
        if (reached[nextItem]) return;
            queue.add(nextItem);
    }
    
    public static int nextInt(BufferedReader reader) throws Exception {
        int n = 0;
        char c;
        while(true) {
            c = (char)reader.read();
            if (c == 0 || c == ' ' || c == '\n') {
                return n;
            }
            n *= 10;
            n += c - '0';
        }
    }
}