ZhenlongDai/ACPR huggingface dataset:
Problem: p03160
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
def jumpCost(array):
    size = len(array)

    memo = [99999999999] * (size)

    memo[0] = 0

    for i in range(size):
        j = i+1

        while j < i + 2 + 1 and j < size:
            memo[j] = min(memo[j], memo[i] + abs(array[i] - array[j]))

            j += 1

    return memo[size - 1]


if __name__ == '__main__':
    n = int(input())

    a = list(map(int, input().rstrip().split()))
    jumpCost(a)

Failing test case input:
6
3 0 1 45 52 26

Expected output:
65


Actual output:

Fixed submission (verdict: Accepted):
def jumpCost(array):
    size = len(array)

    memo = [99999999999] * (size)

    memo[0] = 0

    for i in range(size):
        j = i+1

        while j < i + 2 + 1 and j < size:
            memo[j] = min(memo[j], memo[i] + abs(array[i] - array[j]))

            j += 1

    return memo[size - 1]


if __name__ == '__main__':
    n = int(input())

    a = list(map(int, input().rstrip().split()))
    print(jumpCost(a))

Problem: p03160
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
N = int(input())
h = list(map(int,input().split()))
cost = [1000000]*(N+10)
cost[0] = 0
for i in range(N - 1):
  cost[i+1] = min(abs(h[i] - h[i+1]), cost[i+1])
  if i < N - 3:
    cost[i+2] = min(abs(h[i] - h[i+2]), cost[i+2])
print(cost[N-1])

Failing test case input:
4
17 11 1 24

Expected output:
19


Actual output:
23


Fixed submission (verdict: Accepted):
N = int(input())
h = list(map(int,input().split()))
cost = [10**9]*N
cost[0] = 0
cost[1] = abs(h[1]-h[0])
for i in range(2, N):
  cost[i] = min((abs(h[i-1] - h[i]) + cost[i-1]),cost[i])
  cost[i] = min((abs(h[i-2] - h[i]) + cost[i-2]), cost[i])
print(cost[-1])

Problem: p03160
Buggy submission (Python (3.4.3), verdict: Wrong Answer):


N = int(input())
h = list(map(int, input().split()))
h.insert(0, 0)
inf = 10 ** 10

cost = [inf] * (N + 1)

cost[0] = 0
cost[1] = 0
for i in range(2, N + 1):
    cost_1 = cost[i-1] + abs(h[i] - h[i-1])
    cost_2 = cost[i-2] + abs(h[i] - h[i-2])
    cost[i] = min(cost_1, cost_2)

print(cost[N])


Failing test case input:
6
3 0 1 92 52 26

Expected output:
79


Actual output:
78


Fixed submission (verdict: Accepted):


N = int(input())
h = list(map(int, input().split()))
inf = 10 ** 10

cost = [inf] * N

cost[0] = 0
cost[1] = abs(h[1] - h[0])
for i in range(2, N):
    cost_1 = cost[i-1] + abs(h[i] - h[i-1])
    cost_2 = cost[i-2] + abs(h[i] - h[i-2])
    cost[i] = min(cost_1, cost_2)

print(cost[-1])
Problem: p03160
Buggy submission (Python (3.8.2), verdict: Wrong Answer):


def solution(h):
    n = len(h)
    if n == 1:
        return 0
    elif n == 2:
        return abs(h[1]-h[0])
    dp = [0]*(n)
    dp[1]  = abs(h[1]-h[0]) 
    for i in range(2,n):
        dp[i] = min( dp[i-1]+abs(h[i]-h[i-1]) , dp[i-2]+abs(h[i]-h[i-2]) )
    print(*dp)
    return dp[n-1]

N = int(input())
h = list(map(int,input().split()))
res = solution(h)
print(res)


Failing test case input:
4
0 -1 2 -156

Expected output:
156


Actual output:
0 1 2 156
156


Fixed submission (verdict: Accepted):


def solution(h):
    n = len(h)
    INF = float('inf')
    dp = [INF]*n
    dp[0] = 0
    for i in range(n):
        for j in range(i+1,i+3):
            if j < n:
                dp[j] = min(dp[j] , dp[i]+abs(h[i]-h[j]) )
    
    return dp[n-1]

N = int(input())
h = list(map(int,input().split()))
res = solution(h)
print(res)

Problem: p03160
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
import sys

N = int(input())
H = list(map(int,input().split()))

def frog1(n,h):
  s = [0]*n
  s[0] = 0
  s[1] = min(h[1],s[0]+abs(h[1]-h[0]))
  for i in range(2,n):
    s[i]=min(s[i-2]+abs(h[i]-h[i-2]),s[i-1]+abs(h[i]-h[i-1]))
  return s[n-1]

print(frog1(N,H))

Failing test case input:
4
0 -1 2 -52

Expected output:
52


Actual output:
50


Fixed submission (verdict: Accepted):
import sys

N = int(input())
H = list(map(int,input().split()))

def frog1(n,h):
  s = [0]*n
  s[0] = 0
  s[1] = abs(h[1]-h[0])
  for i in range(2,n):
    s[i]=min(s[i-2]+abs(h[i]-h[i-2]),s[i-1]+abs(h[i]-h[i-1]))
  return s[n-1]

print(frog1(N,H))

Problem: p03160
Buggy submission (Python (3.4.3), verdict: Wrong Answer):

N = int(input())
h_list = list(map(int, input().split()))
h_list = [0, 0] + h_list
dp = {}
dp[0] = 0
dp[1] = 0
for i in range(2, N + 2):
    dp[i] = min(dp[i - 2] + abs(h_list[i - 2] - h_list[i]), dp[i - 1] + abs(h_list[i - 1] - h_list[i]))
    if i == 2:
        dp[i] = 0
print(dp[N + 1])

Failing test case input:
4
1 0 0 -101

Expected output:
102


Actual output:
101


Fixed submission (verdict: Accepted):

N = int(input())
h_list = list(map(int, input().split()))
h_list = h_list
dp = {}
dp[0] = 0
dp[1] = abs(h_list[0] - h_list[1])
for i in range(2, N):
    dp[i] = min(dp[i - 2] + abs(h_list[i - 2] - h_list[i]), dp[i - 1] + abs(h_list[i - 1] - h_list[i]))
print(dp[N - 1])

Problem: p03160
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n = int(input())
h = list(map(int, input().split()))

dp = [0] * n
dp[1] = abs(h[1]-h[0])
for i in range(2, n):
    dp[i] = min(dp[i-1] + abs(h[i] - h[i-2]), dp[i-1] + abs(h[i] - h[i-1]))
print(dp[-1])

Failing test case input:
4
8 146 162 28

Expected output:
256


Actual output:
272


Fixed submission (verdict: Accepted):
n = int(input())
h = list(map(int, input().split()))

dp = [0] * n
dp[1] = abs(h[1]-h[0])
for i in range(2, n):
    dp[i] = min(dp[i-2] + abs(h[i] - h[i-2]), dp[i-1] + abs(h[i] - h[i-1]))
print(dp[-1])
Problem: p03160
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n = int(input())
h = list(map(int,input().split()))
cost = [0]*n
for i in range(1,n):
    cost[i] = cost[i-1] + abs(h[i]-h[i-1])
    if i > 1:
        if cost[i] > cost[i-1] + abs(h[i]-h[i-2]):
            cost[i] = cost[i-2] + abs(h[i]-h[i-2])
print(cost[n-1])

Failing test case input:
4
2 77 54 23

Expected output:
83


Actual output:
129


Fixed submission (verdict: Accepted):
n = int(input())
h = list(map(int,input().split()))
cost = [0]*n
cost[1] = abs(h[1]-h[0])
for i in range(2,n):
    cost[i] = min(cost[i-1] + abs(h[i]-h[i-1]) , cost[i-2] + abs(h[i]-h[i-2]))
print(cost[n-1])

Problem: p03160
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n = int(input())
lis = list(map(int,input().split()))
dp = [0] * n

