program EDPCA
    implicit none
    integer(8)::N,i
    integer(8),allocatable,dimension(:)::H,dp
    read(5,*)N
    allocate(H(N))
    allocate(dp(N))
    read(5,*)(H(i),i=1,N)
    dp=0

    do i=1,N
        if(i==2)then
            dp(i)=abs(H(i)-H(i-1))
        else if(i>2)then
            dp(i)=min(dp(i-1)+abs(H(i)-H(i-1)),dp(i-2)+abs(H(i)-H(i-2)))
        end if
    end do

    print'(i0)',dp(N)
end program EDPCA