Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
N = int(input())
A = [int(x) for x in input().split()]
C = [0 for i in range(N)]
C[1] = A[1] - A[0]
for i in range(N-2):
C[i+2] = min(
C[i]+abs(A[i+2]-A[i]),
C[i+1]+abs(A[i+2]-A[i+1])
)
print(C[-1])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment