Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
n,m = map(int,input().split())
lis = [[] for _ in range(10)]
for _ in range(n):
    a,b = map(int,input().split())
    lis[a-1].append(b)
ans = 0
li = []
for i in range(m):
    li += lis[i]
    li.sort(reverse=True)
    try:
        p = li.pop(0)
        ans += p
    except:
        continue
print(ans)

Fixed submission:
from heapq import heappush,heappop,heapify

n,m = map(int,input().split())
lis = [[] for i in range(m+1)]

for _ in range(n):
    a,b = map(int,input().split())
    if a <= m:
        lis[a].append(-b)

ans = 0
num = []
heapify(num)

for j in range(1,m+1):
    for nu in lis[j]:
        heappush(num,nu)
    if len(num) > 0:
        work = heappop(num)
        ans += -work
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
n,m = map(int,input().split())
lis = [[] for _ in range(10**5)]
for _ in range(n):
  a,b = map(int,input().split())
  lis[a-1].append(b)
ans = 0
li = []
for i in range(m):
  li += lis[i]
  li.sort(reverse=True)
  try:
    ans += li[0]
    del(li[0])
  except:
    continue
print(ans)

Fixed submission:
from heapq import heappush,heappop,heapify

n,m = map(int,input().split())
lis = [[] for i in range(m+1)]

for _ in range(n):
    a,b = map(int,input().split())
    if a <= m:
        lis[a].append(-b)

ans = 0
num = []
heapify(num)

for j in range(1,m+1):
    for nu in lis[j]:
        heappush(num,nu)
    if len(num) > 0:
        work = heappop(num)
        ans += -work
