Download as pdf or txt
Download as pdf or txt
You are on page 1of 2

12/6/2019

Pawn Prime Jump


The game is played with a single pawn on n cells arranged in a single row and numbered from 0 to n-1 from left to
right.

Each cell has a value assigned to it.

Whenever the pawn enters a cell, the value of the cell is added to your score.

Initially, your score is 0 and your pawn is standing at cell 0.

In a single move, you can move the pawn right by either 1 cell or p cells where p is a prime number having the
least significant digit equal to 3. Remember! You must not place the pawn out of the row.

The game ends after your pawn steps on cell n-1 (the value of this cell is also added to the score). The goal is to
maximize the score after the end of the game. What's the maximum possible score you can achieve?

For instance, let n = 5 so we have 5 cells numbered from 0 to 4 and let their values be 0, -10, -20, -30, 50. Then the best
we can do is the following: the pawn starts at cell 0 and we can reach cells 1 and 3 from it (reaching cell 1 is possible
because advancing to next cell is always allowed provided such cell exists, and reaching cell 3 is possible because
advancing the pawn by p cells forward is possible when p is prime ending with digit 3, and 3 is such a prime, so moving
the pawn from cell 0 to cell 3 is possible). The better move from these two moves is moving the pawn to cell 1 and only
then moving it to cell 4 - advancing by 3 cells forward - and ending the game. By doing that we collect (-10) + 50 coins
from cells 1 and 4 respectively ending the game with 40 coins which is the best possible outcome.

Input Format

The first contains a single integer n. After that, n lines follow. The i-th of them contains a single integer cell[i].

Constraints

1 ≤ n ≤ 104

-104 ≤ cell[i] ≤ 104

cell[0] = 0

Output Format

Output simply returns net score when pawn reaches n-1th cell i.e. an integer value.

Sample Input 0

4
0
-10
100
-20

Sample Output 0

70

1/2
Sample Input 1
12/6/2019

6
0
-100
-100
-1
0
-1

Sample Output 1

-2

Sample Input 2

4
0
1
2
3

Sample Output 2

2/2

You might also like