dp[0] = 0
dp[1] = abs(lis[1] - lis[0])

for i in range(n-2):
    a = abs(lis[i+2] - lis[i+1])
    b = abs(lis[i+2] - lis[i])
    if a > b:
        dp[i+2] = b + dp[i]
    else:
        dp[i+2] = a + dp[i+1]
print(dp[n-1]) 

Failing test case input:
4
2 77 54 23

Expected output:
83


Actual output:
129


Fixed submission (verdict: Accepted):
n = int(input())
lis = list(map(int,input().split()))
dp = [0] * n

dp[0] = 0
dp[1] = abs(lis[1] - lis[0])

for i in range(n-2):
    a = abs(lis[i+2] - lis[i+1]) + dp[i+1]
    b = abs(lis[i+2] - lis[i]) + dp[i]
    dp[i+2] = min(a,b)
print(dp[n-1])

Problem: p03160
Buggy submission (PyPy3 (2.4.0), verdict: Wrong Answer):
n = int(input())
h = list(map(int, input().split()))

dp = [float('inf')]*n

dp[0] = 0

for i in range(1,n):
  dp[i] = min(dp[i-1]+abs(h[i]-h[i-1]), dp[i-1]+abs(h[i]-h[i-2]))

print(dp[n-1])

Failing test case input:
4
0 -1 2 -156

Expected output:
156


Actual output:
158


Fixed submission (verdict: Accepted):
n = int(input())
h = list(map(int, input().split()))

dp = [float('inf')]*n

dp[0] = 0
dp[1] = dp[0]+abs(h[1]-h[0])

for i in range(2, n):
  dp[i] = min(dp[i-1]+abs(h[i]-h[i-1]), dp[i-2]+abs(h[i]-h[i-2]))

print(dp[n-1])

Problem: p03160
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n = int(input())
h = list(map(int, input().split()))

dp = [0]*n
dp[0] = 0
dp[1] = abs(h[1] - h[0])

for i in range(2, n):
    dp[i] = min(dp[i-2] + abs(h[i] - h[i-1]), dp[i-1] + abs(h[i] - h[i-1]))
print(dp[-1])

Failing test case input:
6
2 0 26 92 65 14

Expected output:
114


Actual output:
104


Fixed submission (verdict: Accepted):
n = int(input())
h = list(map(int, input().split()))

dp = [0]*n
dp[0] = 0
dp[1] = abs(h[1] - h[0])

for i in range(2, n):
    dp[i] = min(dp[i-2] + abs(h[i] - h[i-2]), dp[i-1] + abs(h[i] - h[i-1]))
print(dp[-1])
Problem: p03160
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n=int(input())
A=list(map(int,input().split()))
inf=float("inf")
dp=[inf for i in range(n)]
dp[0]=0
dp[1]=abs(A[1]-A[0])
for i in range(2,n):
	dp[i]=min(dp[i],abs(dp[i-1]-dp[i]),abs(dp[i-2]-dp[i]))
print(dp[n-1])

Failing test case input:
6
30 10 60 10 60 57

Expected output:
33


Actual output:
inf


Fixed submission (verdict: Accepted):
n=int(input())
A=list(map(int,input().split()))
inf=float("inf")
dp=[inf for i in range(n)]
dp[0]=0
dp[1]=abs(A[1]-A[0])
for i in range(2,n):
	dp[i]=min(dp[i],abs(A[i-1]-A[i])+dp[i-1],abs(A[i-2]-A[i])+dp[i-2])
print(dp[n-1])

Problem: p03160
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n = int(input())
h = [0] + list(map(int, input().split()))

dp =[0, h[0]]

for i in range(2, n):
    dp += [min(dp[i-2] + abs(h[i] - h[i-2]), dp[i-1] + abs(h[i] - h[i-1]))]

print(dp[-1])

Failing test case input:
4
-2 1 2 -52

Expected output:
56


Actual output:
2


Fixed submission (verdict: Accepted):
n = int(input())
h = list(map(int, input().split()))

dp =[0, abs(h[1] - h[0])]

for i in range(2, n):
    dp += [min(dp[i-2] + abs(h[i] - h[i-2]), dp[i-1] + abs(h[i] - h[i-1]))]

print(dp[-1])

Problem: p03160
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n=int(input())
hs=input().rstrip().split(" ")
costs=[0 for i in range(n)]
costs[1]=abs(int(hs[1])-int(hs[0]))
for i in range(n-2):
    jump=costs[i]+abs(int(hs[i+2])-int(hs[i]))
    walk=costs[i+1]+abs(int(hs[i+1])-int(hs[i]))
    costs[i+2]=min(jump,walk)
print(costs[-1])

Failing test case input:
4
0 -1 2 -156

Expected output:
156


Actual output:
5


Fixed submission (verdict: Accepted):
n=int(input())
hs=input().rstrip().split(" ")
costs=[0 for i in range(n)]
costs[1]=abs(int(hs[1])-int(hs[0]))
for i in range(n-2):
    jump=costs[i]+abs(int(hs[i+2])-int(hs[i]))
    walk=costs[i+1]+abs(int(hs[i+2])-int(hs[i+1]))
    costs[i+2]=min(jump,walk)
print(costs[-1])

Problem: p03160
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
N=int(input())
a=input().rstrip().split()
  
asiba=[0]*N
asiba[0]=0
asiba[1]=abs(int(a[1])-int(a[0]))

for i in range(2,N):

    if abs(int(a[i])-int(a[i-1]))> abs(int(a[i])-int(a[i-2])):
        asiba[i]=asiba[i-2]+abs(int(a[i])-int(a[i-2]))

    else:
        asiba[i]=asiba[i-1]+abs(int(a[i])-int(a[i-1]))
    

print(asiba[N-1])



Failing test case input:
4
2 77 54 13

Expected output:
93


Actual output:
139


Fixed submission (verdict: Accepted):
N=int(input())
a=input().rstrip().split()
  
asiba=[100000]*N
asiba[0]=0
asiba[1]=abs(int(a[1])-int(a[0]))

for i in range(2,N):

    if (asiba[i-1]+abs(int(a[i])-int(a[i-1])))> (asiba[i-2]+abs(int(a[i])-int(a[i-2]))):
        asiba[i]=asiba[i-2]+abs(int(a[i])-int(a[i-2]))

    else:
        asiba[i]=asiba[i-1]+abs(int(a[i])-int(a[i-1]))
    

print(asiba[N-1])
Problem: p03160
Buggy submission (Python (3.4.3), verdict: Wrong Answer):


n=int(input())
arr=list(map(int,input().split()))
dp=[0]*len(arr)
dp[0]=0
for i in range(len(arr)):
    if(i==1):
        dp[i]=dp[i-1]+abs(arr[i]-arr[i-1])
    else:
        dp[i]=min(dp[i-1]+abs(arr[i]-arr[i-1]),dp[i-2]+abs(arr[i]-arr[i-2]))
print(dp[n-1])

Failing test case input:
6
30 0 26 33 122 14

Expected output:
30


Actual output:
46


Fixed submission (verdict: Accepted):


n=int(input())
arr=list(map(int,input().split()))
dp=[0]*len(arr)
for i in range(1,n):
	dp[i]=dp[i-1]+abs(arr[i]-arr[i-1])
	if(i>1):
		a=dp[i-2]+abs(arr[i]-arr[i-2])
		dp[i]=min(dp[i],a)
print(dp[n-1])

Problem: p03160
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
N = int(input())
C = list(map(int,input().split()))

dp = [-1 for _ in range(N)]

dp[0] = 0
dp[1] = abs(C[0] - C[1])

for i in range(0,N-2):
    dp[i+2] = min(dp[i] + abs(C[i+2]-C[i]) , dp[i+1] + abs(C[i+1] - C[i]))

print(dp[N-1]) 


Failing test case input:
4
2 91 71 13

Expected output:
127


Actual output:
89


Fixed submission (verdict: Accepted):
N = int(input())
C = list(map(int,input().split()))

dp = [-1 for _ in range(N)]

