Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
n,q=map(int,input().split())
edge=[[] for i in range(n)]
a=[0]*n
b=[0]*n
for i in range(n-1):
    x,y=map(int,input().split())
    edge[x-1].append(y-1)
    edge[y-1].append(x-1)
for i in range(q):
    p,x=map(int,input().split())
    a[p-1]+=x
def dfs(node,tmp):
    a[node]+=tmp
    b[node]=1
    for i in edge[node]:
        if b[i]==0:
            dfs(i,a[node])
dfs(0,0)
print(*a)

Fixed submission:
import sys
sys.setrecursionlimit(10**7)
n,q=map(int,input().split())
edge=[[] for i in range(n)]
a=[0]*n
b=[0]*n
for i in range(n-1):
    x,y=map(int,input().split())
    edge[x-1].append(y-1)
    edge[y-1].append(x-1)
for i in range(q):
    p,x=map(int,input().split())
    a[p-1]+=x
def dfs(node,tmp):
    a[node]+=tmp
    b[node]=1
    for i in edge[node]:
        if b[i]==0:
            dfs(i,a[node])
dfs(0,0)
print(*a)
Buggy python submission (verdict: Runtime Error):
n=int(input())
print(len(set([sorted(i) for i in [input() for i in range(n)]])))

Fixed submission:
def ra(a): #圧縮された要素を非保持
    ll,l=[],1
    for i in range(len(a)-1):
        if a[i]==a[i+1]:
            l+=1
        else:
            ll.append(l)
            l=1
    ll.append(l)
    return ll

