题目描述
Problem Description
There is an athletic facility with $ N $ wooden columns arranged in a row from left to right. The height of the $ i $-th column from the left is $ a_i $ centimeters.
Takahashi starts from the $ 1 $-st column and aims to reach the $ N $-th column by moving across the columns to the right.
When Takahashi is on a column, he can move to either the column that is $ 1 $ or $ 2 $ columns to the right of his current position.
The cost of moving is equal to the absolute difference in height between the current column and the column he moves to.
What is the minimum total cost to reach the $ N $-th column from the $ 1 $-st column?
Input Format
The input is given from the standard input in the following format:
$ N $ $ a_1 $ $ a_2 $ ... $ a_N $
Output Format
Output the minimum total cost required to move from the $ 1 $-st column to the $ N $-th column in one line.
Sample Input and Output
Sample Input #1
4
100 150 130 120
Sample Output #1
40
Sample Input #2
4
100 125 80 110
Sample Output #2
40
Sample Input #3
9
314 159 265 358 979 323 846 264 338
Sample Output #3
310
Notes/Hints
Constraints
- $2 \leq N \leq 100,000$
- $0 \leq a_i \leq 10,000$
- $ a_i $ are all integers.
Sample Explanation 1
In this case, the minimum cost can be achieved by the following moves:
- Move from the $ 1 $-st column to the $ 3 $-rd column. (Cost $ 30 $)
- Move from the $ 3 $-rd column to the $ 4 $-th column. (Cost $ 10 $)
The total cost is $ 40 $.
Sample Explanation 2
In this case, the minimum cost can be achieved by the following moves:
- Move from the $ 1 $-st column to the $ 2 $-nd column. (Cost $ 25 $)
- Move from the $ 2 $-nd column to the $ 4 $-th column. (Cost $ 15 $)
The total cost is $ 40 $.
输入格式
见题面 Input 部分
输出格式
见题面 Output 部分