~/algor $ cat problems/dp-qurbaqa-sakrashi
Frog jumps
Easy
1000 ms
128 MB
20%
$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?
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