Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
# -*- coding: utf-8 -*-
#ARC082C
import copy
import sys
import math

n = int(input())
tmp = input().split()
hoge = list(map(lambda a: int(a), tmp))

hoge.sort()
hoge.append(-1)
a=0
b=0
c=1
maxhoge=0
for i in range(0,n):
	if(hoge[i]!=hoge[i+1]):
		if(i!=n-1):
			if(hoge[i+1]-hoge[i]==1):
				a=b
				b=c
				c=1
			elif(hoge[i+1]-hoge[i]==2):
				a=c
				b=0
				c=1
			else:
				a,b=0
				c=1
	else:
		c+=1
#	print("i:{} | {} {} {}".format(i,a,b,c))

	maxhoge=max(maxhoge,a+b+c)



#print(hoge)
print(maxhoge)



Fixed submission:
# -*- coding: utf-8 -*-
#ARC082C
import copy
import sys
import math

n = int(input())
tmp = input().split()
hoge = list(map(lambda a: int(a), tmp))

hoge.sort()
hoge.append(-1)
a=0
b=0
c=1
maxhoge=0
for i in range(0,n):
	if(hoge[i]!=hoge[i+1]):
		if(i!=n-1):
			if(hoge[i+1]-hoge[i]==1):
				a=b
				b=c
				c=1
			elif(hoge[i+1]-hoge[i]==2):
				a=c
				b=0
				c=1
			else:
				a=0
				b=0
				c=1
	else:
		c+=1
#	print("i:{} | {} {} {}".format(i,a,b,c))

	maxhoge=max(maxhoge,a+b+c)



#print(hoge)
print(maxhoge)
Buggy python submission (verdict: Runtime Error):
# -*- coding: utf-8 -*-
#AGC014A
import sys
#import collections

#n= int(input())

tmp = input().split()
n,k = list(map(lambda a: int(a), tmp))

tmp = input().split()
a = list(map(lambda a: int(a), tmp))

def gcd(a, b):
    while b:
        a, b = b, a % b
    return a

maxa=a[0]
tmp=a[0]
for i in range(1,n):
	maxa=max(maxa,a[i])
	tmp=gcd(tmp, a[i])

if(k<=m)and(k%tmp ==0):
	print("POSSIBLE")
else:
	print("IMPOSSIBLE")

#print(maxa)
#print(tmp)




Fixed submission:
# -*- coding: utf-8 -*-
#AGC014A
import sys
#import collections

#n= int(input())

tmp = input().split()
n,k = list(map(lambda a: int(a), tmp))

tmp = input().split()
a = list(map(lambda a: int(a), tmp))

def gcd(a, b):
    while b:
        a, b = b, a % b
    return a

maxa=a[0]
tmp=a[0]
for i in range(1,n):
	maxa=max(maxa,a[i])
	tmp=gcd(tmp, a[i])

if(k<=maxa)and(k%tmp ==0):
	print("POSSIBLE")
else:
	print("IMPOSSIBLE")

#print(maxa)
#print(tmp)
Buggy python submission (verdict: Time Limit Exceeded):
# -*- coding: utf-8 -*-
#ARC076C
import sys
import math

#n=int(input())

tmp = input().split()
hoge = list(map(lambda a: int(a), tmp))

n=hoge[0]
m=hoge[1]

total=1
if(n==m):
	total+=1

if(abs(n-m)>1):
	print(0)
else:
	print(total*math.factorial(n)*math.factorial(m))

Fixed submission:
# -*- coding: utf-8 -*-
#ARC076C
import sys
import math

#n=int(input())

tmp = input().split()
hoge = list(map(lambda a: int(a), tmp))

n=hoge[0]
m=hoge[1]

#total=1
#if(n==m):
#	total+=1

t = math.factorial(min(n,m))
#print(t)
#print(t**2)
if(abs(n-m)>1):
	print(0)
elif(n==m):
	print((2*(t**2))%1000000007)
else:
	print(((t**2)*max(n,m))%1000000007)
Buggy python submission (verdict: Runtime Error):
# -*- coding: utf-8 -*-
import math

n = int(input())
#tmp = input().split()
#hoge = list(map(lambda a: int(a), tmp))

tmp= math.ceil(math.sqrt(n))

for i in range(0,tmp):
	if(n%(tmp-i)==0):
		break

