Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Time Limit Exceeded):
S = input()
N = len(S)
A = [0]*N
for i in range(N):
    n = i
    b = S[n]
    cnt = 0
    while True:
        if b=="R" and S[n+1]=="L":
            if cnt%2==0:
                A[n]+=1
            else:
                A[n+1]+=1
            break
        if b=="L" and S[n-1]=="R":
            if cnt%2==0:
                A[n]+=1
            else:
                A[n-1]+=1
            break
        if b=="R":
            n+=1
        else:
            n-=1
        cnt+=1
print(*A)

Fixed submission:
S = input()
N = len(S)
A = [0]*N
b = "R"
R = 0
cnt = 0
for i in range(N):
    cnt+=1
    if S[i]=="R":
        if b=="R":
            continue
        else:
            cnt=1
            b = "R"
    elif S[i]=="L":
        if b=="L":
            if cnt%2==1:
                A[R]+=1
            else:
                A[R+1]+=1
        else:
            R = i-1
            b="L"
            n = cnt//2
            A[i-1]+=n
            A[i]+=(cnt-n)
            cnt=0
print(*A)
Buggy python submission (verdict: Time Limit Exceeded):
L,R = map(int,input().split())
a = []
for i in range(L,min(R,L+2019*2)+1):
    a.append(i)
ans = 10**10
b = len(a)
for i in range(b):
    for j in range(b):
        if i<=j:
            break
        ans=min(ans,(a[i]*a[j])%2019)
print(ans)

Fixed submission:
L,R = map(int,input().split())
a = [i for i in range(L,min(L+2019,R)+1)]
b = len(a)
ans = 10**10
for i in range(b):
    for j in range(b):
        if i==j:
            break
        ans = min(ans,a[i]*a[j]%2019)
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
L,R = map(int,input().split())
a = []
for i in range(L,min(R,L+2019*2)+1):
    a.append(i%2019)
ans = 10**10
b = len(a)
for i in range(b):
    for j in range(b):
        if i<=j:
            break
        ans=min(ans,(a[i]*a[j])%2019)
print(ans)

Fixed submission:
L,R = map(int,input().split())
a = [i for i in range(L,min(L+2019,R)+1)]
b = len(a)
ans = 10**10
for i in range(b):
    for j in range(b):
        if i==j:
            break
        ans = min(ans,a[i]*a[j]%2019)
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
L,R = map(int,input().split())
a = []
for i in range(L,min(R,L+2019*3)+1):
    a.append(i%2019)
ans = 10**10
b = len(a)
for i in range(b):
    for j in range(b):
        if i<=j:
            break
        ans=min(ans,(a[i]*a[j])%2019)
print(ans)

Fixed submission:
L,R = map(int,input().split())
a = [i for i in range(L,min(L+2019,R)+1)]
b = len(a)
ans = 10**10
for i in range(b):
    for j in range(b):
        if i==j:
            break
        ans = min(ans,a[i]*a[j]%2019)
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
import scipy.linalg as linalg
import numpy as np
N = int(input())
A = list(map(int,input().split()))
#
b = np.array([a*2 for a in A])
A = []
for i in range(N):
    a = [0]*N
    if i==N-1:
        a[0]=1
        a[N-1]=1
    else:
        a[i]=1
        a[i+1]=1
    A.append(a)
A = np.array(A)
LU = linalg.lu_factor(A)
x = linalg.lu_solve(LU,b)
x = [int(a) for a in x]
print(*x)

Fixed submission:
N = int(input())
A = list(map(int,input().split()))
# solve
x = 0
for i in range(N):
    if i%2==0:
        x+=A[i]
    else:
        x-=A[i]
ans = [x]
for i in range(N-1):
    x = ans[i]
    ans.append(2*A[i]-x)
print(*ans)
Buggy python submission (verdict: Runtime Error):
from collections import Counter
N = int(input())
X = []
for i in range(N):
    x,y = map(int,input().split())
    X.append((x,y))
kouho = []
for i in range(N):
    for j in range(N):
        if i==j:continue
        kouho.append((X[i][0]-X[j][0],X[i][1]-X[j][1]))
C = Counter(kouho)
print(N-max(C.values()))

