CF1472C.Long Jumps

传统题 时间 2000 ms 内存 256 MiB 5 尝试 1 已通过 1 标签

Long Jumps

Polycarp found under the Christmas tree an array aa of nn elements and instructions for playing with it:

  • At first, choose index ii (1in1 \leq i \leq n) — starting position in the array. Put the chip at the index ii (on the value aia_i).
  • While ini \leq n, add aia_i to your score and move the chip aia_i positions to the right (i.e. replace ii with i+aii + a_i).
  • If i>ni \gt n, then Polycarp ends the game.

For example, if n=5n = 5 and a=[7,3,1,2,3]a = [7, 3, 1, 2, 3], then the following game options are possible:

  • Polycarp chooses i=1i = 1. Game process: i=1+78i = 1 \overset{+7}{\longrightarrow} 8. The score of the game is: a1=7a_1 = 7.
  • Polycarp chooses i=2i = 2. Game process: $i = 2 \overset{+3}{\longrightarrow} 5 \overset{+3}{\longrightarrow} 8$. The score of the game is: a2+a5=6a_2 + a_5 = 6.
  • Polycarp chooses i=3i = 3. Game process: $i = 3 \overset{+1}{\longrightarrow} 4 \overset{+2}{\longrightarrow} 6$. The score of the game is: a3+a4=3a_3 + a_4 = 3.
  • Polycarp chooses i=4i = 4. Game process: i=4+26i = 4 \overset{+2}{\longrightarrow} 6. The score of the game is: a4=2a_4 = 2.
  • Polycarp chooses i=5i = 5. Game process: i=5+38i = 5 \overset{+3}{\longrightarrow} 8. The score of the game is: a5=3a_5 = 3.

Help Polycarp to find out the maximum score he can get if he chooses the starting index in an optimal way.

Input

The first line contains one integer tt (1t1041 \leq t \leq 10^4) — the number of test cases. Then tt test cases follow.

The first line of each test case contains one integer nn (1n21051 \leq n \leq 2 \cdot 10^5) — the length of the array aa.

The next line contains nn integers a1,a2,,ana_1, a_2, \dots, a_n (1ai1091 \leq a_i \leq 10^9) — elements of the array aa.

It is guaranteed that the sum of nn over all test cases does not exceed 21052 \cdot 10^5.

Output

For each test case, output on a separate line one number — the maximum score that Polycarp can get by playing the game on the corresponding array according to the instruction from the statement. Note that Polycarp chooses any starting position from 11 to nn in such a way as to maximize his result.

Note

The first test case is explained in the statement.

In the second test case, the maximum score can be achieved by choosing i=1i = 1.

In the third test case, the maximum score can be achieved by choosing i=2i = 2.

In the fourth test case, the maximum score can be achieved by choosing i=1i = 1.

Samples

4
5
7 3 1 2 3
3
2 1 4
6
2 1000 2 3 995 1
5
1 1 1 1 1
7
6
1000
5

在线编程 IDE

建议全屏模式获得最佳体验