#include <iostream>
#include <list>
#include <cmath>

using namespace std;

int main()
{
    unsigned int N;
    cin >> N;
    while (1)
    {
        if (N == 0)
            return 0;
        unsigned int orig[N];
        list<int> index = list<int>();
        list<int> newindex = list<int>();
        list<int> toProcess = list<int>();
        for (unsigned int i = 0; i < N; i++)
        {
            cin >> orig[i];
            index.push_back(i);
        }
        index.pop_front();
        toProcess.push_back(0);
        unsigned int x;
        unsigned int max = 0;
        while (!toProcess.empty())
        {
            x = toProcess.front();
            if (x > max)
                max = x;
            toProcess.pop_front();
            newindex.clear();
            for (list<int>::iterator j = index.begin(); j != index.end(); j++)
            {
                if (orig[(*j)] + orig[x] == abs((int)((*j) - x)))
                {
                    toProcess.push_back(*j);
                }
                else
                {
                    newindex.push_back(*j);
                }
            }
            index = newindex;
        }
        cout << max << endl;
        cin >> N;
    }
    return 0;
}