#print(tmp-i)
ansn=n//(tmp-i)
#print(ansn)
ans=math.floor(math.log10(ansn-1)) + 1

print(ans)



Fixed submission:
# -*- coding: utf-8 -*-
import math

n = int(input())
#tmp = input().split()
#hoge = list(map(lambda a: int(a), tmp))

tmp= math.ceil(math.sqrt(n))
#print(n)
#print(tmp)
for i in range(0,tmp):
	if(n%(tmp-i)==0):
		break

#print(tmp-i)
ansn=n//(tmp-i)
#print(ansn)
#print(math.log10(ansn))
#print(max(ansn,tmp-i))
#print(math.floor(0.9))
ans=math.floor(math.log10(max(ansn,tmp-i))) + 1

print(ans)

Buggy python submission (verdict: Runtime Error):
# -*- coding: utf-8 -*-
import math

n = int(input())
#tmp = input().split()
#hoge = list(map(lambda a: int(a), tmp))

tmp= math.ceil(math.sqrt(n))

for i in range(0,tmp):
	if(n%(tmp-i)==0):
		break

#print(tmp-i)
ansn=n//(tmp-i)
#print(ansn)
ans=math.floor(math.log10(ansn-1)) + 1

print(ans)



Fixed submission:
# -*- coding: utf-8 -*-
import math

n = int(input())
#tmp = input().split()
#hoge = list(map(lambda a: int(a), tmp))

tmp= math.ceil(math.sqrt(n))
#print(n)
#print(tmp)
for i in range(0,tmp):
	if(n%(tmp-i)==0):
		break

#print(tmp-i)
ansn=n//(tmp-i)
#print(ansn)
#print(math.log10(ansn))
#print(max(ansn,tmp-i))
#print(math.floor(0.9))
ans=math.floor(math.log10(max(ansn,tmp-i))) + 1

print(ans)

Buggy python submission (verdict: Runtime Error):
# -*- coding: utf-8 -*-
import math

n = int(input())
#tmp = input().split()
#hoge = list(map(lambda a: int(a), tmp))


tmp= math.ceil(math.sqrt(n))

for i in range(0,n):
	if(n%(tmp+i)==0):
		break

#print(tmp+i)
print(math.floor(math.log10(tmp+i-1) + 1))



Fixed submission:
# -*- coding: utf-8 -*-
import math

n = int(input())
#tmp = input().split()
#hoge = list(map(lambda a: int(a), tmp))

tmp= math.ceil(math.sqrt(n))
#print(n)
#print(tmp)
for i in range(0,tmp):
	if(n%(tmp-i)==0):
		break

#print(tmp-i)
ansn=n//(tmp-i)
#print(ansn)
#print(math.log10(ansn))
#print(max(ansn,tmp-i))
#print(math.floor(0.9))
ans=math.floor(math.log10(max(ansn,tmp-i))) + 1

print(ans)
Buggy python submission (verdict: Runtime Error):
N = int(input())
A = list(map(int,input().split()))

A.sort()
ans=0

if A[0]!=A[1]:
    ans=1

for i in range(1,N):
    if A[i]==A[i-1]:            
        continue
    for j in range(i):
        if A[i]%A[j]==0:
            break
        if j==i-1:
            ans+=1

print(ans)

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

i=0

while True:
    if X-i in A and X+i in A:
        i+=1
    elif X-i in A:
        print(X+i)
        exit()
    else:
        print(X-i)
        exit()
Buggy python submission (verdict: Runtime Error):
import numpy as np

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

ans = np.prod(P)

if ans>10**18:
    print(-1)
    exit()

print(ans)

Fixed submission:
import numpy as np

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

if 0 in P:
    print(0)
    exit()

ans=1
P.sort(reverse=True)

for i in range(N):
    ans*=P[i]
    if ans>10**18:
        print(-1)
        exit()

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A=list(map(int,input().split()))
 
ans=1
 
for i in range(N):
    ans*=A[i]
 
if ans > 10**18:
    print(-1)
    exit()
 
print(ans)

Fixed submission:
import numpy as np

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

if 0 in P:
    print(0)
    exit()

ans=1
P.sort(reverse=True)

for i in range(N):
    ans*=P[i]
    if ans>10**18:
        print(-1)
        exit()

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A=list(map(int,input().split()))

ans=1

for i in range(N):
    ans*=A[i]