n=int(input())
print(sum([i*(i-1)//2 for i in ra(sorted([''.join(sorted(i)) for i in [input() for i in range(n)]]))]))
Buggy python submission (verdict: Runtime Error):
N=int(input()) 
a=[int(input()) for i in range(N)]
b=sorted(a)
n=0
while True:
    if n==a.index(max(a)):
        print(b[-2])
    else:
        print(b[-1])
    n+=1
    if n==N:
        break

Fixed submission:
a=int(input())
print(3*(a**2))
Buggy python submission (verdict: Time Limit Exceeded):
N=int(input()) 
a=[int(input()) for i in range(N)]
b=sorted(a)
n=0
while True:
    if n==a.index(max(a)):
        print(b[-2])
    else:
        print(b[-1])
    n+=1
    if n==N:
        break

Fixed submission:
import sys
input=sys.stdin.readline
N=int(input()) 
a=[int(input()) for i in range(N)]
b=sorted(a)
n=0
c=a.index(max(a))
for n in range(N):
    if n==c:
        print(b[-2])
    else:
        print(b[-1])

Buggy python submission (verdict: Time Limit Exceeded):
N=int(input()) 
a=[int(input()) for i in range(N)]
b=sorted(a)
n=0
while True:
    if n==a.index(max(a)):
        print(b[-2])
    else:
        print(b[-1])
    n+=1
    if n==N:
        break

Fixed submission:
import sys
input=sys.stdin.readline
N=int(input()) 
a=[int(input()) for i in range(N)]
b=sorted(a)
n=0
c=a.index(max(a))
for n in range(N):
    if n==c:
        print(b[-2])
    else:
        print(b[-1])
Buggy python submission (verdict: Runtime Error):
import sys
N=int(input())
a=list(map(int,input().split()))
b,c,d=0,1,0
while True:
    while True:
        e==2**c
        if a[b]%(e)>=e/2:
            d+=1
        b+=1
        if b==N:
            if d%2==1:
                print('No')
                sys.exit()
            else:
                break
    b,d=0,0
    c+=1
    if c==27:
        break
print('Yes')

Fixed submission:
import sys
N=int(input())
a=list(map(int,input().split()))
b,c,d=0,1,0
while True:
    while True:
        if a[b]%(2**c)>=2**(c-1):
            d+=1
        b+=1
        if b==N:
            if d%2==1:
                print('No')
                sys.exit()
            else:
                break
    b,d=0,0
    c+=1
    if c==27:
        break
print('Yes')

Buggy python submission (verdict: Time Limit Exceeded):
import sys
N=int(input())
a=list(map(int,input().split()))
b,c,d=0,1,0
while True:
    while True:
        if a[b]%(2**c)>=2**(c-1):
            d+=1
        b+=1
        if b==N:
            if d%2==1:
                print('No')
                sys.exit()
            else:
                break
    b,d=0,0
    c+=1
    if c==30:
        break
print('Yes')

Fixed submission:
import sys
N=int(input())
a=list(map(int,input().split()))
b,c,d=0,1,0
while True:
    while True:
        if a[b]%(2**c)>=2**(c-1):
            d+=1
        b+=1
        if b==N:
            if d%2==1:
                print('No')
                sys.exit()
            else:
                break
    b,d=0,0
    c+=1
    if c==27:
        break
print('Yes')
Buggy python submission (verdict: Runtime Error):
a=list(map(int,input().sprit()))
print(min(a[0]*a[1],a[2]))

Fixed submission:
a=list(map(int,input().split()))
print(min(a[0]*a[1],a[2]))

Buggy python submission (verdict: Runtime Error):
a=list(map(int,input.split()))
print(min(a[0]*a[1],a[2]))


Fixed submission:
a=list(map(int,input().split()))
print(min(a[0]*a[1],a[2]))

Buggy python submission (verdict: Runtime Error):
a=list(map(int,input.sprit()))
print(min(a[0]*a[1],a[2]))

Fixed submission:
a=list(map(int,input().split()))
print(min(a[0]*a[1],a[2]))
Buggy python submission (verdict: Time Limit Exceeded):
l,r=map(int,input().split())
if l-r>=2019:
    print(0)
    exit()
ans=2020
for i in range(l,r+1):
    for j in range(i+1,r+1):
        i,j=i%2019,j%2019
        ans=min((i*j)%2019,ans)
print(ans)

Fixed submission:
l,r=map(int,input().split())
if r-l>=2019:
    print(0)
    exit()
ans=2020
for i in range(l,r+1):
    for j in range(i+1,r+1):
        ans=min((i*j)%2019,ans)
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
l,r=map(int,input().split())
if l-r>=2019:
    print(0)
    exit()
ans=2020
for i in range(l,r+1):
    for j in range(i+1,r+1):
        ans=min((i*j)%2019,ans)
print(ans)

Fixed submission:
l,r=map(int,input().split())
if r-l>=2019:
    print(0)
    exit()
ans=2020
for i in range(l,r+1):
    for j in range(i+1,r+1):
        ans=min((i*j)%2019,ans)
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
l,r=map(int,input().split())
if l-r>=2019:
    print(0)
    exit()
ans=2020
for i in range(l,r+1):
    for j in range(i+1,r+1):
        ans=min((i*j)%2019,ans)
print(ans)

Fixed submission:
l,r=map(int,input().split())
if r-l>=2019:
    print(0)
    exit()
ans=2020
for i in range(l,r+1):
    for j in range(i+1,r+1):
        ans=min((i*j)%2019,ans)
print(ans)
Buggy python submission (verdict: Runtime Error):
a=int(input())
if a[0]==a[1] or a[1]==a[2] or a[2]==a[3]:
    print('Bad')
else:
    print('Good')

Fixed submission:
a=input()
if a[0]==a[1] or a[1]==a[2] or a[2]==a[3]:
    print('Bad')
else:
    print('Good')
Buggy python submission (verdict: Runtime Error):
a=list(map(int,input().split()))
L=list(map(int,input().split()))
N=a[0]
X=a[1]
l=[0]
n=0
n1=0
while True:
    l.append(L[n]+l[n])
    n=n+1
    if n==N:
        break
while True:
    if l[n1]<=X:
        n1+=1
    else:
        print(n1)
        break

Fixed submission:
a=list(map(int,input().split()))
L=list(map(int,input().split()))
N=a[0]
X=a[1]
l=[0]
n=0
n1=0
while True:
    l.append(L[n]+l[n])
    n=n+1
    if n==N:
        break
while True:
    if l[n1]<=X:
        n1+=1
    else:
        print(n1)
        break
    if n1==N:
        if X>=l[-1]:
            print(n1+1)
            break
        else:            
            print(n1)
            break
Buggy python submission (verdict: Runtime Error):
z=list(map(int,input().split()))
n,m,b=z[0],z[1],[1]
a=[int(input()) for i in range(m)]
if a[0]==1:
    b.append(0)
    c=1
else:
    b.append(1)
    c=0
for i in range(n-1):
    if c<len(a):
        if i+2==a[c]:
            b.append(0)
            c+=1
        else:
            b.append(b[i]+b[i+1])
    else:
        b.append(b[i]+b[i+1])
print(b[-1]%1000000007)

Fixed submission:
z=list(map(int,input().split()))
n,m,b,c=z[0],z[1],[1],0
a=[int(input()) for i in range(m)]
if len(a)>=1:
    if a[0]==1:
        b.append(0)
        c=1
    else:
        b.append(1)
        c=0
else:
    b.append(1)
for i in range(n-1):
    if c<len(a):
        if i+2==a[c]:
            b.append(0)
            c+=1
        else:
            b.append(b[i]+b[i+1])
    else:
        b.append(b[i]+b[i+1])
print(b[-1]%1000000007)
Buggy python submission (verdict: Runtime Error):
N,M=input().strip().split()
l1=[]
while True:
    try:
        l1.append(list(map(int,input().split())))
    except:
        break;
l2=l1[-1]
del l1[-1]
n=0
tate=0
yoko=1
count1=0
count2=0
count3=0
while True:
    while True:        
        sw=str(bin(n))
        del sw[0]
        a=l1[tate][yoko]
        if int(sw[a])==1:
            count1=count1+1
        yoko=yoko+1
        if yoko==l1[tate][0]:
            yoko=1
            if count1%2==l2[tate]:
                count2=count2+1
            break
    tate=tate+1
    if tate==M:
        if count2==N:
            count3=1
        n=n=1
        break
        

Fixed submission:
n,m=map(int,input().split())
a,c=[],0
for i in range(m):
    a.append(list(map(int,input().split())))
p=list(map(int,input().split()))
for i in range(2**n):
    i,b='0'*(n-len(bin(i))+2)+bin(i)[2:],0
    for j in range(m):
        f=0
        for k in range(a[j][0]):
            f+=int(i[a[j][k+1]-1])
        if f%2==p[j]:
            b+=1
    if b==m:
        c+=1
print(c)
Buggy python submission (verdict: Runtime Error):
a=input().split()
N=int(a[0])
K=int(a[1])
count=0
n=1
while True:
    count=count+0.5**math.ceil(math.log2(K)-math.log2(n))/n
    n=n+1
    if n==N:
        break
print(count)

Fixed submission:
import math
n,k=map(int,input().split())
a=0
k=math.log2(k)
for i in range(n):
    a+=2**-max(math.ceil(k-math.log2(i+1)),0)/n
print(a)
Buggy python submission (verdict: Runtime Error):
n=int(input())
edge=[[] for _ in range(n)]
dist=[-1]*n
for i in range(n-1):
    x,y,z=map(int,input().split())
    edge[x-1].append([y-1,z])
    edge[y-1].append([x-1,z])
def dfs(node,d):
    dist[node]=d
    for i in edge[node]:
        if dist[i[0]]==-1:
            dfs(i[0],d+i[1])
dfs(0,0)
print(*[i%2 for i in dist],sep='\n')

Fixed submission:
import sys
sys.setrecursionlimit(10**7)
n=int(input())
edge=[[] for _ in range(n)]
dist=[-1]*n
for i in range(n-1):
    x,y,z=map(int,input().split())
    edge[x-1].append([y-1,z])
    edge[y-1].append([x-1,z])
def dfs(node,d):
    dist[node]=d
    for i in edge[node]:
        if dist[i[0]]==-1:
            dfs(i[0],d+i[1])
dfs(0,0)
print(*[i%2 for i in dist],sep='\n')
Buggy python submission (verdict: Time Limit Exceeded):
r,g,b,n=map(int,input().split())
a=0
for i in range(3001):
    for j in range(3001):
        if (n-(r*i+g*j))%b==0 and (n-(r*i+g*j))>=0:
            a+=1
print(a)

Fixed submission:
r,g,b,n=map(int,input().split())
a=0
for i in range(3001):
    for j in range(3001):
        if (n-(r*i+g*j))%b==0 and (n-(r*i+g*j))>=0:
            a+=1
print(a)
Buggy python submission (verdict: Time Limit Exceeded):
import queue
h,w=map(int,input().split())
a=[input() for _ in range(h)]
q=[]
dist=[[-1 for _ in range(w)]for _ in range(h)]
for i in range(h):
    for j in range(w):
        if a[i][j]=='#':
            q.append([i,j])
            dist[i][j]=0
q=queue.deque(q)
d=[[1,0],[0,1],[-1,0],[0,-1]]
while q:
    y,x=q.popleft()
    for dy,dx in d:
        ny,nx=y+dy,x+dx
        if 0<=ny and ny<h and 0<=nx and nx<w and dist[ny][nx]==-1:
            dist[ny][nx]=dist[y][x]+1
            q.append([ny,nx])
ans=0
for i in range(h):
    for j in range(w):
        ans=max(ans,dist[i][j])
print(ans)

Fixed submission:
import queue
h,w=map(int,input().split())
a=[input() for _ in range(h)]
q=[]
dist=[[-1 for _ in range(w)]for _ in range(h)]
for i in range(h):
    for j in range(w):
        if a[i][j]=='#':
            q.append([i,j])
            dist[i][j]=0
q=queue.deque(q)
d=[[1,0],[0,1],[-1,0],[0,-1]]
while q:
    y,x=q.popleft()
    for dy,dx in d:
        ny,nx=y+dy,x+dx
        if 0<=ny and ny<h and 0<=nx and nx<w and dist[ny][nx]==-1:
            dist[ny][nx]=dist[y][x]+1
            q.append([ny,nx])
ans=0
for i in range(h):
    for j in range(w):
        ans=max(ans,dist[i][j])
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
import math
inf=0
def segtree(a): #RMQ(Range Minimum Query)
    #bi=高さ　bi2=最下段の個数
    global bi 
    bi=math.ceil(math.log2(len(a)))+1
    global bi2
    bi2=2**(bi-1)
    seg=[inf]*(2*bi2-1)
    for i in range(len(a)):
        seg[bi2+i-1]=a[i]
    for i in range(bi-1):
        for j in range(2**(bi-i-2)):
            b=2**(bi-i-2)-1+j
            seg[b]=math.gcd(seg[2*b+1],seg[2*b+2])
    return seg

def seg_update(loc,val): #locの値をvalueに更新
    loc+=bi2-1
    seg[loc]=val
    while True:
        seg[loc]=math.gcd(val,seg[loc])
        if loc==0:
            break
        loc=(loc-1)//2

def seg_find(l,r,tmp=0): #[l,r)の最小値を求める
    a=bi-math.ceil(math.log2(tmp+2))+1
    nl=2**(a-1)*(tmp-(2**(bi-a))+1)
    nr=nl+2**(a-1)
    if nr<=l or nl>=r:
        return inf
    elif l<=nl and nr<=r:
        return seg[tmp]
    else:
        return math.gcd(seg_find(l,r,tmp*2+1),seg_find(l,r,tmp*2+2))

n=int(input())
seg=segtree(list(map(int,input().split())))
ans=0
for i in range(n):
    ans=max(ans,math.gcd(seg_find(0,i),seg_find(i+1,n)))
print(ans)

Fixed submission:
import math
inf=0
def segtree(a): #RMQ(Range Minimum Query)
    #bi=高さ　bi2=最下段の個数
    global bi 
    bi=math.ceil(math.log2(len(a)))+1
    global bi2
    bi2=2**(bi-1)
    seg=[inf]*(2*bi2-1)
    for i in range(len(a)):
        seg[bi2+i-1]=a[i]
    for i in range(bi-1):
        for j in range(2**(bi-i-2)):
            b=2**(bi-i-2)-1+j
            seg[b]=math.gcd(seg[2*b+1],seg[2*b+2])
    return seg

def seg_update(loc,val): #locの値をvalueに更新
    loc+=bi2-1
    seg[loc]=val
    while True:
        seg[loc]=math.gcd(val,seg[loc])
        if loc==0:
            break
        loc=(loc-1)//2

def seg_find(l,r,tmp=0): #[l,r)の最小値を求める
    a=bi-math.ceil(math.log2(tmp+2))+1
    nl=2**(a-1)*(tmp-(2**(bi-a))+1)
    nr=nl+2**(a-1)
    if nr<=l or nl>=r:
        return inf
    elif l<=nl and nr<=r:
        return seg[tmp]
    else:
        return math.gcd(seg_find(l,r,tmp*2+1),seg_find(l,r,tmp*2+2))

n=int(input())
seg=segtree(list(map(int,input().split())))
ans=0
for i in range(n):
    ans=max(ans,math.gcd(seg_find(0,i),seg_find(i+1,n)))
print(ans)
Buggy python submission (verdict: Runtime Error):
n=int(input())
a=list(map(int,input().split()))
count=0
countk=0
saidaiti=0
while True:
    saidaiti=saidaiti+abs(a[count])
    count=count+1
    if a[count]%2==1:
        countk=countk+1
    if count==n:
        break
if countk%2==1:
    saidaiti=saidaiti-2*a[-1]
print(saidaiti)

Fixed submission:
n=int(input())
a=list(map(int,input().split()))
b=[abs(i) for i in a]
print(sum(b)-sum(i<0 for i in a)%2*min(b)*2)
Buggy python submission (verdict: Runtime Error):
b=0
s=list(map(int, input().split()))
if s[0]==s[1]:
    print(2*s[0])
    b=1
elif s[0]>s[1]:
    a=s[0]
    s[0]=s[0]-1
else:
    a=s[1]
    s[1]=s[1]-1
if s[0]==s[1]:
    a=a+s[0]
elif s[0]>s[1]:
    a=a+s[0]
else:
    a=a+s[1]
if b==0:
    print(a)
    

Fixed submission:
a=0
b=0
s=list(map(int, input().split()))
if s[0]==s[1]:
    print(2*s[0])
    b=1
elif s[0]>s[1]:
    a=s[0]
    s[0]=s[0]-1
else:
    a=s[1]
    s[1]=s[1]-1
if s[0]==s[1]:
    a=a+s[0]
elif s[0]>s[1]:
    a=a+s[0]
else:
    a=a+s[1]
if b==0:
    print(a)
Buggy python submission (verdict: Runtime Error):
n=int(input())
a=list(map(int,input().split()))
b=0
for i in range(n):
    if a[i]>=max(a[0:i]):
        b+=1
print(b)

Fixed submission:
n=int(input())
a=list(map(int,input().split()))
b=1
for i in range(n-1):
    if a[i+1]>=max(a[0:i+1]):
        b+=1
print(b)
Buggy python submission (verdict: Runtime Error):
a=[int(input()) for i in range(6)]
if a[4]-a[0]>=a[5]:
  print'Yay!'
  else:
    print ':('

Fixed submission:
a=[int(input()) for i in range(6)]
b=a[4]-a[0]
if a[5]>=b:
    print('Yay!')
else:
    print(':(')

Buggy python submission (verdict: Runtime Error):
a=[int(input()) for i in range(6)]
if (a[4]-a[0]>=a[5]):
  print'Yay!'
  else print ':('

Fixed submission:
a=[int(input()) for i in range(6)]
b=a[4]-a[0]
if a[5]>=b:
    print('Yay!')
else:
    print(':(')

Buggy python submission (verdict: Runtime Error):
a=[int(input()) for i in range(6)]
if a[4]-a[0]>=a[5]:
  print'Yay!'
  else print ':('

Fixed submission:
a=[int(input()) for i in range(6)]
b=a[4]-a[0]
if a[5]>=b:
    print('Yay!')
else:
    print(':(')
Buggy python submission (verdict: Time Limit Exceeded):
import sys
input=sys.stdin.readline
a=list(map(int,input().split()))
n,q,b,c=a[0]-1,a[1],[],[]
s=input()
for i in range(q):
    b.append(list(map(int,input().split())))
for i in range(n):
    if s[i]=='A' and s[i+1]=='C':
        c.append(1)
    else:
        c.append(0)
for i in range(q):
    print(sum(c[b[i][0]-1:b[i][1]-1]))


Fixed submission:
def Csum(a):
    b,c=[0],0
    for i in range(len(a)-1):
        c+=(a[i]=='A' and a[i+1]=='C')
        b.append(c)
    return b
n,q=map(int,input().split())
s=Csum(input())
for i in range(q):
    a,b=map(int,input().split())
    print(s[b-1]-s[a-1])

Buggy python submission (verdict: Time Limit Exceeded):
import sys
input=sys.stdin.readline
a=list(map(int,input().split()))
n,q,b,c=a[0]-1,a[1],[],[]
s=input()
for i in range(q):
    b.append(list(map(int,input().split())))
for i in range(n):
    if s[i]=='A' and s[i+1]=='C':
        c.append(1)
    else:
        c.append(0)
for i in range(q):
    print(sum(c[b[i][0]-1:b[i][1]-1]))

Fixed submission:
def Csum(a):
    b,c=[0],0
    for i in range(len(a)-1):
        c+=(a[i]=='A' and a[i+1]=='C')
        b.append(c)
    return b
n,q=map(int,input().split())
s=Csum(input())
for i in range(q):
    a,b=map(int,input().split())
    print(s[b-1]-s[a-1])

Buggy python submission (verdict: Runtime Error):
a=list(map(int,input().split()))
n,q,b,c=a[0],a[1],[],[]
s=input()
for i in range(q):
    b.append(list(map(int,input().split())))
for i in range(len(s)):
    if s[i]=='A' and s[i+1]=='C':
        c.append(1)
    else:
        c.append(0)
for i in range(q):
    print(sum(c[b[i][0]-1:b[i][1]-1]))

Fixed submission:
def Csum(a):
    b,c=[0],0
    for i in range(len(a)-1):
        c+=(a[i]=='A' and a[i+1]=='C')
        b.append(c)
    return b
n,q=map(int,input().split())
s=Csum(input())
for i in range(q):
    a,b=map(int,input().split())
    print(s[b-1]-s[a-1])

Buggy python submission (verdict: Runtime Error):
a=list(map(int,input().split()))
n,q,b,c=a[0],a[1],[],[]
s=input()
for i in range(q):
    b.append(list(map(int,input().split())))
for i in range(len(s)):
    if s[i]=='A' and s[i+1]=='C':
        c.append(1)
    else:
        c.append(0)
for i in range(q):
    print(sum(c[b[i][0]-1:b[i][1]-1]))

Fixed submission:
def Csum(a):
    b,c=[0],0
    for i in range(len(a)-1):
        c+=(a[i]=='A' and a[i+1]=='C')
        b.append(c)
    return b
n,q=map(int,input().split())
s=Csum(input())
for i in range(q):
    a,b=map(int,input().split())
    print(s[b-1]-s[a-1])
Buggy python submission (verdict: Runtime Error):
a=list(map(int,input().sprit()))
if a[1]%a[0]==0:
    print(a[0]+a[1])
else:
    print(a[1]-a[0])

Fixed submission:
a=list(map(int,input().split()))
if a[1]%a[0]==0:
    print(a[0]+a[1])
else:
    print(a[1]-a[0])
Buggy python submission (verdict: Runtime Error):
import math
from functools import reduce
def g(n):
    return reduce(math.gcd,n)
n=int(input())
print(g(list(map(int,input().split()))))

Fixed submission:
import fractions
from functools import reduce
def g(n):
    return reduce(fractions.gcd,n)
n=int(input())
print(g(list(map(int,input().split()))))
Buggy python submission (verdict: Runtime Error):
n,k=map(int,input().split())
h=list(map(int,input().split()))
dp=[10**9]*n
dp[0]=0
for i in range(n-1):
    for j in range(i+1,min(i+k+1,n)):
        dp[j]=min(dp[j],dp[i]+abs(h[j]-h[i]))
print(dp[-1])

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

Fixed submission:
n,k=map(int,input().split())
h=list(map(int,input().split()))
dp=[10**9]*n
dp[0]=0
for i in range(n-1):
    for j in range(i+1,min(i+k+1,n)):
        dp[j]=min(dp[j],dp[i]+abs(h[j]-h[i]))
print(dp[-1])
Buggy python submission (verdict: Time Limit Exceeded):
n,mw=map(int,input().split())
l=[list(map(int,input().split())) for _ in range(n)]
dp=[[0 for _ in range(mw+1)]for _ in range(n+1)]
for i in range(n):
    w,v=l[i]
    for j in range(mw):
        dp[i+1][j]=max(dp[i+1][j],dp[i][j])
        if j+w<=mw:
            dp[i+1][j+w]=max(dp[i+1][j+w],dp[i][j]+v)
print(max(dp[-1]))

Fixed submission:
n,mw=map(int,input().split())
l=[list(map(int,input().split())) for _ in range(n)]
dp=[[0 for _ in range(mw+1)]for _ in range(n+1)]
for i in range(n):
    w,v=l[i]
    for j in range(mw):
        dp[i+1][j]=max(dp[i+1][j],dp[i][j])
        if j+w<=mw:
            dp[i+1][j+w]=max(dp[i+1][j+w],dp[i][j]+v)
print(max(dp[-1]))
Buggy python submission (verdict: Time Limit Exceeded):
n,mw=map(int,input().split())
l=[list(map(int,input().split())) for _ in range(n)]
dp=[[float('inf') for _ in range(10**5+10)]for _ in range(n+1)]
#dp[i][j]=i個目までの品物を選んだとき、価値をjにする最小の重さ
dp[0][0]=0
for i in range(n):
    w,v=l[i]
    for j in range(10**5+10):
        dp[i+1][j]=min(dp[i+1][j],dp[i][j])
        if j+v<10**5+10:
            dp[i+1][j+v]=min(dp[i+1][j+v],dp[i][j]+w)
    for j in range(10**5+9):
        dp[i+1][-2-j]=min(dp[i+1][-2-j],dp[i+1][-1-j])
for i in range(10**5+10):
    if dp[-1][i]>mw:
        print(i-1)
        break

Fixed submission:
n,mw=map(int,input().split())
l=[list(map(int,input().split())) for _ in range(n)]
dp=[[float('inf') for _ in range(10**5+10)]for _ in range(n+1)]
#dp[i][j]=i個目までの品物を選んだとき、価値をjにする最小の重さ
dp[0][0]=0
for i in range(n):
    w,v=l[i]
    for j in range(10**5+10):
        dp[i+1][j]=min(dp[i+1][j],dp[i][j])
        if j+v<10**5+10:
            dp[i+1][j+v]=min(dp[i+1][j+v],dp[i][j]+w)
    for j in range(10**5+9):
        dp[i+1][-2-j]=min(dp[i+1][-2-j],dp[i+1][-1-j])
for i in range(10**5+10):
    if dp[-1][i]>mw:
        print(i-1)
        break
Buggy python submission (verdict: Runtime Error):
def factorize(n):
    a=[]
    while n%2==0:
        a.append(2)
        n//=2
    f=3
    while f*f<=n:
        if n%f==0:
            a.append(f)
            n//=f
        else:
            f+=2
    if n!=1:
        a.append(n)
    return a
def r(a):
    ll,l=[],1
    for i in range(len(a)-1):
        if a[i]==a[i+1]:
            l+=1
        else:
            ll.append([l,a[i]])
            l=1
    ll.append([l,a[-1]])
    return ll
n,p=map(int,input().split())
a=r(factorize(p))
b=1
for i in a:
    b*=i[1]**(i[0]//n)
print(b)

Fixed submission:
def factorize(n):
    if n==1:
        return [1]
    a=[]
    while n%2==0:
        a.append(2)
        n//=2
    f=3
    while f*f<=n:
        if n%f==0:
            a.append(f)
            n//=f
        else:
            f+=2
    if n!=1:
        a.append(n)
    return a
def r(a):
    ll,l=[],1
    for i in range(len(a)-1):
        if a[i]==a[i+1]:
            l+=1
        else:
            ll.append([l,a[i]])
            l=1
    ll.append([l,a[-1]])
    return ll
n,p=map(int,input().split())
a=r(factorize(p))
b=1
for i in a:
    b*=i[1]**(i[0]//n)
print(b)
Buggy python submission (verdict: Runtime Error):
n=int(input())
if n==22:
    print("Christmas Eve Eve Eve")
if n==23:
    print("Christmas Eve Eve")
if n==24:
    print("Christmas Eve")
if n==25:
    print("
          Christmas")

Fixed submission:
n=int(input())
if n==22:
    print("Christmas Eve Eve Eve")
if n==23:
    print("Christmas Eve Eve")
if n==24:
    print("Christmas Eve")
if n==25:
    print("Christmas")
Buggy python submission (verdict: Runtime Error):
n=int(input())
for i in range(n):
    a.append(input())
if len(a)!=len(set(a)):
    print('No')
    exit()
for i in range(n-1):
    if a[i][-1]!=a[i+1][0]:
        print('No')
        exit()
print('Yes')

Fixed submission:
n=int(input())
a=[]
for i in range(n):
    a.append(input())
if len(a)!=len(set(a)):
    print('No')
    exit()
for i in range(n-1):
    if a[i][-1]!=a[i+1][0]:
        print('No')
        exit()
print('Yes')
Buggy python submission (verdict: Runtime Error):
a=list(map(int(input().split()))
print(a[0]-a[1]+1)

Fixed submission:
a=list(map(int,input().split()))
print(a[0]-a[1]+1)