import Foundation
//漸化式
//var fib = [Int](repeating: 0, count: 100)
//fib[0] = 1
//fib[1] = 1
//for i in 2 ..< 50 {
//    fib[i] = fib[i-1] + fib[i-2]
//    print(fib[i])
//}


let N = Int(readLine()!)!
let h_line = readLine()!.split(separator: " ").map({Int($0)!})

var dp = [Int](repeatElement(0, count: 100))
var cost = 0
dp[0] = 0
dp[1] = h_line[1] - h_line[0]
for i in 2 ..< h_line.count {
    dp[i] = min(abs(h_line[2] - h_line[1]) + dp[i-1], abs(h_line[2] - h_line[0]) + dp[i-2])
}
print(dp.reduce(0, +))