program flog1
    implicit none
    integer::n,i,dis1,dis2
    integer,allocatable::a(:),b(:)
    read*,n
    allocate(a(n),b(n))
    a = 0
    read*,b
    a(1) = 0
    a(2) = abs(b(2) - b(1))
    do i = 2,n
        dis1 = a(i-1) + abs(b(i)-b(i-1))
        dis2 = a(i-2) + abs(b(i)-b(i-2))
        a(i) = min(dis1,dis2)
    end do
    print"(i0)",a(n)
    stop
end program flog1