if ans > 10**18:
    print(-1)
    exit()

print(ans)

Fixed submission:
import numpy as np

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

if 0 in P:
    print(0)
    exit()

ans=1
P.sort(reverse=True)

for i in range(N):
    ans*=P[i]
    if ans>10**18:
        print(-1)
        exit()

print(ans)
Buggy python submission (verdict: Time Limit Exceeded):

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

P=[1]
now=1

for i in range(K):
    now=A[now-1]
    if now in P:
        x = i+1
        y = P.index(now)
        break
    elif i == K-1:
        print(now)
        exit()
    else:
        P.append(now)

c=(K-y)%(x-y)

print(P[y+c])

Fixed submission:

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

P=[1]
S=[0]*N
S[0]=1
now=1

for i in range(K):
    now=A[now-1]
    if S[now-1]==1:
        x = i+1
        y = P.index(now)
        break
    elif i == K-1:
        print(now)
        exit()
    else:
        P.append(now)
        S[now-1]=1

c=(K-y)%(x-y)

print(P[y+c])

Buggy python submission (verdict: Time Limit Exceeded):

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

P=[1]
now=1

for i in range(K):
    now=A[now-1]
    if now in P:
        x = i+1
        y = P.index(now)
        break
    elif i == K-1:
        print(now)
        exit()
    else:
        P.append(now)

c=(K-y)%(x-y)

Q=P[y:]

print(Q[c])

Fixed submission:

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

P=[1]
S=[0]*N
S[0]=1
now=1

for i in range(K):
    now=A[now-1]
    if S[now-1]==1:
        x = i+1
        y = P.index(now)
        break
    elif i == K-1:
        print(now)
        exit()
    else:
        P.append(now)
        S[now-1]=1

c=(K-y)%(x-y)

print(P[y+c])

Buggy python submission (verdict: Time Limit Exceeded):

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

P=[1]
now=1

for i in range(K):
    now=A[now-1]
    if now in P:
        x = i+1
        y = P.index(now)
        break
    elif i == K-1:
        print(now)
        exit()

c=(K-y)%(x-y)

for i in range(c):
    now=A[now-1]

print(now)

Fixed submission:

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

P=[1]
S=[0]*N
S[0]=1
now=1

for i in range(K):
    now=A[now-1]
    if S[now-1]==1:
        x = i+1
        y = P.index(now)
        break
    elif i == K-1:
        print(now)
        exit()
    else:
        P.append(now)
        S[now-1]=1

c=(K-y)%(x-y)

print(P[y+c])

Buggy python submission (verdict: Runtime Error):
N,K = map(int,input().split())
A=list(map(int,input().split()))

P=[1]
now=1

for i in range(K):
    now=A[now-1]
    if now in P:
        x = i+1
        y = P.index(now)
        break
    else:
        P.append(now)

c=(K-y)%(x-y)

for i in range(c):
    now=A[now-1]

print(now)

Fixed submission:

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

P=[1]
S=[0]*N
S[0]=1
now=1

for i in range(K):
    now=A[now-1]
    if S[now-1]==1:
        x = i+1
        y = P.index(now)
        break
    elif i == K-1:
        print(now)
        exit()
    else:
        P.append(now)
        S[now-1]=1

c=(K-y)%(x-y)

print(P[y+c])
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A=[]

for i in range(N):
    S=input()
    if S in A:
        continue
    else:
        A.append(S)

print(len(A))

Fixed submission:
N = int(input())
A=[]
 
for i in range(N):
    S=input()
    A.append(S)
 
print(len(list(set(A))))

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
ans = 0
A=[]

for i in range(N):
    S=input()
    if S in A:
        continue
    else:
        A.append(S)
        ans+=1

print(ans)

Fixed submission:
N = int(input())
A=[]
 
for i in range(N):
    S=input()
    A.append(S)
 
print(len(list(set(A))))

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
ans = 0
A=[]

for i in range(N):
    S=input()
    if S in A:
        continue
    else:
        A.append(S)
        ans+=1

print(ans)

Fixed submission:
N = int(input())
A=[]
 
for i in range(N):
    S=input()
    A.append(S)
 
print(len(list(set(A))))
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A = list(map(int,input().split()))

x = A[0]
y = sum(A[1:])

ans = abs(x-y)

for i in range(1,N-1):
  x=sum(A[:i])
  y=sum(A[i:])
  if abs(x-y) < ans:
    ans = abs(x-y)

