Skip to main content
Tuesday (24.11.2026) at 20:00: ALGOR Contest: Round #4 (Special Challenge) starts!

~/algor $ cat problems/dp-qurbaqa-sakrashi

Frog jumps

Easy 1000 ms 128 MB 20%
Share

$n$ stones lie in a row in a stream, numbered from $1$ to $n$; the height of the $i$-th stone is $h_{i}$. A frog sits on stone $1$ and wants to get to stone $n$. From stone $i$ it can jump to stone $i + 1$ or $i + 2$; a jump from stone $i$ to stone $j$ costs $|h_{i} - h_{j}|$ energy. What is the smallest amount of energy the frog will spend?

Stone heights as columns; the frog's jumps with the least energy are highlighted with arcs

Input

The first line contains a positive integer $n$. The second line contains $n$ space-separated positive integers $h_{i}$.

Output

One integer — the smallest energy spent.

Note

$1 \le n \le 10^{5}$
$1 \le h_{i} \le 10^{4}$

Examples

Input #1
4
10 30 40 20
Output #1
30
Input #2
1
5
Output #2
0

Sign in to submit a solution

Signing up is free and takes a minute.