Joey and the journey to become a film star
/

Problem
Editorial
Analytics

## Joey and the journey to become a film star

We all know how much Joey loves acting. Now his dream to become an actor is really close. All that is left is to pass the forest of DEATH. Forest of death is a place that takes away your life energy and ultimately you die. This forest also has many potions to restore your energy. The only way to cross the forest is by collecting maximum potions. Joey can start his journey from any location at head of forest (1st row) and has to reach the tail of forest (last row). Joey wants to know the maximum amount of potion that he can get when the journey is finished. from [i,j] , he can go to [i+1,k] iff abs(j-k) is a prime.

Input:

The first line has N ans M (Rows and columns)

Then N lines follows each having M values denoting amount of potion at that location.

Output:

Maximum amount of potion at the end.

Constraints:

$1\leq N , M \leq 800$

$1\leq F[i][j] \leq 10^{5}$

Problem Setter - Satyarth

SAMPLE INPUT
3 3
1 2 3
4 5 6
7 8 9
SAMPLE OUTPUT
16
Time Limit: 0.5 sec(s) for each input file.
Memory Limit: 256 MB
Source Limit: 1024 KB

## This Problem was Asked in

Initializing Code Editor...