Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
n=int(input())
h=list(map(int,input().split()))
dp=[]
dp[0]=0
dp[1]=abs(h[1]-h[0])
for i in range(2,n):
  dp.append(min(dp[i-1]+abs(h[i]-h[i-1]),dp[i-2]+abs(h[i]-h[i-2])))
 print(dp[n-1])

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

Buggy python submission (verdict: Runtime Error):
n=int(input())
h=list(map(int,input().split()))
dp=[]
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])

Fixed submission:
n=int(input())
h=list(map(int,input().split()))
dp=[]
dp.append(0)
dp.append(abs(h[1]-h[0]))
for i in range(2,n):
  dp.append(min(dp[i-1]+abs(h[i]-h[i-1]),dp[i-2]+abs(h[i]-h[i-2])))
print(dp[n-1])
Buggy python submission (verdict: Time Limit Exceeded):
N, K = map(int, input().split())
h = list(map(int, input().split()))
dp=[0]*N
for i in range(1,N):
    dp[i] = min(dp[g] + abs(h[i] - h[g]) for g in range(max(i-K,0), i))
print(dp[N-1])

Fixed submission:
def main():
	N, K = map(int, input().split())
	h = list(map(int, input().split()))
	dp=[0]*N
	for i in range(1,N):
		dp[i] = min(dp[g] + abs(h[i] - h[g]) for g in range(max(i-K,0), i))
	print(dp[N-1])
main()

Buggy python submission (verdict: Time Limit Exceeded):
n,k=map(int,input().split())
h=list(map(int,input().split()))
dp=[0]*n
for i in range(1,n):
  dp[i]=min(dp[j]+abs(h[i]-h[j]) for j in range(max(i-k,0),i))
print(dp[n-1])

Fixed submission:
def main():
	N, K = map(int, input().split())
	h = list(map(int, input().split()))
	dp=[0]*N
	for i in range(1,N):
		dp[i] = min(dp[g] + abs(h[i] - h[g]) for g in range(max(i-K,0), i))
	print(dp[N-1])
main()

Buggy python submission (verdict: Time Limit Exceeded):
n,k=map(int,input().split())
h=list(map(int,input().split()))
dp=[]
dp.append(0)
for i in range(1,n):
  dp.append(min(dp[j]+abs(h[i]-h[j]) for j in range(max(i-k,0),i)))
print(dp[n-1])

Fixed submission:
def main():
	N, K = map(int, input().split())
	h = list(map(int, input().split()))
	dp=[0]*N
	for i in range(1,N):
		dp[i] = min(dp[g] + abs(h[i] - h[g]) for g in range(max(i-K,0), i))
	print(dp[N-1])
main()

Buggy python submission (verdict: Time Limit Exceeded):
n,k=map(int,input().split())
h=list(map(int,input().split()))
dp=[]
dp.append(0)
dp.append(abs(h[1]-h[0]))
for i in range(2,n):
  dp.append(min(dp[j]+abs(h[i]-h[j]) for j in range(max(i-k,0),i)))
print(dp[n-1])

Fixed submission:
def main():
	N, K = map(int, input().split())
	h = list(map(int, input().split()))
	dp=[0]*N
	for i in range(1,N):
		dp[i] = min(dp[g] + abs(h[i] - h[g]) for g in range(max(i-K,0), i))
	print(dp[N-1])
main()

Buggy python submission (verdict: Runtime Error):
n,k=map(int,input().split())
h=list(map(int,input().split()))
dp=[]
dp.append(0)
dp.append(abs(h[1]-h[0]))
for i in range(2,n):
  dp.append(min(dp[j]+abs(h[i]-h[j]) for j in range(i-k,i)))
print(dp[n-1])

Fixed submission:
def main():
	N, K = map(int, input().split())
	h = list(map(int, input().split()))
	dp=[0]*N
	for i in range(1,N):
		dp[i] = min(dp[g] + abs(h[i] - h[g]) for g in range(max(i-K,0), i))
	print(dp[N-1])