print(ans)

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

x = A[0]
y = sum(A[1:])

c=x-y
ans=abs(c)

for i in range(1,N-1):
  c+=2*A[i]
  if abs(c)< abs(ans):
    ans = abs(c)

print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
import sys
max_int = 1000000001  # 10^9+1
min_int = -max_int

n = int(input())
a = map(int, sys.stdin.readline().split())

prod = 1
for one in a:
    if not one:
        print(0)
        break
    prod *= one
else:
    if prod > 10**18:
        print(-1)
    else:
        print(prod)




Fixed submission:
import sys
n = int(input())
a = list(map(int, sys.stdin.readline().split()))

a.sort(reverse=True)

if a[-1] == 0:
    print(0)
else:
    limit = 10**18
    prod = 1
    for one in a:
        prod *= one
        if prod > limit:
            print(-1)
            break
    else:
        print(prod)

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = list(map(int, input().split()))
ans = 1
for i in a:
    ans *= i
if ans > 10**18:print(-1)
else:print(ans)

Fixed submission:
n = int(input())
a = list(map(int, input().split()))
ans = 1
big = 10**18
zero = 0 in a
for i in a:
    ans *= i
    if ans > 10**18:break
if zero:ans = 0
if ans > 10**18:print(-1)
else:print(ans)
Buggy python submission (verdict: Runtime Error):
n,k = map(int, input().split())
a = list(map(int, input().split()))
visit = [-1 for i in range(n)]
root = []
now = 1
length = 0
root.append(now)
if k > n:
    for i in range(n):
        if visit[now - 1] != 1:
            visit[now - 1] = 1
            now = a[now - 1]
            root.append(now)
            length += 1
        else:break
    start = 0
    for i in range(n):
        if root[i] == now:
            start = i
            break
    length -= start + 1
    k -= start
    k %= length
    ans = root[start]
    for i in range(k):
        ans = root[start + i]
    print(ans)
else:
    for i in range(k):
        now = a[now - 1]
    print(now)

Fixed submission:
n,k = map(int, input().split())
a = list(map(int, input().split()))
visit = [-1 for i in range(n)]
root = []
now = 1
length = 0
root.append(now)
if k > n:
    for i in range(n):
        if visit[now - 1] != 1:
            visit[now - 1] = 1
            now = a[now - 1]
            root.append(now)
            length += 1
        else:break
    start = 0
    for i in range(n):
        if root[i] == now:
            start = i
            break
    length -= start
    k -= start
    k %= length
    ans = root[start + k]
    print(ans)
else:
    for i in range(k):
        now = a[now - 1]
    print(now)

Buggy python submission (verdict: Runtime Error):
n,k = map(int, input().split())
a = list(map(int, input().split()))
visit = [-1 for i in range(n)]
root = []
now = 1
length = 0
root.append(now)
if k > 10**6:
    for i in range(n):
        if visit[now - 1] != 1:
            visit[now - 1] = 1
            now = a[now - 1]
            root.append(now)
            length += 1
        else:break
    start = 0
    for i in range(n):
        if root[i] == now:
            start = i
            break
    k -= start
    k %= length
    ans = root[start]
    for i in range(k):
        ans = root[start + i]
    print(ans)
else:
    for i in range(k):
        now = a[now - 1]
    print(now)


Fixed submission:
n,k = map(int, input().split())
a = list(map(int, input().split()))
visit = [-1 for i in range(n)]
root = []
now = 1
length = 0
root.append(now)
if k > n:
    for i in range(n):
        if visit[now - 1] != 1:
            visit[now - 1] = 1
            now = a[now - 1]
            root.append(now)
            length += 1
        else:break
    start = 0
    for i in range(n):
        if root[i] == now:
            start = i
            break
    length -= start
    k -= start
    k %= length
    ans = root[start + k]
    print(ans)
else:
    for i in range(k):
        now = a[now - 1]
    print(now)
Buggy python submission (verdict: Time Limit Exceeded):
def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)

    divisors.sort()
    return divisors

x = int(input())
a = 0
b = 0
flag = False
for i in range(10**7):
    tmp = ((x + i**5)**(1/5)).real
    if tmp.is_integer():
        b = i
        a = x + b**5
        flag = True
        break