Fixed submission:
from collections import Counter
N = int(input())
X = []
for i in range(N):
    x,y = map(int,input().split())
    X.append((x,y))
kouho = []
for i in range(N):
    for j in range(N):
        if i==j:continue
        kouho.append((X[i][0]-X[j][0],X[i][1]-X[j][1]))
C = Counter(kouho)
if len(C)==0:print(1)
else:print(N-max(C.values()))
Buggy python submission (verdict: Runtime Error):
MOD = 10**9+7
N,M = map(int,input().split())
a = [int(input()) for _ in range(M)]
x = 0
y = 1
for i in range(N):
  if i+1 in a:
    z = 0
  else:
    z = x + y
  x,y = y,z  
print(z%MOD)


Fixed submission:
a = list(map(int,input().split()))
a.sort()
print(sum(a[:2]))
Buggy python submission (verdict: Time Limit Exceeded):
S = list("x"+input()+"xx")
N = len(S)

ans = 0
b = 0
while b<N:
    if S[b]=="A" and S[b+1]=="B" and S[b+2]=="C":
        S[b]="B"
        S[b+1]="C"
        S[b+2]="A"
        b-=2
        ans+=1
    b+=1
print(ans)

Fixed submission:
S = input()
N = len(S)
X = []
x = 0
while x<N-1:
    if S[x]=="B" and S[x+1]=="C":
        X.append("D")
        x+=1
    else:
        X.append(S[x])
    x+=1
ans = 0
N = len(X)
a = 0
for i in range(N):
    if X[i]=="A":
        a+=1
    elif X[i]=="D":
        ans+=a
    else:
        a=0
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
S = list("xxx"+input()+"xxx")
N = len(S)

ans = 0
b = 0
while b<N:
    if S[b]=="A" and "".join(S[b:b+3])=="ABC":
        S[b]="B"
        S[b+1]="C"
        S[b+2]="A"
        b-=3
        ans+=1
    b+=1
print(ans)

Fixed submission:
S = input()
N = len(S)
X = []
x = 0
while x<N-1:
    if S[x]=="B" and S[x+1]=="C":
        X.append("D")
        x+=1
    else:
        X.append(S[x])
    x+=1
ans = 0
N = len(X)
a = 0
for i in range(N):
    if X[i]=="A":
        a+=1
    elif X[i]=="D":
        ans+=a
    else:
        a=0
print(ans)
Buggy python submission (verdict: Runtime Error):
N,M = map(int,input().split())
#count chain node
cou_cha = [1 for i in range(N)]
cha_node = [[i]for i in range(N)]
for _ in range(M):
  x,y,z = map(int,input().split())
  cou_cha[x-1]+=1
  cou_cha[y-1]+=1
  cha_node[x-1].append(y-1)
  cha_node[y-1].append(x-1)
ans = cou_cha.count(1)
def f(x):
  global cou_cha,cha_node
  if cou_cha[x]==1:
    return
  cou_cha[x]=1
  for chi in cha_node[x]:
    f(chi)
while cou_cha.count(1)!=N:
  ans+=1
  f(cou_cha.index(max(cou_cha)))

print(ans)

Fixed submission:
N,M = map(int,input().split())
p = [i for i in range(N)]#parent
g = [[i] for i in range(N)]#group
for _ in range(M):
  x,y,z = map(int,input().split())
  x,y = p[x-1],p[y-1]
  if x==y:
    continue
  if len(g[x])<len(g[y]):
    x,y = y,x
  g[x] += g[y]
  for z in g[y]:
    p[z] = x
  g[y] = []
print(len(set(p)))
Buggy python submission (verdict: Runtime Error):
N,K = map(int,input())
print(N-K+1)

Fixed submission:
N,K = map(int,input().split())
print(N-K+1)
Buggy python submission (verdict: Time Limit Exceeded):
R,G,B,N = map(int,input().split())
ans = 0
#R>G and G>B
if R<B:
  x = R
  R = B
  B = x
for r in range(N+1):
  if r*R>N:
    break
  for g in range(N+1):
    if r*R+g*G>N:
      break
    if (N-r*R-g*G)%B==0:
      ans+=1