dp[0] = 0
dp[1] = abs(C[0] - C[1])

for i in range(0,N-2):
    dp[i+2] = min(dp[i] + abs(C[i+2]-C[i]) , dp[i+1] + abs(C[i+2] - C[i+1]))

print(dp[N-1])

Problem: p03160
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
N = int(input())
h = list(map(int, input().split()))
dp = [float('inf') for i in range(N)]

dp[0] = 0
dp[1] = abs(h[1] - h[0])

for i in range(2, N):
  dp[i] = min(dp[i-1] + abs(h[i] - h[i-1]), dp[i-2] + abs(h[i] - h[i-2]))

print(dp)
print(dp[N-1])


Failing test case input:
4
5 14 40 20

Expected output:
15


Actual output:
[0, 9, 35, 15]
15


Fixed submission (verdict: Accepted):
N = int(input())
h = list(map(int, input().split()))
dp = [float('inf') for i in range(N)]

dp[0] = 0
dp[1] = abs(h[1] - h[0])

for i in range(2, N):
  dp[i] = min(dp[i-1] + abs(h[i] - h[i-1]), dp[i-2] + abs(h[i] - h[i-2]))

print(dp[N-1])

Problem: p03160
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
N=int(input())
H=list(map(int,input().split()))
dplist=[0 for i in range(N)]
dplist[0]=0
dplist[1]=abs(H[1]-H[0])
for i in range(2,N):
  dplist[i]=min(dplist[i-1]+abs(H[i]-H[i-1]),dplist[i-2]+abs(H[i-2]-H[i]))
print(dplist)

Failing test case input:
4
0 -1 2 -258

Expected output:
258


Actual output:
[0, 1, 2, 258]


Fixed submission (verdict: Accepted):
N=int(input())
H=list(map(int,input().split()))
dplist=[0 for i in range(N)]
dplist[0]=0
dplist[1]=abs(H[1]-H[0])
for i in range(2,N):
  dplist[i]=min(dplist[i-1]+abs(H[i]-H[i-1]),dplist[i-2]+abs(H[i-2]-H[i]))
print(dplist[N-1])
Problem: p03160
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n = int(input())
h_list = list(map(int, input().split()))
dp1 = 0
dp2 = abs(h_list[1]-h_list[0])
dp3 = 0
for i in range(2, n):
    if abs(h_list[i]-h_list[i-1]) >= abs(h_list[i]-h_list[i-2]):
        dp3 = abs(h_list[i]-h_list[i-2]) + dp1
    else:
        dp3 = abs(h_list[i]-h_list[i-1]) + dp2
    dp1 = dp2
    dp2 = dp3
print(dp2)

Failing test case input:
6
3 0 1 45 52 26

Expected output:
65


Actual output:
67


Fixed submission (verdict: Accepted):
n = int(input())
h_list = list(map(int, input().split()))
if n == 1:
    print(h_list[0])
elif n == 2:
    print(abs(h_list[1]-h_list[0]))
else:
    dp1 = 0
    dp2 = abs(h_list[1]-h_list[0])
    dp3 = 0
    for i in range(2, n):
        if abs(h_list[i]-h_list[i-1]) + dp2 >= abs(h_list[i]-h_list[i-2]) + dp1:
            dp3 = abs(h_list[i]-h_list[i-2]) + dp1
        else:
            dp3 = abs(h_list[i]-h_list[i-1]) + dp2
        dp1 = dp2
        dp2 = dp3
    print(dp2)

Problem: p03160
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n = int(input())
h = list(map(int, input().split()))
dp = [0 for i in range(n)]

dp[0] = 0
dp[1] = abs(h[1] - h[0])
for i in range(2, n):
  dp[i] = min(dp[i-1] + abs(h[i] - h[i-1]), dp[i-2] + abs(h[i] - h[i-2]))
  print(dp[i])

print(dp[n-1])
  
  

Failing test case input:
6
30 10 60 10 60 50

Expected output:
40

Actual output:
30
20
30
40
40


Fixed submission (verdict: Accepted):
n = int(input())
h = list(map(int, input().split()))
dp = [0 for i in range(n)]

dp[1] = abs(h[1] - h[0])
for i in range(2, n):
  dp[i] = min(dp[i-1] + abs(h[i] - h[i-1]), dp[i-2] + abs(h[i] - h[i-2]))

print(dp[n-1])

Problem: p03160
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n=int(input())
l=list(map(int, input().split()))
inf=10**12
dp=[inf]*n
dp[0]=0
dp[1]=abs(l[0]-l[1])
for i in range(n-2):
	dp[i+2]=min(dp[i]+abs(l[i+2]-l[i]),dp[i+1]+abs(l[i+2]-l[i+1]))
print(dp)
print(dp[-1])

Failing test case input:
4
4 91 105 28

Expected output:
150


Actual output:
[0, 87, 101, 150]
150


Fixed submission (verdict: Accepted):
n=int(input())
l=list(map(int, input().split()))
inf=10**12
dp=[inf]*n
dp[0]=0
dp[1]=abs(l[0]-l[1])
for i in range(n-2):
	dp[i+2]=min(dp[i]+abs(l[i+2]-l[i]),dp[i+1]+abs(l[i+2]-l[i+1]))
print(dp[-1])

Problem: p03160
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n = int(input())
h = list(map(int, input().split()))
dp = [0]*n

for i in range(n):
  if i == 0:
    dp[i] = 0
  elif i == 1:
    dp[i] = h[i]
  else:
    dp[i] = min(abs(h[i]-dp[i-1]), abs(h[i]-dp[i-2]))
print(dp[n-1])


Failing test case input:
6
3 0 1 45 52 10

Expected output:
81


Actual output:
2


Fixed submission (verdict: Accepted):
n = int(input())
h = list(map(int, input().split()))
dp = [0]*n

for i in range(n):
  if i == 0:
    dp[i] = 0
  elif i == 1:
    dp[i] = abs(h[i]-h[i-1])
  else:
    dp[i] = min(dp[i-1]+abs(h[i]-h[i-1]), dp[i-2]+abs(h[i]-h[i-2]))
print(dp[n-1])
Problem: p03160
Buggy submission (PyPy3 (2.4.0), verdict: Wrong Answer):
N = int(input())
hs = [0] + [int(h) for h in input().split()]

dp = [0] * (N + 1)

for i in range(2, N + 1):
    cost_1 = dp[i - 1] + abs(hs[i] - hs[i - 1])
    cost_2 = dp[i - 2] + abs(hs[i] - hs[i - 2])
    dp[i] = min(cost_1, cost_2)

print(dp)


Failing test case input:
6
30 10 60 10 60 57

Expected output:
33


Actual output:
[0, 0, 10, 30, 10, 30, 33]


Fixed submission (verdict: Accepted):
N = int(input())
N_1 = N + 1
hs = [0] + [int(h) for h in input().split()]

dp = [0] * N_1
dp[2] = abs(hs[1] - hs[2])

for i in range(3, N_1):
    cost_1 = dp[i - 1] + abs(hs[i] - hs[i - 1])
    cost_2 = dp[i - 2] + abs(hs[i] - hs[i - 2])
    dp[i] = min(cost_1, cost_2)

print(dp[-1])

Problem: p03160
Buggy submission (PyPy3 (2.4.0), verdict: Wrong Answer):
N = int(input())
h = list(map(int, input().split()))

dp = [0] * N

dp[1] = abs(h[1] - h[0])

if N == 2:
    print(dp[1])

for i in range(2, N):
    dp[i] = min(dp[i-1] + abs(h[i] - h[i-1]), dp[i-2] + abs(h[i] - h[i-2]))

print(dp[N-1])


Failing test case input:
2
-3 55

Expected output:
58


Actual output:
58
58


Fixed submission (verdict: Accepted):
N = int(input())
h = list(map(int, input().split()))

dp = [10 ** 10] * N

dp[0] = 0
dp[1] = abs(h[1] - h[0])

