LearnPy Hub
← Arena
IntermediateRating 1100

Frog on Stones

A frog starts on stone 1 and wants to reach stone n. From stone i it can hop to i + 1 or i + 2, paying |hᵢ − hⱼ| for the hop. Print the least total cost.

Input

n, then n heights.

Output

One integer.

Sample 1

Input
4
10 30 40 20
Output
30

Sample 2

Input
2
10 10
Output
0
solution.py
Output appears here
Frog on Stones · Python Arena problem · LearnPy Hub