#include <iostream>
#include <stdio.h>
#include <string>
#include <list>
#include <vector>
#include <unordered_map>

using namespace std;

int maxv;

	std::unordered_map< int, list<int> > table;

	std::unordered_map< int, bool > bylsem;

	unordered_map<int, list<int> > nasl;


void dfs(int start)
{
	if(start > maxv)
	{
		maxv = start;		
	}
	
	for(auto it = nasl[start].begin(); it != nasl[start].end(); ++it)
	{
		if(bylsem[*it] == false)
		{
			bylsem[*it] = true;
			dfs(*it);
		}		
	}
}


int main()
{
	maxv = -1;
	
	int N;
	cin >> N;


	while(N != 0)
	{
		maxv = -1;
		table.clear();
		nasl.clear();
		bylsem.clear();

		for(int i = 0; i < N; i++)
		{
			int cislo = 0;
			cin >> cislo;

			auto search1 = table.find(-cislo+i);
			if(search1 != table.end())
			{
				for(auto it = search1->second.begin(); it != search1->second.end(); ++it)
				{
                    int a = *it;
					nasl[a].push_back(i);
					nasl[i].push_back(a);
				}
			}
			table[cislo+i].push_back(i);
		}
		
		dfs(0);	
		cout << maxv << endl;
		
		cin >> N;
	}

	return 0;
}