PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN

#QHD0000001. Ếch nhảy 1 (Frog 1)

HỌC THEO LỘ TRÌNH

Bài tập thuộc lộ trình

1 lộ trình

Ếch nhảy 1 (Frog 1)

Frog 1

Source: AtCoder

Problem Statement

There are NN stones in a row, numbered from 11 to NN. Stone ii has height hih_i.

A frog starts on stone 11. From stone ii, it may jump to stone i+1i+1 or i+2i+2, provided that the destination exists. A jump from stone ii to stone jj costs ∣hi−hj∣|h_i-h_j| units of energy.

Determine the minimum total energy needed to reach stone NN.

Input

The first line contains an integer NN, the number of stones.

The second line contains NN integers h1,h2,…,hNh_1,h_2,\ldots,h_N, the heights in order.

Output

Print one integer: the minimum possible total energy cost.

Subtasks

  • Subtask 1 (20 points): 2≤N≤202\le N\le 20; 1≤hi≤1041\le h_i\le 10^4 (1≤i≤N1\le i\le N).
  • Subtask 2 (30 points): 2≤N≤5002\le N\le 500; 1≤hi≤1041\le h_i\le 10^4 (1≤i≤N1\le i\le N).
  • Subtask 3 (50 points): 2≤N≤1052\le N\le 10^5; 1≤hi≤1041\le h_i\le 10^4 (1≤i≤N1\le i\le N).

Examples

Input

4
10 30 40 20

Output

30

Explanation

Jumping along stones 1→2→41\to2\to4 costs ∣10−30∣+∣30−20∣=30|10-30|+|30-20|=30. No other permitted path has a lower total cost.