main()
Buggy python submission (verdict: Time Limit Exceeded):
def main():
    inf = float('inf')
    n,k=map(int,input().split())
    h = list(map(int,input().split()))
    dp=[0] + [inf] *(n-1)#初期化
    for i in range(1,n):
        for j in range(1,k+1):#iからj離れた場所から来る場合と比較
            if i >=j:
                dp[i] = min(dp[i],abs(h[i-j]-h[i])+dp[i-j])
            else:break
    print(dp[n-1])

if __name__ == '__main__':
    main()

Fixed submission:
def main():
    inf = float('inf')
    n,k=map(int,input().split())
    h = list(map(int,input().split()))
    dp=[0] + [inf] *(n-1)#初期化
    for i in range(1,n):
        for j in range(1,k+1):#iからj離れた場所から来る場合と比較
            if i >=j:
                dp[i] = min(dp[i],abs(h[i-j]-h[i])+dp[i-j])
            else:break
    print(dp[n-1])

if __name__ == '__main__':
    main()

Buggy python submission (verdict: Time Limit Exceeded):
inf = float('inf')
n,k=map(int,input().split())
h = list(map(int,input().split()))
dp=[0] + [inf] *(n-1)#初期化
for i in range(1,n):
    for j in range(1,k+1):#iからj離れた場所から来る場合と比較
        if i >=j:
            dp[i] = min(dp[i],abs(h[i-j]-h[i])+dp[i-j])
        else:break
print(dp[n-1])

Fixed submission:
def main():
    inf = float('inf')
    n,k=map(int,input().split())
    h = list(map(int,input().split()))
    dp=[0] + [inf] *(n-1)#初期化
    for i in range(1,n):
        for j in range(1,k+1):#iからj離れた場所から来る場合と比較
            if i >=j:
                dp[i] = min(dp[i],abs(h[i-j]-h[i])+dp[i-j])
            else:break
    print(dp[n-1])

if __name__ == '__main__':
    main()
Buggy python submission (verdict: Runtime Error):
N,W=map(int,input().split())
w,v=[],[]
for i in range(N):
    weight, value = map(int,input().split())
    w.append(weight)
    v.append(value)
dp = [[0 for _ in range(10*9)] for _ in range(N+1)]
for i in range(N):
    for sum_w in range(W+1):
        if sum_w -w[i] >=0:
            dp[i+1][sum_w] = max(dp[i+1][sum_w],dp[i][sum_w-w[i]] + v[i])
        dp[i+1][sum_w]=max(dp[i+1][sum_w],dp[i][sum_w])
print(dp[N][W])

Fixed submission:
n,w=map(int,input().split())
weight,value=[0]*110,[0]*110
dp = [[0 for _ in range(100100)] for _ in range(110)]
for i in range(n):
    weight[i],value[i] = map(int,input().split())
for i in range(n):
    sum_w =0
    while sum_w <= w:
        #i番目の品物を選ぶ
        if(sum_w - weight[i] >=0):
            dp[i+1][sum_w] =max(dp[i+1][sum_w], dp[i][sum_w - weight[i]]+ value[i])
        #選ばない場合
        dp[i + 1][sum_w] = max(dp[i + 1][sum_w], dp[i][sum_w])
        sum_w +=1
print(dp[n][w])

Buggy python submission (verdict: Runtime Error):
N,W=map(int,input().split())
w,v=[],[]
for i in range(N):
    weight, value = map(int,input().split())
    w.append(weight)
    v.append(value)
dp = [[0 for _ in range(10*5*100)] for _ in range(N+1)]
for i in range(N):
    for sum_w in range(W+1):
        if sum_w -w[i] >=0:
            dp[i+1][sum_w] = max(dp[i+1][sum_w],dp[i][sum_w-w[i]] + v[i])
        dp[i+1][sum_w]=max(dp[i+1][sum_w],dp[i][sum_w])
print(dp[N][W])

Fixed submission:
n,w=map(int,input().split())
weight,value=[0]*110,[0]*110
dp = [[0 for _ in range(100100)] for _ in range(110)]
for i in range(n):
    weight[i],value[i] = map(int,input().split())
