program aaa

integer :: n, i
integer,allocatable,dimension(:) :: h, dp

read*, n
allocate(h(n))
allocate(dp(n))
read*, h

dp=0
dp(1)=0
dp(2)=abs(h(2)-h(1))

if(n==2) then
write(*,'(i0)') dp(2)
return
end if

do i=3, n
dp(i)=min(dp(i-2)+abs(h(i-2)-h(i)),dp(i-1)+abs(h(i-1)-h(i)))
end do

write(*,'(i0)') dp(n)

end program