print(ans)

Fixed submission:
R,G,B,N = map(int,input().split())
ans = 0
for r in range(N+1):
  if r*R>N:
    break
  for g in range(N+1):
    S = N-r*R-g*G
    if S<0:
      break
    elif S%B==0:
      ans+=1
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
R,G,B,N = map(int,input().split())
ans = 0
for r in range(N+1):
  if r*R>N:
    break
  for g in range(N+1):
    if r*R+g*G>N:
      break
    if (N-r*R-g*G)%B==0:
      ans+=1
print(ans)

Fixed submission:
R,G,B,N = map(int,input().split())
ans = 0
for r in range(N+1):
  if r*R>N:
    break
  for g in range(N+1):
    S = N-r*R-g*G
    if S<0:
      break
    elif S%B==0:
      ans+=1
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
R,G,B,N = map(int,input().split())
ans = 0
for r in range(N//R+1):
  for g in range((N-R*r)//G+1):
    if r*R+g*G>N:
      continue
    if (N-r*R-g*G)%B==0:
      ans+=1
print(ans)


Fixed submission:
R,G,B,N = map(int,input().split())
ans = 0
for r in range(N+1):
  if r*R>N:
    break
  for g in range(N+1):
    S = N-r*R-g*G
    if S<0:
      break
    elif S%B==0:
      ans+=1
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
R,G,B,N = map(int,input().split())
ans = 0
for r in range(N//R+1):
  for g in range(N//G+1):
    if r*R+g*G>N:
      continue
    if (N-r*R-g*G)%B==0:
      ans+=1
print(ans)

Fixed submission:
R,G,B,N = map(int,input().split())
ans = 0
for r in range(N+1):
  if r*R>N:
    break
  for g in range(N+1):
    S = N-r*R-g*G
    if S<0:
      break
    elif S%B==0:
      ans+=1
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
N,K = map(int, input().split())
S = input()

a = []
b = []
before_num = '0'
count = 0
for i in range(N):
  if before_num==S[i]:
    count+=1
  else:
    if before_num=='0':
      a.append(count)
    else:
      b.append(count)
    before_num = S[i]
    count = 1
  if i==N-1:
    if before_num=='0':
      a.append(count)
    else:
      b.append(count)
b += [0]

if len(a)<=K:
  print(N)
  exit()
max_count = 0
for i in range(0,len(a)-K+1):
  count = sum(a[i:i+K])
  if i==0:
    count+=sum(b[i:i+K])
  else:
    count+=sum(b[i-1:i+K])
  max_count = max(count, max_count)
print(max_count)

Fixed submission:
N,K = map(int,input().split())
S = input()+"w"
A = []
if S[0]=="0":A.append(0)
a,b = 0,""
for s in S:
    if b!="" and b!=s:
        A.append(a)
        a=1
    else:a+=1
    b=s
if S[-2]=="0":A.append(0)
B = [0]
for i in range(len(A)):
    B.append(B[i]+A[i])
ans = 0
N = len(B)
for i in range(2*K+1,N):
    if i%2==0:continue
    ans = max(ans,B[i]-B[i-2*K-1])
print(ans if ans else B[N-1])
Buggy python submission (verdict: Runtime Error):
N,Q = map(int,input().split())
S = input()
lr = [list(map(int,input().split()))for i in range(Q)]
rui_count = []
AC_k = S.find('AC')
for i in range(N):
    if AC_k+1 > i:
        if i == 0:
            rui_count.append(0)
        else:
            rui_count.append(rui_count[i-1])
        continue
    AC_k = S[i:N].find('AC')
    if AC_k == -1:
        rui_count += [rui_count[i-1]+1 for j in range(i,N)]
        break
    AC_k += i
    rui_count.append(rui_count[i-1]+1)
count = []
for i in lr:
    count.append(rui_count[i[1]-1]-rui_count[i[0]-1])
for i in count:
    print(i)

Fixed submission:
N,Q = map(int,input().split())
S = input()
lr = [list(map(int,input().split()))for i in range(Q)]
rui_count = []
AC_k = S.find('AC')
if AC_k == -1:
    for i in range(Q):
        print(0)
    exit()
for i in range(N):
    if AC_k+1 > i:
        if i == 0:
            rui_count.append(0)
        else:
            rui_count.append(rui_count[i-1])
        continue
    AC_k = S[i:N].find('AC')
    if AC_k == -1:
        rui_count += [rui_count[i-1]+1 for j in range(i,N)]
        break
    AC_k += i
    rui_count.append(rui_count[i-1]+1)
count = []
for i in lr:
    count.append(rui_count[i[1]-1]-rui_count[i[0]-1])
for i in count:
    print(i)

Buggy python submission (verdict: Time Limit Exceeded):
N,Q = map(int,input().split())
S = input()
rui_count = []
count = []
for i in range(N):
    rui_count.append(S[0:i+1].count('AC'))
for i in range(Q):
    l,r = map(int,input().split())
    count.append(rui_count[r-1]-rui_count[l-1])
    
for i in count:
    print(i)

Fixed submission:
N,Q = map(int,input().split())
S = input()
lr = [list(map(int,input().split()))for i in range(Q)]
rui_count = []
AC_k = S.find('AC')
if AC_k == -1:
    for i in range(Q):
        print(0)
    exit()
for i in range(N):
    if AC_k+1 > i:
        if i == 0:
            rui_count.append(0)
        else:
            rui_count.append(rui_count[i-1])
        continue
    AC_k = S[i:N].find('AC')
    if AC_k == -1:
        rui_count += [rui_count[i-1]+1 for j in range(i,N)]
        break
    AC_k += i
    rui_count.append(rui_count[i-1]+1)
count = []
for i in lr:
    count.append(rui_count[i[1]-1]-rui_count[i[0]-1])
for i in count:
    print(i)

Buggy python submission (verdict: Time Limit Exceeded):
N,Q = map(int,input().split())
S = input()
count = []
for i in range(Q):
    l,r = map(int,input().split())
    count.append(S[l-1:r].count('AC'))

for i in count:
    print(i)

Fixed submission:
N,Q = map(int,input().split())
S = input()
lr = [list(map(int,input().split()))for i in range(Q)]
rui_count = []
AC_k = S.find('AC')
if AC_k == -1:
    for i in range(Q):
        print(0)
    exit()
for i in range(N):
    if AC_k+1 > i:
        if i == 0:
            rui_count.append(0)
        else:
            rui_count.append(rui_count[i-1])
        continue
    AC_k = S[i:N].find('AC')
    if AC_k == -1:
        rui_count += [rui_count[i-1]+1 for j in range(i,N)]
        break
    AC_k += i
    rui_count.append(rui_count[i-1]+1)
count = []
for i in lr:
    count.append(rui_count[i[1]-1]-rui_count[i[0]-1])
for i in count:
    print(i)
Buggy python submission (verdict: Time Limit Exceeded):
import sys
sys.setrecursionlimit(10**6)
N = int(input())
S = input()

count = -1

def dfs(index, moji):
    global N,S,count
    if index==N:
        count+=1
        return
    if S[index] in moji:
        dfs(index+1, moji)
    else:
        dfs(index+1, moji)
        dfs(index+1, moji+S[index])

dfs(0,'')
print(count)

Fixed submission:
N = int(input())
S = input()
MOD = 10**9+7

alp = 'abcdefghijklmnopqrstuvwxyz'
count_alp = [0 for i in range(26)]
count = 1

for s in S:
    count_alp[alp.find(s)]+=1

for i in count_alp:
    count*= (i+1)
print((count-1)%MOD)

Buggy python submission (verdict: Runtime Error):
import sys
sys.setrecursionlimit(10**10)
N = int(input())
S = input()

count = -1

def dfs(index, moji):
    global N,S,count
    if index==N:
        count+=1
        return
    if S[index] in moji:
        dfs(index+1, moji)
    else:
        dfs(index+1, moji)
        dfs(index+1, moji+S[index])

dfs(0,'')
print(count)

Fixed submission:
N = int(input())
S = input()
MOD = 10**9+7

alp = 'abcdefghijklmnopqrstuvwxyz'
count_alp = [0 for i in range(26)]
count = 1

for s in S:
    count_alp[alp.find(s)]+=1

for i in count_alp:
    count*= (i+1)
print((count-1)%MOD)

Buggy python submission (verdict: Runtime Error):
N = int(input())
S = input()

count = -1

def dfs(index, moji):
    global N,S,count
    if index==N:
        count+=1
        return
    if S[index] in moji:
        dfs(index+1, moji)
    else:
        dfs(index+1, moji)
        dfs(index+1, moji+S[index])

dfs(0,'')
print(count)

Fixed submission:
N = int(input())
S = input()
MOD = 10**9+7

alp = 'abcdefghijklmnopqrstuvwxyz'
count_alp = [0 for i in range(26)]
count = 1

for s in S:
    count_alp[alp.find(s)]+=1

for i in count_alp:
    count*= (i+1)
print((count-1)%MOD)
Buggy python submission (verdict: Runtime Error):
from fractions import gcd
n = int(input())
a = list(map(int,input().split()))
mina = max(a)
a.sort()
for i in range(n-1):
    mina = min(mina,math.gcd(a[i],a[i+1]))
print(mina)


Fixed submission:
n = int(input())
a = list(map(int,input().split()))
mina = max(a)
def gcd(x,y):
    if y==0:
        return x
    else:
        return gcd(y,x%y)
a.sort()
for i in range(n-1):
    mina = min(mina,gcd(a[i],a[i+1]))
print(mina)

Buggy python submission (verdict: Runtime Error):
import math
n = int(input())
a = list(map(int,input().split()))
mina = max(a)
a.sort()
for i in range(n-1):
    mina = min(mina,math.gcd(a[i],a[i+1]))
print(mina)


Fixed submission:
n = int(input())
a = list(map(int,input().split()))
mina = max(a)
def gcd(x,y):
    if y==0:
        return x
    else:
        return gcd(y,x%y)
a.sort()
for i in range(n-1):
    mina = min(mina,gcd(a[i],a[i+1]))
print(mina)

Buggy python submission (verdict: Runtime Error):
from fractions import gcd
n = int(input())
a = list(map(int,input().split()))
mina = max(a)
for i in range(n-1):
    mina = min(mina,math.gcd(a[i],a[i+1]))
print(mina)


Fixed submission:
n = int(input())
a = list(map(int,input().split()))
mina = max(a)
def gcd(x,y):
    if y==0:
        return x
    else:
        return gcd(y,x%y)
a.sort()
for i in range(n-1):
    mina = min(mina,gcd(a[i],a[i+1]))
print(mina)

Buggy python submission (verdict: Runtime Error):
import math
n = int(input())
a = list(map(int,input().split()))
mina = max(a)
for i in range(n-1):
    mina = min(mina,math.gcd(a[i],a[i+1]))
print(mina)

Fixed submission:
n = int(input())
a = list(map(int,input().split()))
mina = max(a)
def gcd(x,y):
    if y==0:
        return x
    else:
        return gcd(y,x%y)
a.sort()
for i in range(n-1):
    mina = min(mina,gcd(a[i],a[i+1]))
print(mina)
Buggy python submission (verdict: Runtime Error):
n = int(input())
s = []
for i in range(n):
  s.append(int(input()))
if max(s)<sum(s)-max(s):
  print("Yes")
else:
  print("No")

Fixed submission:
n = int(input())
s = list(map(int,input().split()))
if max(s)<sum(s)-max(s):
  print("Yes")
else:
  print("No")
Buggy python submission (verdict: Time Limit Exceeded):
n,m = map(int,input().split())
x = list(map(int,input().split()))
if n>=m:
  print(0)
else:
  x.sort()
  dx = []
  for i in range(m-1):
    dx.append(abs(x[i]-x[i+1]))
  for i in range(n-1):
    dx.remove(max(dx))
  print(sum(dx))

Fixed submission:
n,m = map(int,input().split())
x = list(map(int,input().split()))
if n>=m:
  print(0)
else:
  x.sort()
  dx = []
  for i in range(m-1):
    dx.append(abs(x[i]-x[i+1]))
  dx.sort()
  print(sum(dx[:m-n]))
Buggy python submission (verdict: Runtime Error):
n = int(input())
ab = []
x = 0
for i in range(n):
  a,b = map(int,input().split())
  x -= b
  ab.append(a+b)
ab.sort()
for i in range(raound(n/2)):
  x += ab[i]
print(x)

Fixed submission:
n = int(input())
ab = []
x = 0
for i in range(n):
  a,b = map(int,input().split())
  x -= b
  ab.append(a+b)
ab.sort()
ab.reverse()
for i in range(n):
  if i%2==0:
      x+=ab[i]
print(x)

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = []
b = []
for i in range(n):
    c,d = map(int,input().split())
    a.append(c)
    b.append(d)
t = 0
while(1):
    if len(a)==0:
        break
    maxa = -1
    ai = -1
    if b.count(max(b)) == len(b):
        ai = a.index(max(a))
    else:
        for k in [i for i, x in enumerate(b) if x == max(b)]:
            if maxa <= a[k]:
                maxa = a[k]
                ai = k
    t += a[ai]
    del a[ai]
    del b[ai]

    if len(b)==0:
        break
    maxb = -1
    bi = -1
    if a.count(max(a)) == len(a):
        bi = b.index(max(b))
    else:
        for k in [i for i, x in enumerate(a) if x == max(a)]:
            if maxb <= b[k]:
                maxb = b[k]
                bi = k
    t -= b[bi]
    del a[bi]
    del b[bi]
print(t)

Fixed submission:
n = int(input())
ab = []
x = 0
for i in range(n):
  a,b = map(int,input().split())
  x -= b
  ab.append(a+b)
ab.sort()
ab.reverse()
for i in range(n):
  if i%2==0:
      x+=ab[i]
print(x)

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = []
b = []
for i in range(n):
    c,d = map(int,input().split())
    a.append(c)
    b.append(d)
t = 0
while(1):
    if len(a)==0:
        break
    
    maxa = -1
    ai = -1
    for k in [i for i, x in enumerate(b) if x == max(b)]:
        if maxa <= a[k]:
            maxa = a[k]
            ai = k
    t += maxa
    del a[ai]
    del b[ai]

    if len(b)==0:
        break
    maxb = -1
    bi = -1
    for k in [i for i, x in enumerate(a) if x == max(a)]:
        if maxb <= b[k]:
            maxb = b[k]
            bi = k
    t -= maxb
    del a[bi]
    del b[bi]
print(t)

Fixed submission:
n = int(input())
ab = []
x = 0
for i in range(n):
  a,b = map(int,input().split())
  x -= b
  ab.append(a+b)
ab.sort()
ab.reverse()
for i in range(n):
  if i%2==0:
      x+=ab[i]
print(x)
Buggy python submission (verdict: Runtime Error):
def dp(n,cost):
    global N,h
    if n==N-1:
        return cost
    if n==N-2:
        return dp(n+1,cost+abs(h[n]-h[n+1]))
    else:
        take1 = dp(n+1,cost+abs(h[n]-h[n+1]))
        take2 = dp(n+2,cost+abs(h[n]-h[n+2]))
        return min(take1, take2)
N = int(input())
h = list(map(int,input().split()))
print(dp(0,0))

Fixed submission:
N = int(input())
h = list(map(int,input().split()))
sum = []
sum.append(0)
for i in range(1,N):
    if i>1:
        sum.append(min(sum[i-1]+abs(h[i-1]-h[i]),sum[i-2]+abs(h[i-2]-h[i])))
    else:
        sum.append(sum[i-1]+abs(h[i-1]-h[i]))
print(sum[N-1])
Buggy python submission (verdict: Time Limit Exceeded):
N,K = map(int,input().split())
h = list(map(int,input().split()))
dp = [0 for i in range(N)]
for i in range(1,N):
  s = 10**10
  for j in range(1,min(i,K)+1):
    s = min(s,dp[i-j]+abs(h[i]-h[i-j]))
  dp[i] = s
print(dp[N-1])

Fixed submission:
N,K = map(int,input().split())
H = list(map(int,input().split()))
DP = [0]
for i in range(1,N):
    a = DP[i-1] + abs(H[i]-H[i-1])
    for j in range(2,min(K,i)+1):
        b = DP[i-j] + abs(H[i]-H[i-j])
        a = min(a,b)
    DP.append(a)
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,abs(h[0]-h[1])]
for i in range(2,N):
  dp.append(min([dp[j]+abs(h[j]-h[i]) for j in range(max(0,i-K),i)]))
print(dp[N-1])

Fixed submission:
N,K = map(int,input().split())
H = list(map(int,input().split()))
DP = [0]
for i in range(1,N):
    a = DP[i-1] + abs(H[i]-H[i-1])
    for j in range(2,min(K,i)+1):
        b = DP[i-j] + abs(H[i]-H[i-j])
        a = min(a,b)
    DP.append(a)
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,abs(h[0]-h[1])]
for i in range(2,N):
  s = []
  for j in range(max(0,i-K),i):
    s.append(dp[j]+abs(h[j]-h[i]))
  dp.append(min(s))
print(dp[N-1])

Fixed submission:
N,K = map(int,input().split())
H = list(map(int,input().split()))
DP = [0]
for i in range(1,N):
    a = DP[i-1] + abs(H[i]-H[i-1])
    for j in range(2,min(K,i)+1):
        b = DP[i-j] + abs(H[i]-H[i-j])
        a = min(a,b)
    DP.append(a)
print(DP[N-1])
Buggy python submission (verdict: Time Limit Exceeded):
A,B,C=map(int,input().split())
ABC=0
while(1):
    if C>0:
        ABC+=1
        C-=1
    if C>0 and A==0 and B==0:
        break
    if B>0:
        ABC+=1
        B-=1
    elif A>0:
        A-=1
print(ABC)

Fixed submission:
A,B,C=map(int,input().split())
Z = C-A-B
if Z>1:
    print(B*2+A+1)
else:
    print(B+C)
Buggy python submission (verdict: Time Limit Exceeded):
N,P = map(int,input().split())
c = int(P**(1/N))+1
def is_prime(q):
    q = abs(q)
    if q == 2: return True
    if q < 2 or q&1 == 0: return False
    return pow(2, q-1, q) == 1
if N>1 and is_prime(P):
    print(1)
    exit()
while(1):
    if P%(c**N)==0:
        print(c)
        exit()
    c-=1

Fixed submission:
N,P = map(int,input().split())
r = round(P**(1/N))
for i in range(r,0,-1):
    if P%(i**N)==0:
        print(i)
        exit()

Buggy python submission (verdict: Time Limit Exceeded):
N,P = map(int,input().split())
c = int(P**(1/N))+1
while(1):
    if P%(c**N)==0:
        print(c)
        exit()
    c-=1

Fixed submission:
N,P = map(int,input().split())
r = round(P**(1/N))
for i in range(r,0,-1):
    if P%(i**N)==0:
        print(i)
        exit()

Buggy python submission (verdict: Time Limit Exceeded):
N,P = map(int,input().split())
c = int(P**(1/N))+1
for i in range(c,0,-1):
    if P%(i**N)==0:
        print(i)
        exit()

Fixed submission:
N,P = map(int,input().split())
r = round(P**(1/N))
for i in range(r,0,-1):
    if P%(i**N)==0:
        print(i)
        exit()

Buggy python submission (verdict: Time Limit Exceeded):
N,P = map(int,input().split())
Z = 2
k = 1
if N==1:
    print(P)
    exit()
while(1):
    if P < (Z**N):
        break
    if P%(Z**N)==0:
        k*=Z
        P/=(Z**N)
        Z=1
    Z+=1
print(k)

Fixed submission:
N,P = map(int,input().split())
r = round(P**(1/N))
for i in range(r,0,-1):
    if P%(i**N)==0:
        print(i)
        exit()

Buggy python submission (verdict: Time Limit Exceeded):
N,P = map(int,input().split())
k = 1
c = int(P**(1/N))+2
for i in range(c,1,-1):
    if P%(i**N)==0:
        k=i
        break
print(k)

Fixed submission:
N,P = map(int,input().split())
r = round(P**(1/N))
for i in range(r,0,-1):
    if P%(i**N)==0:
        print(i)
        exit()