package com.apple.geo.autoedit.analytics.acm

import scala.collection.mutable.ArrayBuffer

/**
  * created by naumov on 12/14/19
  */
object Frog1 {


  def calculate(k: Int, h: ArrayBuffer[Int], res: ArrayBuffer[Int]): Int = {
    if (0 == k)
      return 0

    println(k)

    if (-1 == res(k)) {
      res(k) = calculate(k - 1, h, res) + Math.abs(h(k) - h(k - 1))
      //println(s"temp res: ${res(k)}")
      if (k >= 2) {
        res(k) = Math.min(res(k), calculate(k - 2, h, res) + Math.abs(h(k) - h(k - 2)))
      }
    }

    res(k)
  }

  def main(args: Array[String]): Unit = {

    val scanner = new java.util.Scanner(System.in)
    val n = scanner.nextInt()

    var h = new scala.collection.mutable.ArrayBuffer[Int](n)
    for (k <- 0 until n) {
      h.append(scanner.nextInt())
    }

    var res = collection.mutable.ArrayBuffer.fill(n)(-1)

    println(calculate(n-1, h, res))


  }

}
