CF1472C Long Jumps

Description

Polycarp found under the Christmas tree an array $ a $ of $ n $ elements and instructions for playing with it: - At first, choose index $ i $ ( $ 1 \leq i \leq n $ ) — starting position in the array. Put the chip at the index $ i $ (on the value $ a_i $ ). - While $ i \leq n $ , add $ a_i $ to your score and move the chip $ a_i $ positions to the right (i.e. replace $ i $ with $ i + a_i $ ). - If $ i > n $ , then Polycarp ends the game. For example, if $ n = 5 $ and $ a = [7, 3, 1, 2, 3] $ , then the following game options are possible: - Polycarp chooses $ i = 1 $ . Game process: $ i = 1 \overset{+7}{\longrightarrow} 8 $ . The score of the game is: $ a_1 = 7 $ . - Polycarp chooses $ i = 2 $ . Game process: $ i = 2 \overset{+3}{\longrightarrow} 5 \overset{+3}{\longrightarrow} 8 $ . The score of the game is: $ a_2 + a_5 = 6 $ . - Polycarp chooses $ i = 3 $ . Game process: $ i = 3 \overset{+1}{\longrightarrow} 4 \overset{+2}{\longrightarrow} 6 $ . The score of the game is: $ a_3 + a_4 = 3 $ . - Polycarp chooses $ i = 4 $ . Game process: $ i = 4 \overset{+2}{\longrightarrow} 6 $ . The score of the game is: $ a_4 = 2 $ . - Polycarp chooses $ i = 5 $ . Game process: $ i = 5 \overset{+3}{\longrightarrow} 8 $ . The score of the game is: $ a_5 = 3 $ . Help Polycarp to find out the maximum score he can get if he chooses the starting index in an optimal way.

Input Format

N/A

Output Format

N/A

Explanation/Hint

The first test case is explained in the statement. In the second test case, the maximum score can be achieved by choosing $ i = 1 $ . In the third test case, the maximum score can be achieved by choosing $ i = 2 $ . In the fourth test case, the maximum score can be achieved by choosing $ i = 1 $ .