print(ans)
Buggy python submission (verdict: Runtime Error):
a,b,c = map(int,input().split())
print(max(0,c-(a-b))

Fixed submission:
a,b,c = map(int,input().split())
print(max(0,c-(a-b)))
Buggy python submission (verdict: Runtime Error):
n = int(input())
lis = list(map(int,input().split()))
for i in range(n-1):
  if lis[i] -1 >= lis[i+1]:
    lis[i] -= 1
for i in range(n-1):
  if lis[i] > lis[i+1]:
    print("No")
    exit()
print("Yes")


Fixed submission:
n = int(input())
ans = 0
for i in range(1,n+1):
  if len(str(i)) % 2 == 1:
    ans += 1
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
s = str(input())
num = len(s)
dp = [[0] * 13 for i in range(num+1)]
dp[0][0] = 1
mod = 13
ansmod = 10 ** 9 + 7

for i in range(num):
    if s[i] == "?":
        for j in range(10):
            for k in range(13):
                dp[i+1][(k * 10 +j)%mod] += dp[i][k]
    else:
        for k in range(13):
            dp[i+1][(k * 10 + (int(s[i])))%mod] += dp[i][k]
    for j in range(13):
        dp[i+1][j] %= ansmod
  #    print(dp)
print(dp[num][5])

Fixed submission:
s = str(input())
dp = [[0] * 13 for i in range(len(s)+1)]
dp[0][0] = 1
Naoppy = 1
mod = 13
ansmod = 10 ** 9 + 7
ans = 0
for i in range(len(s)):
    if s[i] == "?":
        for j in range(10):
            for k in range(13):
                dp[i+1][(k * 10 +j)%mod] += dp[i][k]
    else:
        for k in range(13):
            dp[i+1][(k * 10 + (int(s[i])))%mod] += dp[i][k]
    for j in range(13):
        dp[i+1][j] %= ansmod
  #    print(dp)
print(dp[len(s)][5])

Buggy python submission (verdict: Time Limit Exceeded):
s = str(input())
dp = [[0] * 13 for i in range(len(s)+1)]
dp[0][0] = 1
Naoppy = 1
mod = 13
ansmod = 10 ** 9 + 7
ans = 0
for i in range(len(s)):
    if s[i] == "?":
        for j in range(10):
            for k in range(13):
                dp[i+1][(k * 10 +j)%mod] += dp[i][k]
    else:
        for k in range(13):
            dp[i+1][(k * 10 + (int(s[i])))%mod] += dp[i][k]
    for j in range(13):
        dp[i+1][j] %= ansmod
  #    print(dp)
print(dp[len(s)][5])

Fixed submission:
s = str(input())
dp = [[0] * 13 for i in range(len(s)+1)]
dp[0][0] = 1
Naoppy = 1
mod = 13
ansmod = 10 ** 9 + 7
ans = 0
for i in range(len(s)):
    if s[i] == "?":
        for j in range(10):
            for k in range(13):
                dp[i+1][(k * 10 +j)%mod] += dp[i][k]
    else:
        for k in range(13):
            dp[i+1][(k * 10 + (int(s[i])))%mod] += dp[i][k]
    for j in range(13):
        dp[i+1][j] %= ansmod
  #    print(dp)
print(dp[len(s)][5])
Buggy python submission (verdict: Runtime Error):
n = int(input())
lis = [int(input()) for i in range(n)]
li=sort(lis,reverse=True)
for i in range(n):
  if lis[i] == lis[0]:
    print(lis[1])
  else:
    print(lis[0])

Fixed submission:
n = int(input())
lis = [int(input()) for i in range(n)]
li=sorted(lis,reverse=True)
for i in range(n):
  if lis[i] == li[0]:
    print(li[1])
  else:
    print(li[0])
Buggy python submission (verdict: Runtime Error):
n = int(input())
lis = list(map(int,input().split()))
ans = 0
for i in range(1,n-1):
  lis = sorted([lis[i-1],lis[i],lis[i+1]])
  if lis[1] == lis[i]:
    ans += 1
print(ans)

Fixed submission:
n = int(input())
lis = list(map(int,input().split()))
ans = 0
for i in range(1,n-1):
  li = sorted([lis[i-1],lis[i],lis[i+1]])
  if li[1] == lis[i]:
    ans += 1
print(ans)
Buggy python submission (verdict: Runtime Error):
n,blue = map(int,input().split())
red = n-blue
mod = 10 ** 9 + 7

now = [1]
for i in range(1,red+2):
    next = []
    for j in range(min(i+1,blue+1)):
        if j == 0 or j == i:
            next.append(1)
        else:
            next.append((now[j-1]+now[j])%mod)
    now = next

  # print(now)
for i in range(1,blue+1):
    print((now[i] * pow(i,blue-i,mod))%mod)

Fixed submission:
n,blue = map(int,input().split())
red = n-blue
mod = 10 ** 9 + 7

now = [1]
get = [1]
for i in range(1,red+2):
    next = []
    for j in range(min(i+1,blue+1)):
        if j == 0 or j == i:
            next.append(1)
        else:
            next.append((now[j-1]+now[j])%mod)
    now = next
for i in range(1,blue):
    next = []
    for j in range(i+1):
        if j == 0 or j == i:
            next.append(1)
        else:
            next.append((get[j-1]+get[j])%mod)
    get = next

  # print(now)
for i in range(1,blue+1):
    try:
  #        print(now[i],get[i-1])
        print((now[i] * get[i-1])%mod)
    except:
        print(0)

Buggy python submission (verdict: Runtime Error):
n,blue = map(int,input().split())
red = n-blue
mod = 10 ** 9 + 7

now = [1]
for i in range(1,red+2):
    next = []
    for j in range(min(i+1,blue+1)):
        if j == 0 or j == i:
            next.append(1)
        else:
            next.append((now[j-1]+now[j])%mod)
    now = next

  # print(now)
for i in range(1,blue+1):
    print((now[i] * pow(i,blue-i,mod))%mod)

Fixed submission:
n,blue = map(int,input().split())
red = n-blue
mod = 10 ** 9 + 7

now = [1]
get = [1]
for i in range(1,red+2):
    next = []
    for j in range(min(i+1,blue+1)):
        if j == 0 or j == i:
            next.append(1)
        else:
            next.append((now[j-1]+now[j])%mod)
    now = next
for i in range(1,blue):
    next = []
    for j in range(i+1):
        if j == 0 or j == i:
            next.append(1)
        else:
            next.append((get[j-1]+get[j])%mod)
    get = next

  # print(now)
for i in range(1,blue+1):
    try:
  #        print(now[i],get[i-1])
        print((now[i] * get[i-1])%mod)
    except:
        print(0)
Buggy python submission (verdict: Runtime Error):
n = int(input())
lis = list(map(int,input().split()))
le = 0
ri = sum(lis)
ans = sum(lis)
cou = 0
for i in range(1,101):
  while lis[cou] == i:
    le += lis[cou]
    ri -= lis[cou]
    cou += 1
  ans = min(ans,abs(le-ri))
print(ans)


Fixed submission:
n = int(input())
lis = list(map(int,input().split()))
ans = 10 ** 9
le = 0
ri = sum(lis)
ans = sum(lis)
for num in lis:
  le += num
  ri -= num
  ans = min(ans,abs(ri-le))
print(ans)

Buggy python submission (verdict: Runtime Error):
n = int(input())
lis = list(map(int,input().split()))
le = 0
ri = sum(lis)
ans = sum(lis)
cou = 0
for i in range(1,101):
  while lis[cou] == i:
    ri += lis[cou]
    le -= lis[cou]
    cou += 1
  ans = min(ans,abs(le-ri))
print(ans)


Fixed submission:
n = int(input())
lis = list(map(int,input().split()))
ans = 10 ** 9
le = 0
ri = sum(lis)
ans = sum(lis)
for num in lis:
  le += num
  ri -= num
  ans = min(ans,abs(ri-le))
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
lis = list(map(int,input().split()))
le = 0
ri = sum(lis)
ans = sum(lis)
cou = 0
for i in range(1,101):
  while lis[cou] == i:
    ri += lis[cou]
    le -= lis[cou]
  ans = min(ans,abs(le-ri))
print(ans)

Fixed submission:
n = int(input())
lis = list(map(int,input().split()))
ans = 10 ** 9
le = 0
ri = sum(lis)
ans = sum(lis)
for num in lis:
  le += num
  ri -= num
  ans = min(ans,abs(ri-le))
print(ans)
Buggy python submission (verdict: Runtime Error):
n,m = map(int,input().split())
lis = [int(input()) for i in range(m)]
dp = [0 for i in range(n+2)]
dp[0] = 1
cou = 0
co = 0
for i in range(n):
  if i+1 != lis[cou]:
    dp[i+1] += dp[i]
    dp[i+1] %= 10 ** 9+7
  else:
    cou +=1
  if i+2 !=  lis[co]:
    dp[i+2] += dp[i]
    dp[i+2] %= 10 ** 9 + 7
  else:
    co += 1
print(dp[n])

Fixed submission:
n,m = map(int,input().split())
lis = [int(input()) for i in range(m)]
dp = [0 for i in range(n+2)]
lis.append(0)
dp[0] = 1
cou = 0
co = 0
if lis[0] == 1:co += 1
for i in range(n):
  if i+1 != lis[cou]:
    dp[i+1] += dp[i]
    dp[i+1] %= 10 ** 9+7
  else:
    cou +=1
  if i+2 != lis[co]:
    dp[i+2] += dp[i]
    dp[i+2] %= 10 ** 9 + 7
  else:
    co += 1
print(dp[n])

Buggy python submission (verdict: Time Limit Exceeded):
n,m = map(int,input().split())
lis = [int(input()) for i in range(m)]
dp = [0 for i in range(n+2)]
dp[0] = 1
for i in range(n):
  if i+1 not in lis:
    dp[i+1] += dp[i]
    dp[i+1] %= 10 ** 9+7
  if i+2 not in lis:
    dp[i+2] += dp[i]
    dp[i+2] %= 10 ** 9 + 7
print(dp[n])


Fixed submission:
n,m = map(int,input().split())
lis = [int(input()) for i in range(m)]
dp = [0 for i in range(n+2)]
lis.append(0)
dp[0] = 1
cou = 0
co = 0
if lis[0] == 1:co += 1
for i in range(n):
  if i+1 != lis[cou]:
    dp[i+1] += dp[i]
    dp[i+1] %= 10 ** 9+7
  else:
    cou +=1
  if i+2 != lis[co]:
    dp[i+2] += dp[i]
    dp[i+2] %= 10 ** 9 + 7
  else:
    co += 1
print(dp[n])
Buggy python submission (verdict: Runtime Error):
n,k = map(int,input().split())
lis = list(map(int,input().split()))
ans = 0
for i in range(n):
    for j in range(n-i+1):
        num = lis[:i]
        if j > 0:
            num += lis[-j:]
        if len(num) <= k:
            cnt = min(len(num),k-len(num))
            num.sort()
            for h in range(cnt):
                num[cnt] = max(0,num[cnt])
            ans = max(ans,sum(num))
print(ans)

Fixed submission:
n,k = map(int,input().split())
lis = list(map(int,input().split()))
ans = 0
for i in range(n):
    for j in range(n-i+1):
        num = lis[:i]
        if j:
            num += lis[-j:]
        if len(num) <= k:
            spell = min(len(num),k-len(num))
            num.sort()
            for l in range(spell):
                num[l] = max(0,num[l])
            ans = max(ans,sum(num))
print(ans)
Buggy python submission (verdict: Runtime Error):
n,m = map(int,input().split())
s = str(input())
print(s[:m-1]+s[m-1].lower+s[m-1])

Fixed submission:
n,m = map(int,input().split())
s = str(input())
print(s[:m-1]+chr(ord(s[m-1])-ord("A")+ord("a"))+s[m:])
Buggy python submission (verdict: Runtime Error):
n = int(input())
lis = [[] for i in range(n)]

for i in range(n-1):
    u,v,w = map(int,input().split())
    lis[u-1].append((v-1,w%2))
    lis[v-1].append((u-1,w%2))

li = [-1] * n

def calc(i,c):
    li[i] = c
    for j, w in lis[i]:
        if li[j] < 0:
            calc(j, li[i]^w)

calc(0,0)
for d in li:
    print(d)

Fixed submission:
import sys
sys.setrecursionlimit(1000000)

n = int(input())
lis = [[] for i in range(n)]

for i in range(n-1):
    u,v,w = map(int,input().split())
    lis[u-1].append((v-1,w%2))
    lis[v-1].append((u-1,w%2))

li = [-1] * n

def calc(i,c):
    li[i] = c
    for j, w in lis[i]:
        if li[j] < 0:
            calc(j, li[i]^w)

calc(0,0)

for d in li:
    print(d)
Buggy python submission (verdict: Runtime Error):
import math
n = int(input())
ans = 0
for i in range(1,math.floor(math.sqrt(n))+1):
    if n % i == 0:
        num = (n//i)-1
        if n // num == n % num:
            ans += num
print(ans)

Fixed submission:
import math
n = int(input())
ans = 0
for i in range(1,math.floor(math.sqrt(n))+1):
    if n % i == 0:
        num = (n//i)-1
        if num > 0:
            if n // num == n % num:
                ans += num
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
import fractions
n = int(input())
lis = list(map(int,input().split()))
lis.sort()
if n == 2:
  print(max(lis))
  exit()
li = [lis[0]]
lii = [lis[-1]]
for i in range(1,n):
  li.append(fractions.gcd(li[i-1],lis[i]))
  lii.insert(0,fractions.gcd(lii[-i],lis[-(i+1)]))
ans = max(lii[1],li[-2])
for i in range(n-2):
  ans = max(ans,fractions.gcd(li[i],lii[i+2]))
print(ans)

Fixed submission:
from fractions import gcd
n = int(input())
a = list(map(int, (input().split())))

if n == 2:
    print(max(a[0], a[1]))
    exit()

noskip = gcd(a[0], a[1])
skipped = max(gcd(a[0], a[2]), gcd(a[1], a[2]))

for i in range(2, n):
    skipped = max(gcd(skipped, a[i]), noskip)
    noskip = gcd(noskip, a[i])

print(max(noskip, skipped))
Buggy python submission (verdict: Runtime Error):
s = str(input())
w1,w2,b1,b2 = 0,0,0,0
for i in range(len(s)):
  if i % 2 == 0:
  	if s[i] == "0":
      w1 += 1
    else:
      b1 += 1
  else:
    if s[i] == "0":
      w2 += 1
    else:
      b2 += 1
print(min(w1+b2,w2+b1))

Fixed submission:
s = str(input())
w1,w2,b1,b2 = 0,0,0,0
for i in range(len(s)):
  if i % 2 == 0:
    if s[i] == "0":
      w1 += 1
    else:
      b1 += 1
  else:
    if s[i] == "0":
      w2 += 1
    else:
      b2 += 1
print(min(w1+b2,w2+b1))
Buggy python submission (verdict: Runtime Error):
import math
n = int(input())
lis = [int(input()) for i in range(n)]
print(5 + math.ceil(n/min(lis))-1)

Fixed submission:
n = int(input())
lis = [int(input()) for i in range(5)]
key = 0
if n % min(lis) == 0:key = 1
print(5 + n//min(lis)-key)
Buggy python submission (verdict: Runtime Error):
lis = [1 for i in range(26)]
s = str(input())
for i in range(len(s)):
  lis[ord(s[i])-ord("a")] += 1
ans = 1
for num in lis:
  ans *= num
print(ans)

Fixed submission:
lis = [1 for i in range(26)]
n = int(input())
s = str(input())
for i in range(n):
  lis[ord(s[i])-ord("a")] += 1
ans = 1
for num in lis:
  ans *= num
  ans %= 10 ** 9 + 7
print(ans-1)
Buggy python submission (verdict: Runtime Error):
MOD = 10**9 + 7

N = int(input())
C = [int(input()) for _ in range(N)]

dp = [0]*(N+1)
lis = [-1] * (2 * 10**5 + 1)
dp[0] = 1
lis[C[0]] = 0
for i,c in enumerate(C[1:],1):
    prev_i = c_to_i[c]
    dp[i] = dp[i-1]
    if prev_i != i-1:
        dp[i] += dp[prev_i]
        dp[i] %= MOD
    lis[c] = i

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



Fixed submission:
MOD = 10**9 + 7
N = int(input())
C = [int(input()) for _ in range(N)]
dp = [0]*(N+1)
lis = [-1] * (2 * 10**5 + 1)
dp[0] = 1
lis[C[0]] = 0
for i,c in enumerate(C[1:],1):
    prev_i = lis[c]
    dp[i] = dp[i-1]
    if prev_i != i-1:
        dp[i] += dp[prev_i]
        dp[i] %= MOD
    lis[c] = i
answer = dp[N-1]
print(answer)
Buggy python submission (verdict: Runtime Error):
n,m,c = map(int,input().split())
b = list(map(int,input().split()))
ans = 0
for i in range(n):
    num = c
    lis = list(map(int,input().split()))
    for j in range(m):
        num += b[j] * lis[i]
    if num > 0:ans += 1
print(ans)

Fixed submission:
n,m,c = map(int,input().split())
b = list(map(int,input().split()))
ans = 0
for i in range(n):
    num = c
    lis = list(map(int,input().split()))
    for j in range(m):
        num += b[j] * lis[j]
    if num > 0:ans += 1
print(ans)
Buggy python submission (verdict: Runtime Error):
n,m = map(int,input().split())
lis = list(map(int,input().split()))
lis.sort(key = lambda x:x[1])
ans = 0
cou = 0
num = 0
while cou < m:
  nu = min(lis[num],m-cou)
  cou += nu
  ans += lis[num] * nu
  num += 1
print(ans)
  

Fixed submission:
n, m = map(int, input().split())
lis = [list(map(int,input().split())) for i in range(n)]
lis.sort(key=lambda x:x[0])
ans = 0
cou = 0
num = 0
while cou < m:
    nu = min(lis[num][1], m - cou)
    cou += nu
    ans += lis[num][0] * nu
    num += 1
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
a,b = map(int,input().split())
ans = 0
for i in range(a,b+1):
    ans = ans^i
print(ans)

Fixed submission:
a,b = map(int,input().split())
nu = 0
if a % 2 == 1:
    nu = a
    a += 1
num = (b-a) // 4
a += 4 * num
ans = a
for i in range(a+1,b+1):
    ans ^= i
ans ^= nu
print(ans)
Buggy python submission (verdict: Runtime Error):
s = str(input())
n = len(s)
for i in range(n):
  for j in range(i,n):
    if s[:i] + s[k:] == "keyence":
      print("YES")
      exit()
print("NO")

Fixed submission:
s = str(input())
n = len(s)
for i in range(n):
  for j in range(i,n):
    if s[:i] + s[j:] == "keyence":
      print("YES")
      exit()
print("NO")

Buggy python submission (verdict: Runtime Error):
s = str(input())
num = len(s)
for i in range(n):
  for j in range(i,n):
    if s[:i] + s[k:] == "keyence":
      print("YES")
      exit()
print("NO")

Fixed submission:
s = str(input())
n = len(s)
for i in range(n):
  for j in range(i,n):
    if s[:i] + s[j:] == "keyence":
      print("YES")
      exit()
print("NO")
Buggy python submission (verdict: Runtime Error):
h,w = map(int,input().split())
lis = [str(input()) for i in range(h)]
ans = 0
ch = [[0] * w for i in range(h)]

def firstcheck(x,y):
    if lis[x][y] != "#" or ch[x][y] != 0:
        return False
    if x > 0:
        if lis[x-1][y] == ".":
            return True
    if x < h-1:
        if lis[x+1][y] == ".":
            return True
    if y > 0:
        if lis[x][y-1] == ".":
            return True
    if y < w-1:
        if lis[x][y+1] == ".":
            return True
    return False

for sx in range(h):
    for sy in range(w):
        if firstcheck(sx,sy):
            cnt = 1
            nu = 0
            ch[sx][sy] = 1
            num = [[0] * w for i in range(h)]
            now = {(sx,sy,1)}
            while len(now) != 0:
                tmp = set()
                for x,y,iro in now:
                    if x > 0:
                        if lis[x-1][y] != lis[x][y] and num[x-1][y] == 0:
                            nu += iro
                            tmp.add((x-1,y,(iro+1)%2))
                            num[x-1][y] = 1
                            if lis[x-1][y] == "#" and ch[x-1][y] == 0:
                                cnt += 1
                                ch[x-1][y] = 1
                    if x < h-1:
                        if lis[x+1][y] != lis[x][y] and num[x+1][y] == 0:
                            nu += iro
                            tmp.add((x+1,y,(iro+1)%2))
                            num[x+1][y] = 1
                            if lis[x+1][y] == "#" and ch[x+1][y] == 0:
                                cnt += 1
                                ch[x+1][y] = 1
                    if y > 0:
                        if lis[x][y-1] != lis[x][y] and num[x][y-1] == 0:
                            nu += iro
                            tmp.add((x,y-1,(iro+1)%2))
                            num[x][y-1] = 1
                            if lis[x][y-1] == "#" and ch[x][y-1] == 0:
                                cnt += 1
                                ch[x][y-1] = 1
                    if y < w-1:
                        if lis[x][y+1] != lis[x][y] and num[x][y+1] == 0:
                            nu += iro
                            tmp.add((x,y+1,(iro+1)%2))
                            num[x][y+1] = 1
                            if lis[x][y+1] == "#" and ch[x][y+1] == 0:
                                cnt += 1
                                ch[x][y+1] = 1
                now = tmp
            ans += nu * cnt
print(ans)

Fixed submission:
n = int(input())
h = int(input())
w = int(input())
print((n-h+1)*(n-w+1))
Buggy python submission (verdict: Runtime Error):
def dp():
    n,w = map(int,input().split())
    lis = (map(int,input().split()) for i in range(n))
    
    dpp = [0] * (w + 1)
    for weight, value in lis:
        for j in range(w,weight-1,-1):
            dp = dpp[j-weight] + value
            if dpp[j] < dp:
                dpp[j] = dp
    return max(dpp)
print(dp())

Fixed submission:
n = int(input())
lis = list(map(int,input().split()))
ans = [10 ** 9 for i in range(n+5)]
ans[0] = 0
for i in range(n):
    if i < n-1:
        ans[i+1] = min(ans[i+1],ans[i]+abs(lis[i+1]-lis[i]))
    if i < n-2:
        ans[i+2] = min(ans[i+2],ans[i]+abs(lis[i+2]-lis[i]))
print(ans[n-1])
Buggy python submission (verdict: Time Limit Exceeded):
n,k = map(int,input().split())
lis = list(map(int,input().split()))
dp = [10 ** 10 for i in range(n+k)]
dp[0] = 0
for i in range(n):
  for j in range(1,k+1):
    if i + j < n:
      dp[i+j] = min(dp[i+j],dp[i] + abs(lis[i+j]-lis[i]))
print(dp[n-1])

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

dp = [10 ** 10 for i in range(n+k+1)]

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

Buggy python submission (verdict: Time Limit Exceeded):
n,k = map(int,input().split())
lis = list(map(int,input().split()))

dp = [10 ** 10 for i in range(n+k+1)]

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

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

dp = [10 ** 10 for i in range(n+k+1)]

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

Buggy python submission (verdict: Time Limit Exceeded):
n,k = map(int,input().split())
lis = list(map(int,input().split()))
ans = [10 ** 9 for i in range(n+5)]
ans[0] = 0
for i in range(n):
    for step in range(1,k+1):
        if i + step < n:ans[i+step] = min(ans[i+step],ans[i] + abs(lis[i+step]-lis[i]))
print(ans[n-1])

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

dp = [10 ** 10 for i in range(n+k+1)]

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

Buggy python submission (verdict: Time Limit Exceeded):
n,k = map(int,input().split())
lis = list(map(int,input().split()))
ans = [10 ** 9 for i in range(n+5)]
ans[0] = 0
for i in range(n):
    for step in range(1,k+1):
        try:
            ans[i+step] = min(ans[i+step],ans[i] + abs(lis[i+step]-lis[i]))
        except:
            continue
print(ans[n-1])

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

dp = [10 ** 10 for i in range(n+k+1)]

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