for i in range(2, N):
    dp[i] = min(dp[i-1] + abs(h[i] - h[i-1]), dp[i-2] + abs(h[i] - h[i-2]))

print(dp[N-1])

Problem: p03160
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n=int(input())
a=list(map(int,input().split()))

dp=[-1]*n
dp[0]=0
dp[1]=abs(a[0]-a[1])

for i in range(2,n):
    dp[i]=min(
    dp[i-2]+abs(a[i]-a[i-2]),
    dp[i-2]+abs(a[i]-a[i-1])+abs(a[i-2]-a[i-1]),
    dp[i-1]+abs(a[i]-a[i-2]),
    dp[i-1]+abs(a[i]-a[i-1])+abs(a[i-2]-a[i-1]))
    
print(dp[-1])

Failing test case input:
6
3 0 1 45 52 26

Expected output:
65


Actual output:
66


Fixed submission (verdict: Accepted):
n=int(input())
a=list(map(int,input().split()))

dp=[-1]*n
dp[0]=0
dp[1]=abs(a[0]-a[1])

for i in range(2,n):
    dp[i]=min(
        dp[i-2]+abs(a[i]-a[i-2]),
        dp[i-1]+abs(a[i]-a[i-1])
    )
    
print(dp[-1])

Problem: p03160
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n = int(input())
h = list(map(int,input().split()))
dp = [int(1e+10) for _ in range(n)]
dp[0],dp[1] = 0,h[1]-h[0]
for i in range(2,n):
    dp[i] = min(dp[i-1] + abs(h[i] - h[i-1]),dp[i-2] + abs(h[i] - h[i-2]))
print(dp[-1])

Failing test case input:
4
0 -1 2 -52

Expected output:
52


Actual output:
50


Fixed submission (verdict: Accepted):
n = int(input())
h = list(map(int,input().split()))
dp = [int(1e+10) for _ in range(n)]
dp[0],dp[1] = 0,abs(h[1]-h[0])
for i in range(2,n):
    dp[i] = min(dp[i-1] + abs(h[i] - h[i-1]),dp[i-2] + abs(h[i] - h[i-2]))
print(dp[-1])
Problem: p03160
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
N=int(input())

h_list=list(map(int,input().split()))

pos = 0

cost = [0]

for i in range(1,N):
  back_1 = abs(h_list[i] - h_list[i-1])
  if i>1:
    back_2 = abs(h_list[i] - h_list[i-2])
  if i>1:
    cost.append( back_2 if back_1 > back_2 else back_1)
  else:
    cost.append( back_1)
  
print(cost[N-1])

Failing test case input:
4
2 77 45 13

Expected output:
75


Actual output:
32


Fixed submission (verdict: Accepted):
N=int(input())

h_list=list(map(int,input().split()))

pos = 0

cost = [0]

for i in range(1,N):
  back_1 = abs(h_list[i] - h_list[i-1])
  if i>1:
    back_2 = abs(h_list[i] - h_list[i-2])
  if i>1:
    cost.append( (back_2 + cost[i-2] )if (back_1 + cost[i-1]) > (back_2 + cost[i-2] ) else (back_1 + cost[i-1]))
  else:
    cost.append( back_1 + cost[i-1])
    
  
print(cost[N-1])

Problem: p03160
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
INF = 1000
N = int(input())
h = list(map(lambda x: int(x), input().split()))
h.insert(0, 0)


dp = [INF for _ in range(N + 1)]


dp[0] = 0
dp[1] = 0


for i in range(1, N):
    min_i = abs(h[i + 1] - h[i])
    min_i2 = abs(h[i + 1] - h[i - 1])
    dp[i + 1] = min(dp[i] + min_i, dp[i - 1] + min_i2)


print(dp[N])


Failing test case input:
2
-48 -1

Expected output:
47


Actual output:
1


Fixed submission (verdict: Accepted):
INF = 1000
N = int(input())
h = list(map(lambda x: int(x), input().split()))


dp = [INF for _ in range(N)]


dp[0] = 0
dp[1] = abs(h[0] - h[1])


for i in range(0, N - 2):
    dp[i + 2] = min(dp[i + 1] + abs(h[i + 2] - h[i + 1]), dp[i] + abs(h[i + 2] - h[i]))


print(dp[N - 1])

Problem: p03160
Buggy submission (Python (3.4.3), verdict: Wrong Answer):

import time
import re
import math

def main():
    n=int(input())
    H=list(map(int,input().split()))
    memo=[0]*n
    for a in range(n):
        if a==0:
            memo[a]=0
        elif a==1:
            memo[a]=memo[a-1]+abs(H[a-1]-H[a])
        else:
            memo[a]=min([memo[a-1]+abs(H[a-1]-H[a]),memo[a-2]+abs(H[a-2]-H[a])])
    print(memo)
    print(memo[-1])


start=time.time()
main()


Failing test case input:
6
30 12 60 17 60 9

Expected output:
31


Actual output:
[0, 18, 30, 23, 30, 31]
31


Fixed submission (verdict: Accepted):

import time
import re
import math

def main():
    n=int(input())
    H=list(map(int,input().split()))
    memo=[0]*n
    for a in range(n):
        if a==0:
            memo[a]=0
        elif a==1:
            memo[a]=memo[a-1]+abs(H[a-1]-H[a])
        else:
            memo[a]=min([memo[a-1]+abs(H[a-1]-H[a]),memo[a-2]+abs(H[a-2]-H[a])])
    print(memo[-1])


start=time.time()
main()
Problem: p03160
Buggy submission (Python (3.4.3), verdict: Wrong Answer):


N = int(input())
h = list(map(int, input().split()))

dp = [0]
INF = max(h) + 1
for i in range(1, N):
    if i == 1:
        cost1 = abs(h[i] - h[i - 1])
        dp.append(cost1)
    if i == 2:
        cost1 = abs(h[i] - h[i - 1])
        cost2 = abs(h[i] - h[i - 2])
        dp.append(min(
            dp[i - 1] + cost1,
            dp[i - 2] + cost2,
        ))

answer = dp.pop()

print(answer)


Failing test case input:
4
2 77 54 37

Expected output:
69


Actual output:
52


Fixed submission (verdict: Accepted):


N = int(input())
h = list(map(int, input().split()))

dp = [0]
for i in range(1, N):
    if i == 1:
        cost1 = abs(h[i] - h[i - 1])
        dp.append(cost1)
    if i >= 2:
        cost1 = abs(h[i] - h[i - 1])
        cost2 = abs(h[i] - h[i - 2])
        dp.append(min(
            dp[i - 1] + cost1,
            dp[i - 2] + cost2,
        ))


answer = dp.pop()

print(answer)

Problem: p03160
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n=int(input())
a=list(map(int,input().split()))

dp=[0 for i in range(n)]
dp[0]=a[0]
dp[1]=abs(a[0]-a[1])
for i in range(n-2):
    dp[i+2]=abs(dp[i]-dp[i+2])
    dp[i+1]=abs(min(dp[i+1],dp[i]+abs(a[i+1]-a[i])))
if(n>2):
    dp[-1]=min(dp[-2]+abs(a[-1]-a[-2]),dp[-3]+abs(a[-3]-a[-1]))
   
print(dp[-1])


Failing test case input:
4
8 289 2 28

Expected output:
32


Actual output:
34


Fixed submission (verdict: Accepted):
n=int(input())
a=list(map(int,input().split()))

dp=[0 for i in range(n)]
dp[0]=0
dp[1]=abs(a[0]-a[1])
for i in range(n-2):
    dp[i+2]=dp[i]+abs(a[i]-a[i+2])
    dp[i+1]=abs(min(dp[i+1],dp[i]+abs(a[i+1]-a[i])))
if(n>2):
    dp[-1]=min(dp[-2]+abs(a[-1]-a[-2]),dp[-3]+abs(a[-3]-a[-1]))
   
print(dp[-1])

