#P10914. Stone Jumping Game

    ID: 12960 Type: Default 1000ms 256MiB

Stone Jumping Game

Stone Jumping Game

Little Ming is playing a stone jumping game with his friends. There are \( n \) stones arranged in a row, numbered from \( 1 \) to \( n \). The \( i^{th} \) stone has a positive integer weight \( c_i \).

If at any moment Little Ming is on stone \( j \), he can choose one of two jumps provided the destination is within bounds:

  • Jump to stone \( j + c_j \) if \( j + c_j \leq n \).
  • Jump to stone \( 2j \) if \( 2j \leq n \).

The game ends when no further jump is available. If Little Ming starts from stone \( x \), let \( S_x \) be the set of weights on all stones that can possibly be visited (a stone's weight is included only once even if visited multiple times). His score from starting at stone \( x \) is \( |S_x| \) (the number of distinct weights).

Your task is to determine the maximum score Little Ming can achieve by choosing an optimal starting stone.

inputFormat

The first line contains an integer \( n \) representing the number of stones. The second line contains \( n \) positive integers \( c_1, c_2, \dots, c_n \) which are the weights written on the stones.

outputFormat

Output a single integer, the maximum score Little Ming can obtain.

sample

5
1 1 1 1 1
1