cho.sh
Notes
Loading...

Mountain Bike

Time limit

2s

Memory limit

128 MB

Problem

Dahae enjoys mountain biking. Sometimes she likes riding for a long time, but this time she wants to travel from the starting point of a mountain to the destination as quickly as possible.

The mountain is represented as an R by C grid. Each cell contains the height of that position. Dahae starts at (1, 1) and must reach (R, C). Her initial speed at (1, 1) is V. Each move goes to one adjacent cell in one of the four directions: up, down, left, or right. A speed of V means she can move V cells per unit time.

If the current cell has height A and the next cell has height B, then after completing that move her speed becomes 2A−B2^{A-B}2A−B times the current speed. In reality the speed would change during the move, but in this problem it changes only after a one-cell move is completed. Therefore, the time for a move is computed using the speed at the start of that move.

Given the mountain heights and the initial speed, write a program that finds the minimum time needed to move from (1, 1) to (R, C).

Input

The first line contains three integers V, R, and C. (1 ≤ V ≤ 1,000,000, 1 ≤ R ≤ 100, 1 ≤ C ≤ 100)

Each of the next R lines contains C integers, describing the height grid of the mountain. Each height is an integer between -25 and 25, inclusive.

Output

Print the minimum time needed for the trip. An absolute or relative error of at most 10−210^{-2}10−2 is accepted.