if flag == False:
    for i in range(-10**7,0):
        tmp = ((x + i**5)**(1/5)).real
        if tmp.is_integer():
            b = i
            a = x + b**5
            flag = True
            break
print(int(a),int(b))


Fixed submission:
x = int(input())
a = []
b = []
ansa = 0
ansb = 0
for i in range(10**3):
    a.append(i**5)
    b.append(i**5)
for i in a:
    for j in b:
        if i - j == x:
            ansa = i**(1/5)
            ansb = j**(1/5)
        elif i + j == x:
            ansa = i**(1/5)
            ansb = -(j**(1/5))
        elif -i + j == x:
            ansa = -(i**(1/5))
            ansb = -(j**(1/5))
        elif -i -j == x:
            ansa = -(i**(1/5))
            ansb = j**(1/5)
print(int(ansa), int(ansb))
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = list(map(int, input().split()))
ans = 0
MOD = 10**9 + 7
for i in range(60):
    tmp0 = 0
    tmp1 = 0
    for j in range(n):
        if a[j]>>i&1 == 0: tmp0 += 1
        else: tmp1 += 1
    ans += (tmp0*tmp1%MOD)*(2**i%MOD)
print(ans%MOD)

Fixed submission:
n = int(input())
a = list(map(int, input().split()))
ans = 0
MOD = 10**9 + 7
for i in range(60):
    tmp0 = 0
    tmp1 = 0
    for j in range(n):
        if a[j]>>i&1 == 0: tmp0 += 1
        else: tmp1 += 1
    ans += (tmp0*tmp1%MOD)*(2**i%MOD)
print(ans%MOD)

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = list(map(int, input().split()))
ans = 0
MOD = 10**9 + 7
for i in range(60):
    tmp0 = 0
    tmp1 = 0
    for j in range(n):
        if a[j]>>i&1 == 0: tmp0 += 1
        else: tmp1 += 1
    ans += tmp0*tmp1*2**i%MOD
print(ans%MOD)

Fixed submission:
n = int(input())
a = list(map(int, input().split()))
ans = 0
MOD = 10**9 + 7
for i in range(60):
    tmp0 = 0
    tmp1 = 0
    for j in range(n):
        if a[j]>>i&1 == 0: tmp0 += 1
        else: tmp1 += 1
    ans += (tmp0*tmp1%MOD)*(2**i%MOD)
print(ans%MOD)

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = list(map(int, input().split()))
ans = 0
MOD = 10**9 + 7
for i in range(n - 1):
    for j in range(i,n):
        ans += a[i]^a[j]
        ans %= MOD
print(ans%MOD)

Fixed submission:
n = int(input())
a = list(map(int, input().split()))
ans = 0
MOD = 10**9 + 7
for i in range(60):
    tmp0 = 0
    tmp1 = 0
    for j in range(n):
        if a[j]>>i&1 == 0: tmp0 += 1
        else: tmp1 += 1
    ans += (tmp0*tmp1%MOD)*(2**i%MOD)
print(ans%MOD)

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = list(map(int, input().split()))
ans = 0
MOD = 10**9 + 7
for i in range(n - 1):
    for j in range(i,n):
        ans += a[i]^a[j]

print(ans%MOD)

Fixed submission:
n = int(input())
a = list(map(int, input().split()))
ans = 0
MOD = 10**9 + 7
for i in range(60):
    tmp0 = 0
    tmp1 = 0
    for j in range(n):
        if a[j]>>i&1 == 0: tmp0 += 1
        else: tmp1 += 1
    ans += (tmp0*tmp1%MOD)*(2**i%MOD)
print(ans%MOD)
Buggy python submission (verdict: Time Limit Exceeded):
S = input()
digits = list(map(int, S))
divisor = 2019

rem_count = [0] * divisor
rem_count[0] = 1
num = 0
pow10 = 1
total = 0

for digit in reversed(digits):
    num = digit * pow10 + num
    total += rem_count[num % divisor]
    pow10 *= 10
    rem_count[num % divisor] += 1

print(total)


Fixed submission:
S = input()
digits = list(map(int, S))
divisor = 2019

rem_count = [0] * divisor
rem_count[0] = 1
num = 0
pow10 = 1
total = 0

for digit in reversed(digits):
    num = digit * pow10 + num
    num %= divisor
    total += rem_count[num % divisor]
    pow10 *= 10
    pow10 %= divisor
    rem_count[num % divisor] += 1