Problem: p03160
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n = int(input())
h = list(map(int,input().split()))
dp = [0]*n
dp[0] = 0
dp[1] = h[1] - h[0]
for i in range(2,n):
    dp[i] = min((dp[i-2]+abs(h[i]-h[i-2])),dp[i-1]+abs(h[i]-h[i-1]))
print(dp[n-1])

Failing test case input:
6
30 0 26 33 60 18

Expected output:
26


Actual output:
18


Fixed submission (verdict: Accepted):
n = int(input())
h = list(map(int,input().split()))
dp = [0]*n
dp[0] = 0
dp[1] = abs(h[1] - h[0])
for i in range(2,n):
    dp[i] = min((dp[i-2]+abs(h[i]-h[i-2])),dp[i-1]+abs(h[i]-h[i-1]))
print(dp[n-1])

Problem: p03160
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n = int(input())
h = list(map(int,input().split()))

dp = [10**5]*n

def chmin(a,b,i):
    if a > b:
        dp[i] = b

dp[0] = 0
for i in range(1,n):
    chmin(dp[i],dp[i-1] + abs(h[i] - h[i-1]),i)
    chmin(dp[i],dp[i-1] + abs(h[i] - h[i-2]),i)

print(dp[n-1])

Failing test case input:
4
8 146 105 28

Expected output:
174


Actual output:
236


Fixed submission (verdict: Accepted):
n = int(input())
h = list(map(int,input().split()))

dp = [float("inf")]*(n+2)

dp[0] = 0

for i in range(n-1):
    dp[i+1] = min(dp[i+1], dp[i] + abs(h[i] - h[i+1]))
    if i < n-2:
        dp[i+2] = min(dp[i+2] , dp[i] + abs(h[i] - h[i+2]))

print(dp[n-1])
Problem: p03160
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n = int(input())
h = [int(i) for i in input().split()]

cost = [float("inf") for i in range(n)]
cost[:2] = 0, h[0]

for i in range(2, n):
    cost[i] = min(cost[i-1] + abs(h[i]-h[i-1]), cost[i-2] + abs(h[i]-h[i-2]))

print(cost[-1])

Failing test case input:
6
30 12 60 10 60 9

Expected output:
21


Actual output:
33


Fixed submission (verdict: Accepted):
n = int(input())
h = [int(i) for i in input().split()]


cost = [float("inf") for i in range(n)]
cost[:2] = 0, abs(h[0]-h[1])


for i in range(2, n):
    tmp1 = cost[i-1] + abs(h[i]-h[i-1])
    tmp2 = cost[i-2] + abs(h[i]-h[i-2])
    cost[i] = min(tmp1, tmp2)


print(cost[-1])

Problem: p03160
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
import sys

def chmin(a,i,b):
  if a[i] > b:
    a[i] = b
    
    return True
  else:
    return False

n = int(input())
h = list( map(int,input().split()))
dp = [sys.maxsize for i in range(n)]

dp[0] = 0
print(n,h)
print(dp)

for i in range(len(dp)):
  if i - 1 >= 0:
    chmin(dp,i, abs(h[i]-h[i-1]))

  if i - 2 >= 0:
    chmin(dp,i, abs(h[i]-h[i-2]))
    
print(dp)   
print(dp[-1])

Failing test case input:
4
8 146 162 28

Expected output:
256


Actual output:
4 [8, 146, 162, 28]
[0, 9223372036854775807, 9223372036854775807, 9223372036854775807]
[0, 138, 16, 118]
118


Fixed submission (verdict: Accepted):
import sys

def chmin(a,i,b):
  if a[i] > b:
    a[i] = b
    
    return True
  else:
    return False

n = int(input())
h = list( map(int,input().split()))
dp = [sys.maxsize for i in range(n)]

dp[0] = 0



for i in range(len(dp)):
  if i - 1 >= 0:
    chmin(dp,i, abs(h[i]-h[i-1])+dp[i-1])

  if i - 2 >= 0:
    chmin(dp,i, abs(h[i]-h[i-2])+dp[i-2])
    

print(dp[-1])

Problem: p03160
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
import sys
n = int(input())
h = list(map(int,input().split()))
inf = float("inf")
dp = [inf]*(n+1)
if n == 2:
    print(abs(h[1]-h[0]))
    sys.exit()

dp[1] = abs(h[1]-h[0])
dp[2] = min(abs(h[2]-h[1]), abs(h[2]-h[0]))

for i in range(3,n):
    dp[i] = min(abs(h[i]-h[i-1])+dp[i-1], abs(h[i]-h[i-2])+dp[i-2])
print(dp[n-1])    

Failing test case input:
4
2 91 71 13

Expected output:
127


Actual output:
78


Fixed submission (verdict: Accepted):
import sys
n = int(input())
h = list(map(int,input().split()))
inf = float("inf")
dp = [inf]*(n+1)
if n == 2:
    print(abs(h[1]-h[0]))
    sys.exit()

dp[1] = abs(h[1]-h[0])
dp[2] = min(abs(h[2]-h[1])+dp[1], abs(h[2]-h[0]))

for i in range(3,n):
    dp[i] = min(abs(h[i]-h[i-1])+dp[i-1], abs(h[i]-h[i-2])+dp[i-2])
print(dp[n-1])
Problem: p03160
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
N = int(input())
h = list(map(int,input().split()))

dp = [float('inf')]*N

dp[0] = 0
dp[1] = h[1]-h[0]

for i in range(2,N):
    dp[i] = min(dp[i-1]+abs(h[i]-h[i-1]),dp[i-2]+abs(h[i]-h[i-2]))

print(dp[N-1])

Failing test case input:
4
34 11 -4 -1

Expected output:
35


Actual output:
-11


Fixed submission (verdict: Accepted):
N = int(input())
h = list(map(int,input().split()))

dp = [float('inf')]*N

dp[0] = 0
dp[1] = abs(h[1]-h[0])

for i in range(2,N):
    dp[i] = min(dp[i-1]+abs(h[i]-h[i-1]),dp[i-2]+abs(h[i]-h[i-2]))

print(dp[N-1])

Problem: p03160
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
def Frog1():
    N = int(input())
    Hs = list(map(int,input().split()))
    dp = [0 for i in range(N)]
    dp[0] = 0
    dp[1] = abs(Hs[1]-Hs[0])
    for i in range(2,N):
        dp[i] = min(abs(Hs[i-1]-Hs[i])+dp[i-1],abs(Hs[i-2]-Hs[i])+dp[i-2])
Frog1()


Failing test case input:
2
62 1

Expected output:
61


Actual output:

Fixed submission (verdict: Accepted):
def Frog1():
    N = int(input())
    Hs = list(map(int,input().split()))
    dp = [0 for i in range(N)]
    dp[0] = 0
    dp[1] = abs(Hs[1]-Hs[0])
    for i in range(2,N):
        dp[i] = min(abs(Hs[i-1]-Hs[i])+dp[i-1],abs(Hs[i-2]-Hs[i])+dp[i-2])
    print(dp[N-1])
Frog1()

Problem: p03160
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
N=int(input())
h=list(map(int,input().split()))

c=[0]*N
c[1]=abs(h[1]-h[0])
for i in range(2,N):
  c[i]=min(c[i-2]+abs(h[i]-h[i-2]),c[i-1]+abs(h[i]-h[i-1]))
print(c)

Failing test case input:
4
9 77 54 37

Expected output:
62


Actual output:
[0, 68, 45, 62]


Fixed submission (verdict: Accepted):
N=int(input())
h=list(map(int,input().split()))

c=[0]*N
c[1]=abs(h[1]-h[0])
for i in range(2,N):
  c[i]=min(c[i-2]+abs(h[i]-h[i-2]),c[i-1]+abs(h[i]-h[i-1]))
print(c[-1])

Problem: p03160
Buggy submission (PyPy3 (2.4.0), verdict: Wrong Answer):
n=int(input())

h=list(map(int,input().split()))

inf=float('inf')
np=[inf]*n

np[0]=0

