Jumping Yoshi

Starting from the first pebble, follow jumps allowed when two spot counts sum to their distance and report the farthest reachable pebble.

Medium6GraphBFSHash mapNo attempts yetTime limit2sMemory limit256 MB

Problem

Yoshi is a frog. He lives in the zoo under a log that was carried there whole from a distant equatorial rainforest. The log is big and wet, so it attracts flies, and that is what keeps Yoshi happy.

A line of pebbles runs through the wetland in front of the log. The pebbles carry dark spots, and Yoshi sometimes looks at them and pretends they are very big flies.

Yesterday his friend Addawser the camel came by and suggested a game.

"Do you see those spots on the pebbles?" asked Addawser. "Start on the leftmost pebble and jump from one pebble to another, with one restriction. You may jump between two pebbles only if the sum of the numbers of spots on them equals the distance between them. And you have to get to a pebble as far away as you can."

"All right, but you know that I can count at most to twenty three," hesitated Yoshi.

"No problem, I will help you with the bigger numbers," said Addawser.

The pebbles lie on a straight line and the distance between two neighbouring pebbles is exactly 11. A jump may go to the left or to the right. Starting from the first pebble, find the distance of the most distant pebble that can be reached by a sequence of jumps that follow the rule.

Input

The input holds several test cases. Each case starts with a line containing one integer NN (1N1061 \le N \le 10^6), the number of pebbles. The second line holds NN integers in the same order as the pebbles lie in the wetland, and the ii-th integer is the number of spots on the ii-th pebble. No pebble carries fewer than 00 or more than 10910^9 spots. The number of different pairs of pebbles that Yoshi can jump between never exceeds 10610^6.

The input ends with a line holding a single 00, which is not processed.

Output

For each test case, print one line with the distance of the pebble that is reachable by successive jumps under the rule and that is the most distant from the first pebble. Print 00 if no jump from the first pebble is possible.