print(total)

Buggy python submission (verdict: Time Limit Exceeded):
s = input()
n = len(s)

digits = [ord(c) - ord('0') for c in s]

total = 0
for i in range(n):
    if digits[i] == 0:
        continue

    num = 0
    for j in range(i, n):
        num = num * 10 + digits[j]
        if j + 4 < i:
            continue

        if num % 2019 == 0:
            total += 1

print(total)

Fixed submission:
S = input()
digits = list(map(int, S))
divisor = 2019

rem_count = [0] * divisor
rem_count[0] = 1
num = 0
pow10 = 1
total = 0

for digit in reversed(digits):
    num = digit * pow10 + num
    num %= divisor
    total += rem_count[num % divisor]
    pow10 *= 10
    pow10 %= divisor
    rem_count[num % divisor] += 1

print(total)

Buggy python submission (verdict: Time Limit Exceeded):
s = input()
n = len(s)

digits = [ord(c) - ord('0') for c in s]

total = 0
for i in range(n):
    if digits[i] == 0:
        continue

    num = 0
    for j in range(i, n):
        num = num * 10 + digits[j]
        if j + 4 < i:
            continue

        if num % 2019 == 0:
            total += 1

print(total)

Fixed submission:
S = input()
digits = list(map(int, S))
divisor = 2019

rem_count = [0] * divisor
rem_count[0] = 1
num = 0
pow10 = 1
total = 0

for digit in reversed(digits):
    num = digit * pow10 + num
    num %= divisor
    total += rem_count[num % divisor]
    pow10 *= 10
    pow10 %= divisor
    rem_count[num % divisor] += 1

print(total)
Buggy python submission (verdict: Time Limit Exceeded):
# key not available ""
import sys
n, k = [int(i) for i in input().split()]
arr = [int(i) for i in input().split()]
dp = [sys.maxsize]*n
dp[0] = 0
for i in range(n):
    for j in range(i+1, i+k+1):
        if j < n:
            dp[j] = min(dp[j], dp[i]+abs(arr[i]-arr[j]))
print(dp[-1])


Fixed submission:
# key not available ""
import sys
n, k = [int(i) for i in input().split()]
arr = [int(i) for i in input().split()]
dp = [sys.maxsize]*n
dp[0] = 0
for i in range(n):
    for j in range(i+1, i+k+1):
        if j < n:
            dp[j] = min(dp[j], dp[i]+abs(arr[i]-arr[j]))
print(dp[-1])

Buggy python submission (verdict: Time Limit Exceeded):
# key not available ""
import math
n, k = [int(i) for i in input().split()]
arr = [int(i) for i in input().split()]
dp = [0]*n
dp[0] = 0
for i in range(1, n):
    for j in range(i-1, max(-1, i-k-1), -1):
        if j == i-1:
            dp[i] = dp[j]+abs(arr[i]-arr[j])
        else:
            dp[i] = min(dp[i], dp[j]+abs(arr[i]-arr[j]))

print(dp[-1])


Fixed submission:
# key not available ""
import sys
n, k = [int(i) for i in input().split()]
arr = [int(i) for i in input().split()]
dp = [sys.maxsize]*n
dp[0] = 0
for i in range(n):
    for j in range(i+1, i+k+1):
        if j < n:
            dp[j] = min(dp[j], dp[i]+abs(arr[i]-arr[j]))
print(dp[-1])

Buggy python submission (verdict: Time Limit Exceeded):
# key not available ""
import math
n, k = [int(i) for i in input().split()]
arr = [int(i) for i in input().split()]
dp = [0]*n
dp[0] = 0
for i in range(1, n):
    for j in range(1, k+1):
        if i-j >= 0:
            if j == 1:
                dp[i] = dp[i-1]+abs(arr[i]-arr[i-1])
            else:
                dp[i] = min(dp[i], dp[i-j]+abs(arr[i]-arr[i-j]))
print(dp[-1])


Fixed submission:
# key not available ""
import sys
n, k = [int(i) for i in input().split()]
arr = [int(i) for i in input().split()]
dp = [sys.maxsize]*n
dp[0] = 0
for i in range(n):
    for j in range(i+1, i+k+1):
        if j < n:
            dp[j] = min(dp[j], dp[i]+abs(arr[i]-arr[j]))
print(dp[-1])