for i in range(n-1):
    if np[i+1]>abs(h[i]-h[i+1])+np[i] :
        np[i+1]=abs(h[i]-h[i+1])+np[i]
    if i < n-2:
        if np[i+2]>abs(h[i]-h[i+2])+np[i] :
            np[i+2]=abs(h[i]-h[i+2])+np[i]

print(int(np[n-1]))
print(np)


Failing test case input:
4
8 289 2 28

Expected output:
32


Actual output:
32
[0, 281, 6, 32]


Fixed submission (verdict: Accepted):
n=int(input())

h=list(map(int,input().split()))

inf=float('inf')
np=[inf]*n

np[0]=0

for i in range(n-1):
    if np[i+1]>abs(h[i]-h[i+1])+np[i] :
        np[i+1]=abs(h[i]-h[i+1])+np[i]
    if i < n-2:
        if np[i+2]>abs(h[i]-h[i+2])+np[i] :
            np[i+2]=abs(h[i]-h[i+2])+np[i]

print(int(np[n-1]))
Problem: p03160
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n = int(input())
h = list(map(int, input().split()))
dp = [0]*n

for i in range(n):
  if i == 0:
    dp[i] = h[i]
  elif i == 1:
    dp[i] = abs(dp[i] - dp[i-1])
  else:
    dp[i] = min(abs(dp[i]-dp[i-1]), abs(dp[i]-dp[i-2]))
print(dp[n-1])


Failing test case input:
6
0 0 1 45 52 10

Expected output:
80


Actual output:
0


Fixed submission (verdict: Accepted):
n = int(input())
h = list(map(int, input().split()))
dp = [0]*n

for i in range(n):
  if i == 0:
    dp[i] = 0
  elif i == 1:
    dp[i] = abs(h[i]-h[i-1])
  else:
    dp[i] = min(dp[i-1]+abs(h[i]-h[i-1]), dp[i-2]+abs(h[i]-h[i-2]))
print(dp[n-1])

Problem: p03160
Buggy submission (Python (3.8.2), verdict: Wrong Answer):




N = int(input())
h = list(map(int, input().split()))

dp = list()


dp.append(0)
dp.append(dp[0] + h[1] - h[0])

for i in range(2, N):
	dp.append(min(dp[i-2] + abs(h[i] - h[i-2]), dp[i-1] + abs(h[i] - h[i-1])))


print(dp)

Failing test case input:
4
2 91 105 13

Expected output:
167


Actual output:
[0, 89, 103, 167]


Fixed submission (verdict: Accepted):




N = int(input())
h = list(map(int, input().split()))

dp = list()


dp.append(0)
dp.append(dp[0] + abs(h[1] - h[0]))

for i in range(2, N):
	dp.append(min(dp[i-2] + abs(h[i] - h[i-2]), dp[i-1] + abs(h[i] - h[i-1])))


print(dp[N-1])

Problem: p03160
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n=int(input())
h=list(map(int,input().split()))
dp=[0]*n
dp[1]=abs(h[0]-h[1])
for i in range(n-2):
    dp[i+2]=min(dp[i+1]+abs(h[i+2]-h[i+1]),dp[i]+abs(h[i]-h[i+1]))
print(dp[n-1])

Failing test case input:
6
3 0 26 92 52 14

Expected output:
87


Actual output:
69


Fixed submission (verdict: Accepted):
n=int(input())
h=list(map(int,input().split()))
dp=[0]*n
dp[1]=abs(h[0]-h[1])
for i in range(n-2):
    dp[i+2]=min(dp[i+1]+abs(h[i+2]-h[i+1]),dp[i]+abs(h[i]-h[i+2]))
print(dp[n-1])

Problem: p03160
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
from sys import stdin

n = int(stdin.readline().rstrip())
li = list(map(int,stdin.readline().rstrip().split()))

def score(li,n):
    dp = [-1 for _ in li]
    dp[0] = li[0]
    dp[1] = abs(li[1]-li[0])
    if n == 1:
        return dp[0]
    elif n == 2:
        return dp[1]
    else:
        for i in range(2,n):
            dp[i] = min(dp[i-2]+abs(li[i]-li[i-2]),dp[i-1]+abs(li[i]-li[i-1]))
        return(dp[n-1])
    
print(score(li,n))

Failing test case input:
6
2 -2 0 4 65 18

Expected output:
20


Actual output:
22


Fixed submission (verdict: Accepted):
from sys import stdin

n = int(stdin.readline().rstrip())
li = list(map(int,stdin.readline().rstrip().split()))

def score(li,n):
    dp = [-1 for _ in li]
    dp[0] = 0
    dp[1] = abs(li[1]-li[0])
    if n == 1:
        return dp[0]
    elif n == 2:
        return dp[1]
    else:
        for i in range(2,n):
            dp[i] = min(dp[i-2]+abs(li[i]-li[i-2]),dp[i-1]+abs(li[i]-li[i-1]))
        return(dp[n-1])
    
print(score(li,n))
Problem: p03160
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
N = int(input())
H = [int(_) for _ in input().split()]
dp = [0, 0]
dp[0] = abs(H[1] - H[0])
if N == 2:
    print(dp[0])
else:
    dp[1] = abs(H[2] - H[0])
    for i in range(3, N):
        dp = [dp[1]] + [
            min(dp[0] + abs(H[i] - H[i - 2]), dp[1] + abs(H[i] - H[i - 1]))
        ]
    print(dp)


Failing test case input:
4
-2 0 2 -92

Expected output:
94


Actual output:
[4, 94]


Fixed submission (verdict: Accepted):
N = int(input())
H = [int(_) for _ in input().split()]
dp = [0, 0]
dp[0] = abs(H[1] - H[0])
if N == 2:
    print(dp[0])
else:
    dp[1] = abs(H[2] - H[0])
    for i in range(3, N):
        dp = [dp[1]] + [
            min(dp[0] + abs(H[i] - H[i - 2]), dp[1] + abs(H[i] - H[i - 1]))
        ]
    print(dp[-1])

Problem: p03160
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
import math

n = int(input())
list_ = list(map(int, input().split()))

cost_list = [math.inf for _ in range(n)]

cost_list[0]=0
cost_list[1]=list_[1]-list_[0]

for i in range(2,n):
  one = cost_list[i-1] + abs(list_[i]-list_[i-1])
  two = cost_list[i-2] + abs(list_[i]-list_[i-2])
  
  cost_list[i]=min(one,two,)
  
print(cost_list[-1])

Failing test case input:
4
29 7 0 2

Expected output:
27


Actual output:
-17


Fixed submission (verdict: Accepted):
import math

n = int(input())
list_ = list(map(int, input().split()))

cost_list = [math.inf for _ in range(n)]

cost_list[0]=0
cost_list[1]=abs(list_[1]-list_[0])

for i in range(2,n):
  one = cost_list[i-1] + abs(list_[i]-list_[i-1])
  two = cost_list[i-2] + abs(list_[i]-list_[i-2])
  
  cost_list[i]=min(one,two,)
  
print(cost_list[-1])

Problem: p03160
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n = int(input())
h = list(map(int, input().split()))
dp = [0] * n
dp[0] = 0
dp[1] = abs(h[0] - h[1])
for i in range(2, n - 1):
    dp[i] = min((dp[i - 2] + abs(h[i - 2] - h[i])), (dp[i - 1] + abs(h[i - 1] - h[i])))
print(dp[n - 1])

Failing test case input:
4
34 11 -4 -1

Expected output:
35


Actual output:
0


Fixed submission (verdict: Accepted):
n = int(input())
h = list(map(int, input().split()))
dp = [float('inf')] * n
dp[0] = 0
dp[1] = abs(h[0] - h[1])
for i in range(2, n):
    dp[i] = min((dp[i - 2] + abs(h[i - 2] - h[i])), (dp[i - 1] + abs(h[i - 1] - h[i])))
print(dp[-1])

Problem: p03160
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
N = int(input())

h = [int(i) for i in input().split()]

dp = [0] * N
dp[1] = abs(h[0] - h[1])

