cswork / OAOpen practice workspace

UberOA #15

Prime Jumps — Maximum Game Score

Estimated MediumJudge-ready

Topics (AI-labelled)DP BasicsBits & Math

Start at cell 0 with a score of 0. Each move jumps 1 cell to the right, or jumps a prime number of cells whose last decimal digit is 3. The value of the landing cell is added to the score, and you must finish at n−1. Find the highest score.

This site's standard input/output is stated explicitly.

Input

The first line contains n, and the second line contains n cell values. 1≤n≤10000, −10000≤cell[i]≤10000, cell[0]=0.

Output

Output one integer answer.

Example 1

Input:

5
0 -10 -20 -30 50

Output:

40

Example 2

Input:

1
0

Output:

0

Example 3

Input:

4
0 1 1 1

Output:

3

Example notes

Example 1: 0→1→4 scores −10+50=40, which beats the 20 obtained by jumping 3 first. Example 2: the start is the end, so the score is 0. Example 3: moving cell by cell gives 3, and skipping positive cells is never better.

Editorial

Loading solution…