for i in range(n):
    sum_w =0
    while sum_w <= w:
        #i番目の品物を選ぶ
        if(sum_w - weight[i] >=0):
            dp[i+1][sum_w] =max(dp[i+1][sum_w], dp[i][sum_w - weight[i]]+ value[i])
        #選ばない場合
        dp[i + 1][sum_w] = max(dp[i + 1][sum_w], dp[i][sum_w])
        sum_w +=1
print(dp[n][w])
Buggy python submission (verdict: Time Limit Exceeded):
k,s = map(int,input().split())
cnt = 0
for x in range(0,k+1):
    for y in range(0,k+1):
        for z in range(0,k+1):
            if x+y == s-z:
                cnt +=1
print(cnt)

Fixed submission:
k,s = map(int,input().split())
cnt = 0
for x in range(0,k+1):
    for y in range(0,k+1):
        if 0 >= x+y-s >= -k :
            cnt +=1
print(cnt)
Buggy python submission (verdict: Runtime Error):
N = int(input())
a = list(map(int,input().split()))
 
ans = []
for i in range(-100, 101):
    total = 0
    for ai in a:
        total += (ai - i)**2
    ans.append(total)
 
print(min(ans))

Fixed submission:
N = int(input())
sumof = 0

for i in range(1, N+1):
    sumof += i
print(sumof)
Buggy python submission (verdict: Runtime Error):
 = map(int, input().split())
a = list(map(int, input().split()))

ans = 9999

for i in range(-100, 101):
    sumof = 0
    for j in a:
        sumof += (i - j)*(i - j)
    ans = min(ans, sumof)
    
print(ans)


Fixed submission:
N = map(int, input().split())
a = list(map(int, input().split()))

ans = 9999999999

for i in range(-100, 101):
    sumof = 0
    for j in a:
        sumof += (i - j)*(i - j)
    ans = min(ans, sumof)
    
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
import math

H, W, A, B = map(int, input().split())