for x in range(2, N):
    if abs(h[x] - h[x - 1]) <= abs(h[x] - h[x - 2]):
        dp[x] = dp[x - 1] + abs(h[x] - h[x - 1])
    else:
        dp[x] = dp[x - 2] + abs(h[x] - h[x - 2])

print(dp[N - 1])

Failing test case input:
4
34 11 -4 -1

Expected output:
35


Actual output:
41


Fixed submission (verdict: Accepted):
N = int(input())

h = [int(i) for i in input().split()]

dp = [0] * N
dp[1] = abs(h[0] - h[1])

for x in range(2, N):
    if dp[x - 1] + abs(h[x] - h[x - 1]) < dp[x - 2] + abs(h[x] - h[x - 2]):
        dp[x] = dp[x - 1] + abs(h[x] - h[x - 1])
    else:
        dp[x] = dp[x - 2] + abs(h[x] - h[x - 2])

print(dp[N - 1])
Problem: p03160
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
def hoge():
  dp =[0] * (n + 1)
  dp[0] = 0
  dp[1] = abs(h_list[1] - h_list[0])
  for i in range(1, n):
    dp[i + 1] = min(dp[i - 2] + abs(h_list[i - 2] - h_list[i]), dp[i - 1] + abs(h_list[i - 1] - h_list[i]))
  return dp[n]

def solve():
  global n, h_list
  n = int(input())
  h_list = list(map(int, input().split()))
  ans = hoge()
  print(ans)
  return 0

if __name__ == "__main__":
  solve()

Failing test case input:
6
30 12 60 33 60 9

Expected output:
63


Actual output:
54


Fixed submission (verdict: Accepted):
def hoge():
  dp = [0] * (n + 5)
  dp[1] = abs(h_list[1] - h_list[0])
  for i in range(2, n):
    dp[i] = min(
      dp[i - 2] + abs(h_list[i] - h_list[i - 2]),
      dp[i - 1] + abs(h_list[i] - h_list[i - 1])
      )
  return dp[n - 1]

def solve():
  global n, h_list
  n = int(input())
  h_list = list(map(int, input().split()))
  ans = hoge()
  print(ans)
  return 0

if __name__ == "__main__":
  solve()

Problem: p03160
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n = int(input())
h = list(map(int, input().split()))
dp = [0]
dp.append(abs(h[1]-h[0]))
print(dp)
if n > 2:
    for i in range(2,n):
        dp.append(min(abs(h[i]-h[i-2])+dp[i-2],abs(h[i]-h[i-1])+dp[i-1]))
print(dp[-1])

Failing test case input:
6
2 0 26 33 122 14

Expected output:
50


Actual output:
[0, 2]
50


Fixed submission (verdict: Accepted):
n = int(input())
h = list(map(int, input().split()))
dp = [0]
dp.append(abs(h[1]-h[0]))
if n > 2:
    for i in range(2,n):
        dp.append(min(abs(h[i]-h[i-2])+dp[i-2],abs(h[i]-h[i-1])+dp[i-1]))
print(dp[-1])

Problem: p03160
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
N = int(input())
H = [0] + list(map(int, input().split()))
dp = [0] * (N + 1)
dp[0] = 0
dp[1] = 0
for i in range(2, N+1):
    dp[i] = min(dp[i - 1] + abs(H[i] - H[i - 1]), dp[i - 2] + abs(H[i] - H[i - 2]))
print(dp[N])

Failing test case input:
6
30 12 60 33 60 9

Expected output:
63


Actual output:
57


Fixed submission (verdict: Accepted):
N = int(input())
H = list(map(int, input().split()))
dp = [0] * N
dp[0] = 0
dp[1] = abs(H[1] - H[0])
for i in range(2, N):
    dp[i] = min(dp[i - 1] + abs(H[i] - H[i - 1]), dp[i - 2] + abs(H[i] - H[i - 2]))
print(dp[N - 1])

Problem: p03160
Buggy submission (PyPy3 (2.4.0), verdict: Wrong Answer):
N = int(input())
Hs = list(map(int, input().split()))

dp = [2 ** 32] * (N + 1)
dp[0] = 0

for i in range(N):
    for j in range(1, 3):
        if i + j < N:
            dp[i+j] = min(dp[i+j], dp[i] + abs(Hs[i+j]-Hs[i]))
print(dp[N])



Failing test case input:
2
62 1

Expected output:
61


Actual output:
4294967296


Fixed submission (verdict: Accepted):

N = int(input())
Hs = list(map(int, input().split()))

dp = [2 ** 32] * N
dp[0] = 0

for i in range(N):
    for j in range(1, 3):
        if i + j < N:
            dp[i+j] = min(dp[i+j], dp[i] + abs(Hs[i+j]-Hs[i]))
print(dp[N-1])
Problem: p03160
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n = int(input())
h = list(map(int, input().split()))

c = [10**4] * n
c[1] = 0

for i in range(n):
    if i == 0:
        continue

    h1 = c[i - 1] + abs(h[i] - h[i - 1])

    c[i] = h1 if h1 < c[i] else c[i]

    if not i < 2:
        h2 = c[i - 2] + abs(h[i] - h[i - 2])
        c[i] = h2 if h2 < c[i] else c[i]

print(c[-1])

Failing test case input:
6
30 10 99 10 60 50

Expected output:
60


Actual output:
40


Fixed submission (verdict: Accepted):
n = int(input())
h = list(map(int, input().split()))

c = [10 ** 5 + 1] * n
c[0] = 0
c[1] = abs(h[1] - h[0])

for i in range(2, n):
    h1 = c[i - 1] + abs(h[i] - h[i - 1])
    h2 = c[i - 2] + abs(h[i] - h[i - 2])
    c[i] = h1 if h1 < h2 else h2

print(c[-1])

Problem: p03160
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
import sys

n = int(sys.stdin.readline())
inp = list(map(lambda x: int(x), sys.stdin.readline().split(" ")))


dp = [0]*(n)
dp[1] = abs(inp[1]-inp[0])

for i in range(1,n-1):
    if (abs(inp[i+1]-inp[i-1]) < abs(inp[i+1]-inp[i])):
        dp[i+1] = abs(inp[i+1]-inp[i-1]) + dp[i-1]
    else:
        dp[i+1] = abs(inp[i+1]-inp[i]) + dp[i]

print(dp[-1])

Failing test case input:
6
30 12 21 33 60 18

Expected output:
36


Actual output:
54


Fixed submission (verdict: Accepted):
import sys

n = int(sys.stdin.readline())
inp = list(map(lambda x: int(x), sys.stdin.readline().split(" ")))


dp = [0]*(n)
dp[1] = abs(inp[1]-inp[0])

for i in range(1,n-1):
    dp[i+1] = min(abs(inp[i+1]-inp[i-1])+dp[i-1], abs(inp[i+1]-inp[i])+dp[i])

print(dp[-1])

Problem: p03160
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
N = int(input())
cost= input().split()
cost = [int(i) for i in cost]
ans_list =[abs(cost[0] - cost[1])]
count = 1
while len(ans_list) != N-1:
  one_step = abs(cost[count] - cost[count+1])
  two_step = abs(cost[count-1] - cost[count+1])
  if one_step < two_step:
    num = ans_list[count-1]+one_step
    ans_list.append(num)
  else:
    if count == 1:
      ans_list.append(two_step)
    else:
      num = ans_list[count-2]+two_step
      ans_list.append(num)
  count += 1
print(ans_list.pop())

  
  
  

Failing test case input:
6
3 0 1 45 52 26

Expected output:
65


Actual output:
67


Fixed submission (verdict: Accepted):
N = int(input())
cost= input().split()
cost = [int(i) for i in cost]
ans_list =[abs(cost[0] - cost[1])]
count = 1
while len(ans_list) != N-1:
  if count == 1:
    one_step = ans_list[count-1] + abs(cost[count] - cost[count+1])
    two_step = abs(cost[count-1] - cost[count+1])
    ans_list.append(min(one_step,two_step))
  else:
    one_step = ans_list[count-1] + abs(cost[count] - cost[count+1])
    two_step = ans_list[count-2] + abs(cost[count-1] - cost[count+1])
    ans_list.append(min(one_step,two_step))
  count += 1
