fun main(args: Array<String>) {
  	val N = readLine()!!.toInt()
    val costs = readLine()!!.split(" ").map{it.toInt()}
    val cost_sum = Array(N,{0})
  	for(i in 2..N){
    dp(i,cost_sum,costs)
      
    }
 	 print(cost_sum[N-1])
}

fun dp(size:Int,cost_sum:Array<Int>,costs:List<Int>){
    if (size===2){
        cost_sum[size-1]=Math.abs(costs[size-1]-costs[size-2])
    }else{
        cost_sum[size-1]=Math.min(
          cost_sum[size-2]+Math.abs(costs[size-1]-costs[size-2]),
          cost_sum[size-3]+Math.abs(costs[size-1]-costs[size-3])
          )
    }
}