def comb(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

def solve():
    ans = 0
    an = H + B - A - 1
    ar = B
    bn = W + A - B - 2
    br = W - B - 1
    for i in range(W-B):
        a = comb(an, ar)
        b = comb(bn, br)
        ans += a * b
        an += 1; ar += 1
        bn -= 1; br -= 1
    return ans%(10**9+7)

print(solve())


Fixed submission:
MAX = 510000
MOD = 1000000007

fac = [0] * MAX
finv = [0] * MAX
inv = [0] * MAX

def comb_init():
    fac[0] = fac[1] = 1
    finv[0] = finv[1] = 1
    inv[1] = 1
    for i in range(2, MAX):
        fac[i] = fac[i - 1] * i % MOD
        inv[i] = MOD - inv[MOD % i] * (MOD // i) % MOD
        finv[i] = finv[i - 1] * inv[i] % MOD
        
def comb(n, r):
    if n < r:           return 0
    if n < 0 or r < 0:  return 0
    return fac[n] * (finv[r] * finv[n - r] % MOD) % MOD

def solve():
    ans = 0
    an = H + B - A - 1
    ar = B
    bn = W + A - B - 2
    br = W - B - 1
    for i in range(W-B):
        a = comb(an, ar)
        b = comb(bn, br)
        ans += (a * b) % MOD
        an += 1; ar += 1
        bn -= 1; br -= 1
    return ans % MOD

H, W, A, B = map(int, input().split())

comb_init()
print(solve())
Buggy python submission (verdict: Runtime Error):
def fragOptimalJump(h,n):
    dp=[0]*(n+1)
    dp[2]=abs(h[1]-h[2])
    for i in range(3,n+1):
        min=10000
        p=1
        j=1
        while j<i:
            d=dp[j]+abs(h[i]-h[j])
            if d<min:
                min=d
            p=p*2
            j=p
            
        dp[i]=min
    return dp[n]

N=int(input())
H=[0]*(N+1)
read = [int(n) for n in input().split()]
H=[0]+read
print(H)
H=[0,1,2,3,4]
print(fragOptimalJump(H,4))

Fixed submission:
def fragOptimalJump(h,n,k):
    dp=[0]*(n+1)
    dp[2]=abs(h[1]-h[2])
    for i in range(3,n+1):
        l=i-k
        if l<0:
            l=1
        min=10000000000
        for j in range(l,i):
            d=dp[j]+abs(h[i]-h[j])
            if d<min:
                min=d
            
        dp[i]=min
    return dp[n]



N,k=input().split()
N,k=int(N),int(k)
H=[0]*(N+1)
read = [int(n) for n in input().split()]
H=[0]+read
print(fragOptimalJump(H,N,k))
Buggy python submission (verdict: Runtime Error):
def MAXI(a):
    m=max(a)
    for i in range(3):
        if a[i]==m:
            id=i
    return m,id



tot=0
N=int(input())
i=0
while i<N:
    
    if i==0:
        x=[int(a) for a in input().split()]
        m,id=MAXI(x)
        tot+=m
        i=i+1
    else:
        x=[int(a) for a in input().split()]
        y=[int(a) for a in input().split()]
        i=i+2
        MAX=0
        for j in range(3):
            if j!=id:
                for k in range(3):
                    if k!=j:
                        s=x[j]+y[k]
                        if s>MAX:
                            MAX=s
                            id1=k
                        
        tot+=MAX
        id=id1
                            
        
print(tot)
    


Fixed submission:
def LIST():
    return list(map(int, input().split()))
N = int(input())
arr = [LIST() for _ in range(N)]
dp = [[arr[0][0],arr[0][1],arr[0][2]],[0,0,0]]
l=1
p=0
for i in range(1, N):
    for j in range(3):
        for k in range(3):
            if j == k: continue
            a1=dp[p][j]
            a2=arr[i][k]
            a3=a1+a2
            dp[l][k] = max(dp[l][k], dp[p][j] + arr[i][k])
    l=l^1
    p=p^1
            
print(max([dp[p][j] for j in range(3)]))
Buggy python submission (verdict: Runtime Error):
def A(w, v, n,V):
    mem=[0 for i in range(V+1)]
    if n == 0 or V == 0:
        return 0
 
    for i in range(n):
        for j in range(V,w[i]-1,-1):
            m=v[i]+ mem[j - w[i]]
          if m>mem[j]:
            mem[j]=m
    return mem[V]
n,V=input().split()
n,V=int(n),int(V)
 
w=[0]*n
v=[0]*n
for i in range(n):
  x,y=input().split()
  w[i],v[i]=int(x),int(y)
 
print(A(w,v,n,V))

Fixed submission:
def A(w, v, n,V):
    mem=[0 for i in range(V+1)]
    if n == 0 or V == 0:
        return 0
 
    for i in range(n):
        for j in range(V,w[i]-1,-1):
            m=v[i]+ mem[j - w[i]]
            if m>mem[j]:
                mem[j]=m
    return mem[V]
n,V=input().split()
n,V=int(n),int(V)
 
w=[0]*n
v=[0]*n
for i in range(n):
  x,y=input().split()
  w[i],v[i]=int(x),int(y)
 
print(A(w,v,n,V))

Buggy python submission (verdict: Time Limit Exceeded):
def A(w, v, n,V):
    mem=[0 for i in range(V+1)]
    if n == 0 or V == 0:
        return 0
 
    for i in range(n):
        for j in range(V,w[i]-1,-1):
            mem[j] = max(mem[j], v[i]+ mem[j - w[i]])
    return mem[V]
n,V=input().split()
n,V=int(n),int(V)
 
w=[0]*n
v=[0]*n
for i in range(n):
  x,y=input().split()
  w[i],v[i]=int(x),int(y)
 
print(A(w,v,n,V))

Fixed submission:
def A(w, v, n,V):
    mem=[0 for i in range(V+1)]
    if n == 0 or V == 0:
        return 0
 
    for i in range(n):
        for j in range(V,w[i]-1,-1):
            m=v[i]+ mem[j - w[i]]
            if m>mem[j]:
                mem[j]=m
    return mem[V]
n,V=input().split()
n,V=int(n),int(V)
 
w=[0]*n
v=[0]*n
for i in range(n):
  x,y=input().split()
  w[i],v[i]=int(x),int(y)
 
print(A(w,v,n,V))

Buggy python submission (verdict: Runtime Error):
def A(w, v, n,V):
    mem=[0 for i in range(V+1)]
    if n == 0 or V == 0:
        return 0

    for i in range(n):
        for j in range(V,W[i]-1,-1):
            mem[j] = max(mem[j], v[i]+ mem[j - w[i]])
    return mem[V]
n,V=input().split()
n,V=int(n),int(V)

w=[0]*n
v=[0]*n
for i in range(n):
  x,y=input().split()
  w[i],v[i]=int(x),int(y)

print(A(W,V,4,4))


Fixed submission:
def A(w, v, n,V):
    mem=[0 for i in range(V+1)]
    if n == 0 or V == 0:
        return 0
 
    for i in range(n):
        for j in range(V,w[i]-1,-1):
            m=v[i]+ mem[j - w[i]]
            if m>mem[j]:
                mem[j]=m
    return mem[V]
n,V=input().split()
n,V=int(n),int(V)
 
w=[0]*n
v=[0]*n
for i in range(n):
  x,y=input().split()
  w[i],v[i]=int(x),int(y)
 
print(A(w,v,n,V))
Buggy python submission (verdict: Time Limit Exceeded):
import sys

input=sys.stdin.readline
N,K=list(map(int,input().split()))
h=list(map(int,input().split()))+[0]*100000

dp=[sys.maxsize]*(N+K+10)
dp[1]=0

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

print(dp[N])

Fixed submission:
import sys
import numpy as np
# inputを高速化する。
input = sys.stdin.readline
n, k = map(int, input().split())
h = [int(i) for i in input().split()]
# dpの配列を作る。
dp = np.zeros(n, dtype=int)
# hの配列を作る。
h = np.array(h)
for i in range(1, n):
    # start は負になることはない。
    start = max(0, i-k)
    # 行列として足し算できるのでforを使う必要がない。
    dp[i] = min(dp[start: i] + np.abs(h[i] - h[start: i]))
print(dp[n-1])

Buggy python submission (verdict: Time Limit Exceeded):
import sys

N,K=list(map(int,input().split()))
h=list(map(int,input().split()))+[0]*100000

dp=[sys.maxsize]*(N+K+10)
dp[1]=0

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

print(dp[N])

Fixed submission:
import sys
import numpy as np
# inputを高速化する。
input = sys.stdin.readline
n, k = map(int, input().split())
h = [int(i) for i in input().split()]
# dpの配列を作る。
dp = np.zeros(n, dtype=int)
# hの配列を作る。
h = np.array(h)
for i in range(1, n):
    # start は負になることはない。
    start = max(0, i-k)
    # 行列として足し算できるのでforを使う必要がない。
    dp[i] = min(dp[start: i] + np.abs(h[i] - h[start: i]))
print(dp[n-1])

Buggy python submission (verdict: Time Limit Exceeded):
import sys

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

dp=[sys.maxsize]*100100
dp[1]=0

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

print(dp[N])

        
    


Fixed submission:
import sys
import numpy as np
# inputを高速化する。
input = sys.stdin.readline
n, k = map(int, input().split())
h = [int(i) for i in input().split()]
# dpの配列を作る。
dp = np.zeros(n, dtype=int)
# hの配列を作る。
h = np.array(h)
for i in range(1, n):
    # start は負になることはない。
    start = max(0, i-k)
    # 行列として足し算できるのでforを使う必要がない。
    dp[i] = min(dp[start: i] + np.abs(h[i] - h[start: i]))
print(dp[n-1])
Buggy python submission (verdict: Runtime Error):
N,K = map(int,input().split())
stones = list(map(int,input().split()))
dp =[0] *N

for i in range(1,N):
    dp[i] = min(abs(stones[i] - stones[j]) + dp[j] for j in range(max(0, i - K), i))

print(dp[-1])


Fixed submission:
n = int(input())
cost = list(map(int, input().split()))

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

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

print(dp[n-1])

Buggy python submission (verdict: Runtime Error):
N,K = map(int,input().split())
stones = list(map(int,input().split()))
dp =[0] *N

for i in range(1,N):
    dp[i] = min(abs(stones[i] - stones[j]) + dp[j] for j in range(max(0, i - K), i))

print(dp[-1])


Fixed submission:
n = int(input())
cost = list(map(int, input().split()))

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

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

print(dp[n-1])
Buggy python submission (verdict: Time Limit Exceeded):
n, k = [int(e) for e in input().split()]
h = [int(e) for e in input().split()]
cost = [0] * n
for i in range(1, n):
	cost[i] = min(abs(h[i] - h[j]) + cost[j] for j in range(max(0, i - k), i))
print(cost[n - 1])

Fixed submission:
N,K = map(int,input().split())
stones = list(map(int,input().split()))
dp =[0] *N

for i in range(1,N):
    dp[i] = min(abs(stones[i] - stones[j]) + dp[j] for j in range(max(0, i - K), i))

print(dp[-1])

Buggy python submission (verdict: Time Limit Exceeded):
N,K = map(int,input().split())
stones = list(map(int,input().split()))
dp =[0] *N

for i in range(1,N):
    dp[i] = min(abs(stones[i] - stones[j]) + dp[j] for j in range(max(0, i - K), i))

print(dp[-1])


Fixed submission:
N,K = map(int,input().split())
stones = list(map(int,input().split()))
dp =[0] *N

for i in range(1,N):
    dp[i] = min(abs(stones[i] - stones[j]) + dp[j] for j in range(max(0, i - K), i))

print(dp[-1])

Buggy python submission (verdict: Time Limit Exceeded):
N,K = map(int,input().split())
stones = list(map(int,input().split()))
dp =[0] *N

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

for i in range(2,N):
    dp[i] = min(abs(stones[i] - stones[j]) + dp[j] for j in range(max(0, i - K), i))

print(dp[-1])


Fixed submission:
N,K = map(int,input().split())
stones = list(map(int,input().split()))
dp =[0] *N

for i in range(1,N):
    dp[i] = min(abs(stones[i] - stones[j]) + dp[j] for j in range(max(0, i - K), i))

print(dp[-1])

Buggy python submission (verdict: Time Limit Exceeded):
N,K = map(int,input().split())
stones = list(map(int,input().split()))
dp =[0] *N

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

for i in range(2,N):
    dp[i] = min(abs(stones[i] - stones[j]) + dp[j] for j in range(max(0, i - K), i))

print(dp[-1])


Fixed submission:
N,K = map(int,input().split())
stones = list(map(int,input().split()))
dp =[0] *N

for i in range(1,N):
    dp[i] = min(abs(stones[i] - stones[j]) + dp[j] for j in range(max(0, i - K), i))

print(dp[-1])

Buggy python submission (verdict: Time Limit Exceeded):
N,K = map(int,input().split())
stones = list(map(int,input().split()))
dp =[1000000007] *N

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

for i in range(2,N):
    for j in range(max(0, i - K), i):
        dp[i] = min(abs(stones[i] - stones[j]) + dp[j], dp[i])

print(dp[-1])


Fixed submission:
N,K = map(int,input().split())
stones = list(map(int,input().split()))
dp =[0] *N

for i in range(1,N):
    dp[i] = min(abs(stones[i] - stones[j]) + dp[j] for j in range(max(0, i - K), i))

print(dp[-1])

Buggy python submission (verdict: Time Limit Exceeded):
N,K = map(int,input().split())
stones = list(map(int,input().split()))
dp =[1000000007] *N

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

for i in range(2,N):
    start = max(0, i - K)
    for j in range(start, i):
        dp[i] = min(abs(stones[i] - stones[j]) + dp[j],dp[i])

print(dp[-1])


Fixed submission:
N,K = map(int,input().split())
stones = list(map(int,input().split()))
dp =[0] *N

for i in range(1,N):
    dp[i] = min(abs(stones[i] - stones[j]) + dp[j] for j in range(max(0, i - K), i))

print(dp[-1])
Buggy python submission (verdict: Time Limit Exceeded):
n, k = [int(i) for i in input().split()]
h = [int(i) for i in input().split()]

d = [float('inf')] * n
d[0] = 0

for i in range(1, n):
  d[i] = min(d[j] + abs(h[i] - h[j]) for j in range(max(i - k, 0), i))

print(d[n - 1])


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

def frog(n, k, h):
    d = [float('inf')] * n
    d[0] = 0

    for i in range(1, n):
        d[i] = min(
            d[j] + abs(h[i] - h[j]) for j in range(max(i - k, 0), i)
        )
    return d[n - 1]


print(frog(n, k, h))

Buggy python submission (verdict: Time Limit Exceeded):
n, k = [int(i) for i in input().split()]
h = [int(i) for i in input().split()]


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

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

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

def frog(n, k, h):
    d = [float('inf')] * n
    d[0] = 0

    for i in range(1, n):
        d[i] = min(
            d[j] + abs(h[i] - h[j]) for j in range(max(i - k, 0), i)
        )
    return d[n - 1]


print(frog(n, k, h))

Buggy python submission (verdict: Time Limit Exceeded):
n, k = [int(i) for i in input().split()]
arr = [int(i) for i in input().split()]


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

for i in range(1, n):
    dp[i] = min(dp[j] + abs(arr[i] - arr[j]) for j in range(max(i - k, 0), i))
print(dp[n - 1])

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

def frog(n, k, h):
    d = [float('inf')] * n
    d[0] = 0

    for i in range(1, n):
        d[i] = min(
            d[j] + abs(h[i] - h[j]) for j in range(max(i - k, 0), i)
        )
    return d[n - 1]


print(frog(n, k, h))

Buggy python submission (verdict: Time Limit Exceeded):
n, k = map(int, input().split())
arr = [int(x) for x in input().split()]
dp = [float('inf')] * n
dp[0] = 0

for i in range(1, n):
    dp[i] = min(dp[j] + abs(arr[i] - arr[j]) for j in range(max(i - k, 0), i))
print(dp[n - 1])


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

def frog(n, k, h):
    d = [float('inf')] * n
    d[0] = 0

    for i in range(1, n):
        d[i] = min(
            d[j] + abs(h[i] - h[j]) for j in range(max(i - k, 0), i)
        )
    return d[n - 1]


print(frog(n, k, h))

Buggy python submission (verdict: Time Limit Exceeded):
n,k = map(int,input().split())
arr = [int(x) for x in input().split()]
dp = [100000007]*(n+1)
dp[0] = 0

for i in range(1,n):
    dp[i] = min(dp[j] + abs(arr[i] - arr[j]) for j in range(max(i-k,0),i))
print(dp[n-1])

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

def frog(n, k, h):
    d = [float('inf')] * n
    d[0] = 0

    for i in range(1, n):
        d[i] = min(
            d[j] + abs(h[i] - h[j]) for j in range(max(i - k, 0), i)
        )
    return d[n - 1]


print(frog(n, k, h))
Buggy python submission (verdict: Runtime Error):
def solve():
  N=int(input())
  a=list(map(int,input().split()))
  dp=[float('inf') for i in range(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(a[i]-a[i+j]))
        
  print(dp[N-1])
solve()
      

Fixed submission:
def solve():
  N=int(input())
  a=list(map(int,input().split()))
  dp=[float('inf') for i in range(N)]
  dp[0]=0
  for i in range(N):
  	for j in range(i+1,min(i+3,N)):
  		dp[j]=min(dp[j],dp[i]+abs(a[i]-a[j]))
  print(dp[N-1])
solve()
      
# your code goes here