print(ans_list.pop())
Problem: p03160
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n=int(input())
data=[int(x) for x in input().split()]
ans=[0]*n
ans[0]=0
ans[1]=abs(data[1]-data[0])
for q in range(2,n):
    temp2=abs(data[q]-data[q-2])
    temp1=abs(data[q]-data[q-1])
    if(temp2<temp1):
        ans[q]=temp2+ans[q-2]
    else:
        ans[q]=temp1+ans[q-1]
print(ans[-1])

Failing test case input:
4
4 146 105 28

Expected output:
178


Actual output:
260


Fixed submission (verdict: Accepted):
n=int(input())
data=[int(x) for x in input().split()]
ans=[0]*n
ans[0]=0
ans[1]=abs(data[1]-data[0])
for q in range(2,n):
    temp2=abs(data[q]-data[q-2])+ans[q-2]
    temp1=abs(data[q]-data[q-1])+ans[q-1]
    if(temp2<temp1):
        ans[q]=temp2
    else:
        ans[q]=temp1
print(ans[-1])

Problem: p03160
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n=int(input())
h=list(map(int,input().split()))
l=[]
l.append(abs(h[1]-h[0]))
if n>2:
  l.append(min(h[2]-h[0],l[-1]+abs(h[2]-h[1])))
if n>3:
  for i in range(3,n):
    l.append(min(l[-1]+abs(h[i]-h[i-1]),l[-2]+abs(h[i]-h[i-2])))
print(l[-1])

Failing test case input:
4
39 283 1 7

Expected output:
44


Actual output:
-32


Fixed submission (verdict: Accepted):
n=int(input())
h=list(map(int,input().split()))
l=[]
l.append(abs(h[1]-h[0]))
if n>2:
  l.append(min(abs(h[2]-h[0]),l[-1]+abs(h[2]-h[1])))
if n>3:
  for i in range(3,n):
    l.append(min(l[-1]+abs(h[i]-h[i-1]),l[-2]+abs(h[i]-h[i-2])))
print(l[-1])

Problem: p03160
Buggy submission (Python (3.8.2), verdict: Wrong Answer):




N = int(input())
h = list(map(int, input().split()))

dp = list()


dp.append(h[0])
dp.append(dp[0] + h[1] - h[0])

for i in range(2, N):
	dp.append(min(dp[i-2] + abs(h[i] - h[i-2]), dp[i-1] + abs(h[i] - h[i-1])))

print(dp[N-1])

Failing test case input:
4
29 7 0 1

Expected output:
28


Actual output:
13


Fixed submission (verdict: Accepted):




N = int(input())
h = list(map(int, input().split()))

dp = list()


dp.append(0)
dp.append(dp[0] + abs(h[1] - h[0]))

for i in range(2, N):
	dp.append(min(dp[i-2] + abs(h[i] - h[i-2]), dp[i-1] + abs(h[i] - h[i-1])))


print(dp[N-1])

Problem: p03160
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n = int(input())
h_list = list(map(int,input().split()))
cost_min_list = [0] * n
cost_min_list[0] = 0
cost_min_list[0] = h_list[0]
for i in range(2, n):
    cost_min_list[i] = min(cost_min_list[i - 1] + abs(h_list[i] - h_list[i - 1]),
                           cost_min_list[i - 2] + abs(h_list[i] - h_list[i - 2]))
print(cost_min_list[n-1])

Failing test case input:
4
1 0 0 -101

Expected output:
102


Actual output:
101


Fixed submission (verdict: Accepted):
n = int(input())
h_list = list(map(int,input().split()))
cost_min_list = [0] * n
cost_min_list[0] = 0
cost_min_list[1] = abs(h_list[1] - h_list[0])
for i in range(2, n):
    cost_min_list[i] = min(cost_min_list[i - 1] + abs(h_list[i] - h_list[i - 1]),
                           cost_min_list[i - 2] + abs(h_list[i] - h_list[i - 2]))
print(cost_min_list[n - 1])
Problem: p03160
Buggy submission (Python (3.8.2), verdict: Wrong Answer):




N = int(input())
h = list(map(int, input().split()))

dp = list()


dp.append(0)
dp.append(dp[0] + h[1] - h[0])

for i in range(2, N):
	dp.append(min(dp[i-2] + h[i] - h[i-2], dp[i-1] + h[i] - h[i-2]))

print(dp[N-1])

Failing test case input:
2
112 1

Expected output:
111


Actual output:
-111


Fixed submission (verdict: Accepted):




N = int(input())
h = list(map(int, input().split()))

dp = list()


dp.append(0)
dp.append(dp[0] + abs(h[1] - h[0]))

for i in range(2, N):
	dp.append(min(dp[i-2] + abs(h[i] - h[i-2]), dp[i-1] + abs(h[i] - h[i-1])))


print(dp[N-1])

Problem: p03160
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
INF =10001
N = int(input())
h = [int(i) for i in input().split()]
i = 2
dp = [INF for i in range(N)]
dp[0],dp[1] = 0,abs(h[1]-h[0])

while i<N:
    dp[i] = min(dp[i-1],abs(h[i] - h[i-1]))
    dp[i] = min(dp[i-2],abs(h[i] - h[i-2]))
    i+=1
    
print(sum(dp))

Failing test case input:
6
2 0 18 50 65 14

Expected output:
84


Actual output:
6


Fixed submission (verdict: Accepted):
INF =10001
N = int(input())
h = [int(i) for i in input().split()]
i = 2
dp = [INF for i in range(N)]
dp[0],dp[1] = 0,abs(h[1]-h[0])

while not i==N:
    dp[i] = min(dp[i-2]+abs(h[i] - h[i-2]),dp[i-1]+abs(h[i] - h[i-1]))
    i+=1
    
print(dp[N-1])

Problem: p03160
Buggy submission (Python (3.8.2), verdict: Wrong Answer):


def solution(h):
    n = len(h)
    if n == 1:
        return 0
    elif n == 2:
        return abs(h[1]-h[0])
    dp = [0]*(n)
    dp[1]  = abs(h[1]-h[0]) 
    for i in range(2,n):
        dp[i] = min( dp[i-1]+abs(h[i]-h[i-1]) , dp[i-2]+abs(h[i]-h[i-2]) )
    print(*dp)
    return dp[n-1]

N = int(input())
h = list(map(int,input().split()))
res = solution(h)
print(res,end="")


Failing test case input:
6
30 0 26 33 122 14

Expected output:
30


Actual output:
0 30 4 11 100 30
30

Fixed submission (verdict: Accepted):


def solution(h):
    n = len(h)
    INF = float('inf')
    dp = [INF]*n
    dp[0] = 0
    for i in range(n):
        for j in range(i+1,i+3):
            if j < n:
                dp[j] = min(dp[j] , dp[i]+abs(h[i]-h[j]) )
    
    return dp[n-1]

N = int(input())
h = list(map(int,input().split()))
res = solution(h)
print(res)

Problem: p03160
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
N=int(input())
h=list(map(int,input().split()))

dp=[0]*(N)

for i in range(1,N):
    if i==1:
        dp[i]=abs(h[i]-h[i-1])
    else:
        dp[i]=min(dp[i-1]+abs(h[i]-h[i-1]),dp[i-2]+abs(h[i]-h[i-2]))

print(dp)

Failing test case input:
6
30 12 60 33 60 9

Expected output:
63


Actual output:
[0, 18, 30, 39, 30, 63]


Fixed submission (verdict: Accepted):
N=int(input())
h=list(map(int,input().split()))

dp=[0]*(N)

for i in range(1,N):
    if i==1:
        dp[i]=abs(h[i]-h[i-1])
    else:
        dp[i]=min(dp[i-1]+abs(h[i]-h[i-1]),dp[i-2]+abs(h[i]-h[i-2]))

print(dp[N-1])