Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
from bisect import bisect_left
import heapq
n=int(input())
l=[]
l.append(int(input()))
heapq.heapify(l)
for i in range(n-1):
    a=int(input())
    x=bisect_left(l,a)
    if x==0:
        heapq.heappush(l,a)
    else:
        l[x-1]=a
    print(l)
print(len(l))

Fixed submission:
from bisect import bisect_right,bisect_left
n=int(input())
a=[int(input()) for _ in range(n)]
INF=float('INF')
l=[INF]*n
for i in a[::-1]:
    l[bisect_right(l,i)]=i
print(bisect_left(l,INF))
Buggy python submission (verdict: Time Limit Exceeded):
import sys
from collections import deque
input = sys.stdin.readline

def main():
    n=int(input())
    l=[[] for _ in range(n+1)]
    for _ in range(n-1):
        u,v,w=map(int,input().split())
        l[u].append([v,w])
        l[v].append([u,w])
    ans=[0]*(n+1)
    chk=[(1,0)]
    while chk:
        x,d=chk.pop()
        for v,w in l[x]:
            chk.append((v,d+w))
            if (d+w)%2==0:
                ans[v]=0
            else:
                ans[v]=1
    [print(i) for i in ans[1:]]

if __name__ == '__main__':
    main()

Fixed submission:
import sys
input = sys.stdin.readline

def main():
    n=int(input())
    l=[[] for _ in range(n+1)]
    for _ in range(n-1):
        u,v,w=map(int,input().split())
        u-=1
        v-=1
        l[u].append([v,w])
        l[v].append([u,w])
    ans=[-1]*n
    chk=[(0,0,-1)]
    while chk:
        v,d,p=chk.pop()
        if d%2==0:
            ans[v]=0
        else:
            ans[v]=1
        for u,w in l[v]:
            if u==p:
                continue
            chk.append((u,d+w,v))
    [print(i) for i in ans]

if __name__ == '__main__':
    main()
Buggy python submission (verdict: Time Limit Exceeded):
import sys
import fractions
from functools import reduce
input = sys.stdin.readline

def gcd(*numbers):
    return reduce(fractions.gcd, numbers)

def main():
    n=int(input())
    a=list(map(int,input().split()))
    ans=gcd(*a)
    for i in range(n):
      l=[a[j] for j in range(n) if j!=i]
      ans=max(gcd(*l),ans)
    print(ans)

if __name__ == '__main__':
    main()

Fixed submission:
import sys
from fractions import gcd
input = sys.stdin.readline

def main():
    n=int(input())
    a=list(map(int,input().split()))
    f,b=[0]*(n+2),[0]*(n+2)
    f[1],b[n]=a[0],a[-1]
    for i in range(2,n+1):
        f[i],b[n-i+1]=gcd(a[i-1],f[i-1]),gcd(a[n-i],b[n-i+2])
    ans=0
    for i in range(1,n+1):
      ans=max(ans,gcd(f[i-1],b[i+1]))
    print(ans)
    
if __name__ == '__main__':
    main()

Buggy python submission (verdict: Time Limit Exceeded):
import sys
import fractions
from functools import reduce
input = sys.stdin.readline

def gcd(*numbers):
    return reduce(fractions.gcd, numbers)

def main():
    n=int(input())
    a=list(map(int,input().split()))
    ans=gcd(*a)
    for i in range(n):
      l=[a[j] for j in range(n) if j!=i]
      ans=max(gcd(*l),ans)
    print(ans)

if __name__ == '__main__':
    main()

Fixed submission:
import sys
from fractions import gcd
input = sys.stdin.readline

def main():
    n=int(input())
    a=list(map(int,input().split()))
    f,b=[0]*(n+2),[0]*(n+2)
    f[1],b[n]=a[0],a[-1]
    for i in range(2,n+1):
        f[i],b[n-i+1]=gcd(a[i-1],f[i-1]),gcd(a[n-i],b[n-i+2])
    ans=0
    for i in range(1,n+1):
      ans=max(ans,gcd(f[i-1],b[i+1]))
    print(ans)
    
if __name__ == '__main__':
    main()
Buggy python submission (verdict: Time Limit Exceeded):
import sys
from bisect import bisect_left,bisect_right,insort
#input = sys.stdin.readline

def main():
    n,k=map(int,input().split())
    s=list(input())
    flg,cnt,chk='1',0,[0]    
    for i in range(n):
        if s[i]==flg:
            chk[cnt]+=1
        else:
            flg=str((int(flg)+1)%2)
            cnt+=1
            chk.append(1)
    lng=len(chk)
    if k*2>lng:
        print(n)
    else:
        i=1
        ans=0
        while i+2*(k-1)<=n-1:
            ans=max(ans,sum(chk[i-1:i+2*k]))
            i+=2
        print(ans)

if __name__ == '__main__':
    main()

Fixed submission:
import sys
from itertools import accumulate
from bisect import bisect_left,bisect_right,insort
#input = sys.stdin.readline

def main():
    n,k=map(int,input().split())
    s=list(input())
    flg,cnt,chk='1',0,[0]    
    for i in range(n):
        if s[i]==flg:
            chk[cnt]+=1
        else:
            flg=str((int(flg)+1)%2)
            cnt+=1
            chk.append(1)
    if s[-1]=='0':
        chk.append(0)
    lng=len(chk)
    if k*2>lng:
        print(n)
    else:
        ans=0
        acc=[0]+list(accumulate(chk))
        for i in range(0,len(chk)-2*k,2):
            ans=max(ans,acc[i+2*k+1]-acc[i])
        print(ans)

if __name__ == '__main__':
    main()

Buggy python submission (verdict: Time Limit Exceeded):
import sys
from bisect import bisect_left,bisect_right,insort
#input = sys.stdin.readline

def main():
    n,k=map(int,input().split())
    s=list(input())
    flg,cnt,chk='1',0,[0]    
    for i in range(n):
        if s[i]==flg:
            chk[cnt]+=1
        else:
            flg=str((int(flg)+1)%2)
            cnt+=1
            chk.append(1)
    lng=len(chk)
    if k*2>lng:
        print(n)
    else:
        i=1
        ans=0
        while i+2*(k-1)<=n-1:
            ans=max(ans,sum(chk[i-1:i+2*k]))
            i+=2
        print(ans)

if __name__ == '__main__':
    main()

Fixed submission:
import sys
from itertools import accumulate
from bisect import bisect_left,bisect_right,insort
#input = sys.stdin.readline

def main():
    n,k=map(int,input().split())
    s=list(input())
    flg,cnt,chk='1',0,[0]    
    for i in range(n):
        if s[i]==flg:
            chk[cnt]+=1
        else:
            flg=str((int(flg)+1)%2)
            cnt+=1
            chk.append(1)
    if s[-1]=='0':
        chk.append(0)
    lng=len(chk)
    if k*2>lng:
        print(n)
    else:
        ans=0
        acc=[0]+list(accumulate(chk))
        for i in range(0,len(chk)-2*k,2):
            ans=max(ans,acc[i+2*k+1]-acc[i])
        print(ans)

if __name__ == '__main__':
    main()
Buggy python submission (verdict: Time Limit Exceeded):
import sys
from bisect import bisect_left,bisect_right,insort
input = sys.stdin.readline

def main():
    x,y,z,K=map(int,input().split())
    a=sorted(list(map(int,input().split())))
    b=sorted(list(map(int,input().split())))
    c=sorted(list(map(int,input().split())))
    l,r=a[0]+b[0]+c[0],a[-1]+b[-1]+c[-1]
    while l+1<r:
        ans=0
        m=(l+r)//2
        for i in range(x-1,-1,-1):
            if a[i]>=m:
                ans+=y*z
                continue
            for j in range(y-1,-1,-1):
                if a[i]+b[j]>=m:
                    ans+=z
                    continue
                for k in range(z-1,-1,-1):
                    if a[i]+b[j]+c[k]>=m:
                        ans+=1
                        continue
                    else:
                        break
        if ans>=K:
            l=m
        else:
            r=m
    s=[0]
    for i in range(x-1,-1,-1):
        for j in range(y-1,-1,-1):
            for k in range(z-1,-1,-1):
                if a[i]+b[j]+c[k]>=l:
                    s.append(a[i]+b[j]+c[k])
                    continue
                else:
                    break
    s.sort()
    for i in range(len(s)-1,0,-1):
        print(s[i])

if __name__ == '__main__':
    main()

Fixed submission:
x, y, z, k = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))
 
AB = [a + b for a in A for b in B]
AB.sort(reverse=True)
AB = AB[:k]
 
ABC = [ab + c for ab in AB for c in C]
ABC.sort(reverse=True)
ABC = ABC[:k]
 
print('\n'.join(map(str, ABC)))
Buggy python submission (verdict: Time Limit Exceeded):
def resolve():
    import sys
    from collections import deque
    input = sys.stdin.readline
    n,m = map(int,input().split())
    edgein = [[] for i in range(n)]
    edgeout = [[] for i in range(n)]
    edgecnt=[0]*n
    rootnum=0
    for i in range(n+m-1):
        a,b= map(int,input().split())
        edgein[b-1].append(a-1)
        edgeout[a-1].append(b-1)
    for i in range(n):
        edgecnt[i]=len(edgein[i])
        if edgecnt[i]==0:
            rootnum=i
    chkedge=deque()
    chkedge.append(rootnum)
    while chkedge:
        chk=chkedge.popleft()
        for i in edgeout[chk]:
            edgecnt[i]=max(edgecnt[i],edgecnt[chk]+1)
            chkedge.append(i)
    for i in range(n):
        chk=edgecnt[i]
        if not edgein[i]:
            print(0)
        for j in edgein[i]:
            if edgecnt[j]==chk-1:
                print(j+1)
                break

if __name__ == '__main__':
    resolve()

Fixed submission:
def resolve():
    import sys
    from collections import deque
    input = sys.stdin.readline
    n,m = map(int,input().split())
    edge = [[] for i in range(n)]
    edgecnt=[0]*n
    ans=[0]*n
    for i in range(n+m-1):
        a,b= map(int,input().split())
        edge[a-1].append(b-1)
        edgecnt[b-1]+=1
    for i,j in enumerate(edgecnt):
        if j==0:
            ans[i]=-1
            chkedge=deque([i])
            break
    while chkedge:
        chk=chkedge.popleft()
        for i in edge[chk]:
            edgecnt[i]-=1
            if edgecnt[i]==0:
                ans[i]=chk
                chkedge.append(i)
    for i in ans:print(i+1)

if __name__ == '__main__':
    resolve()
Buggy python submission (verdict: Runtime Error):
from collections import deque
n,k=map(int,input().split())
td=[[0]*2 for _ in range(n)]
for i in range(n):
    t,d=map(int,input().split())
    td[i][0],td[i][1]=d,t
td.sort(reverse=True)
di=set()
sa=deque()
ans=0
for d,t in td[:k]:
    if t in di:
        sa.append(d)
    else:
        di.add(t)
    ans+=d

s=[0]*(k+1)
cnt=len(di)
s[cnt]=ans
for d,t in td[k:]:
    if t in di:
        continue
    else:
        x=sa.popleft()
        ans+=d-x
        di.add(t)
        cnt+=1
        s[cnt]=ans

for i in range(k+1):
    s[i]+=i*i

print(max(s))

Fixed submission:
import heapq
n,k=map(int,input().split())
td=[[0]*2 for _ in range(n)]
for i in range(n):
    t,d=map(int,input().split())
    td[i][0],td[i][1]=d,t
td.sort(reverse=True)
di=set()
sa=[]
heapq.heapify(sa)
ans=0
for d,t in td[:k]:
    if t in di:
        heapq.heappush(sa, d)
    else:
        di.add(t)
    ans+=d

s=[-10**18]*(k+1)
cnt=len(di)
s[cnt]=ans
for d,t in td[k:]:
    if t in di:
        continue
    else:
        if sa:
            x=heapq.heappop(sa)
            ans+=d-x
            di.add(t)
            cnt+=1
            s[cnt]=ans

for i in range(k+1):
    s[i]+=i*i

print(max(s))
Buggy python submission (verdict: Runtime Error):
import numpy as np
n=int(input())
h=np.array(list(map(int,input().split()))+[0]*2)
dp = np.full(n+k, 10 ** 10, dtype=np.int64)
dp[0] = 0
for i in range(1,n):
    dp[i:i+2]=np.minimum(dp[i:i+2],np.abs(h[i:i+2]-h[i-1])+dp[i-1])
print(dp[n-1])

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

Buggy python submission (verdict: Runtime Error):
import numpy as np
n=map(int,input().split())
k=2
h=np.array(list(map(int,input().split()))+[0]*k)
dp = np.full(n+k, 10 ** 10, dtype=np.int64)
dp[0] = 0
for i in range(1,n):
    dp[i:i+k]=np.minimum(dp[i:i+k],np.abs(h[i:i+k]-h[i-1])+dp[i-1])
print(dp[n-1])

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

Buggy python submission (verdict: Runtime Error):
n,k=map(int,input().split())
h=list(map(int,input().split()))
c=[0]*n
for i in range(1,n):
    c[i]=min([cj+abs(h[i]-hj) for cj,hj in zip(c[max(0,i-k):i],h[max(0,i-k):i])])
print(c[-1])

Fixed submission:
n=int(input())
h=list(map(int,input().split()))
c=[0]*n
c[1]=abs(h[0]-h[1])
for i in range(2,n):
    c[i]=min(c[i-2]+abs(h[i]-h[i-2]),c[i-1]+abs(h[i]-h[i-1]))
print(c[n-1])
Buggy python submission (verdict: Runtime Error):
3 1
10 20 10

Fixed submission:
n,k=map(int,input().split())
h=list(map(int,input().split()))
c=[0]*n
for i in range(1,n):
    c[i]=min([cj+abs(h[i]-hj) for cj,hj in zip(c[max(0,i-k):i],h[max(0,i-k):i])])
print(c[-1])

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

Fixed submission:
n,k=map(int,input().split())
h=list(map(int,input().split()))
c=[0]*n
for i in range(1,n):
    c[i]=min([cj+abs(h[i]-hj) for cj,hj in zip(c[max(0,i-k):i],h[max(0,i-k):i])])
print(c[-1])

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

Fixed submission:
n,k=map(int,input().split())
h=list(map(int,input().split()))
c=[0]*n
for i in range(1,n):
    c[i]=min([cj+abs(h[i]-hj) for cj,hj in zip(c[max(0,i-k):i],h[max(0,i-k):i])])
print(c[-1])

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

Fixed submission:
n,k=map(int,input().split())
h=list(map(int,input().split()))
c=[0]*n
for i in range(1,n):
    c[i]=min([cj+abs(h[i]-hj) for cj,hj in zip(c[max(0,i-k):i],h[max(0,i-k):i])])
print(c[-1])
Buggy python submission (verdict: Time Limit Exceeded):
n,W=map(int,input().split())
w,v=[],[]
for i in range(n):
    x,y=map(int,input().split())
    w.append(x)
    v.append(y)
dp=[[0]*(W+1) for _ in range(n+1)]
for i in range(n):
    for j in range(W+1):
        if j-w[i]>=0:
            dp[i+1][j]=max(dp[i][j],dp[i][j-w[i]]+v[i])
        else:
            dp[i+1][j]=dp[i][j]
print(dp[n][W])

Fixed submission:
n,W=map(int,input().split())
dp=[[0]*(W+1) for _ in range(n+1)]
for i in range(1,n+1):
    w,v=map(int,input().split())
    for j in range(1,W+1):
        if j-w<0:
            dp[i][j]=dp[i-1][j]
        else:
            dp[i][j]=max(dp[i-1][j],dp[i-1][j-w]+v)
print(max(dp[n]))

Buggy python submission (verdict: Time Limit Exceeded):
n,W=map(int,input().split())
dp=[[0]*(W+1) for _ in range(n+1)]
for i in range(1,n+1):
    w,v=map(int,input().split())
    for j in range(1,W+1):
        if j-w<0:
            dp[i][j]=dp[i-1][j]
        else:
            dp[i][j]=max(dp[i-1][j],dp[i-1][j-w]+v)
print(max(dp[n]))

Fixed submission:
n,W=map(int,input().split())
dp=[[0]*(W+1) for _ in range(n+1)]
for i in range(1,n+1):
    w,v=map(int,input().split())
    for j in range(1,W+1):
        if j-w<0:
            dp[i][j]=dp[i-1][j]
        else:
            dp[i][j]=max(dp[i-1][j],dp[i-1][j-w]+v)
print(max(dp[n]))

Buggy python submission (verdict: Runtime Error):
n,W=map(int,input().split())
dp=[[0]*(w+1) for _ in range(n+1)]
for i in range(1,n+1):
	w,v=map(int,input().split())
	for j in range(1,W+1):
		if j-w>0:
			dp[i][j]=dp[i-1][j]
		else:
			dp[i][j]=max(dp[i-1][j],dp[i-1][j-w]+v)
print(max(dp[n])

Fixed submission:
n,W=map(int,input().split())
dp=[[0]*(W+1) for _ in range(n+1)]
for i in range(1,n+1):
    w,v=map(int,input().split())
    for j in range(1,W+1):
        if j-w<0:
            dp[i][j]=dp[i-1][j]
        else:
            dp[i][j]=max(dp[i-1][j],dp[i-1][j-w]+v)
print(max(dp[n]))

Buggy python submission (verdict: Runtime Error):
n,W=map(int,input().split())
dp=[[0]*(w+1) for _ in range(n+1)]
for i in range(1,n+1):
	w,v=map(intinput().split())
	for j in range(1,W+1):
		if j-w>0:
			dp[i][j]=dp[i-1][j]
		else:
			dp[i][j]=max(dp[i-1][j],dp[i-1][j-w]+v)
print(max(dp[n])

Fixed submission:
n,W=map(int,input().split())
dp=[[0]*(W+1) for _ in range(n+1)]
for i in range(1,n+1):
    w,v=map(int,input().split())
    for j in range(1,W+1):
        if j-w<0:
            dp[i][j]=dp[i-1][j]
        else:
            dp[i][j]=max(dp[i-1][j],dp[i-1][j-w]+v)
print(max(dp[n]))
Buggy python submission (verdict: Runtime Error):
import sys
input = sys.stdin.readline
import numpy as np

def main():
    n, W = map(int, input().split())
    dp = np.zeros(W + 1, dtype = np.int64)
    for i in range(n):
        w,v=map(int,input().split())
        dp[w:]=np.maximum(dp[w:],dp[:-w]+v)
    print(max(dp))

if __name__ == '__main__':
    main()

Fixed submission:
import sys
input = sys.stdin.readline
import numpy as np
INF=10**9+1
def main():
    n, W = map(int, input().split())
    dp = np.full(n*1000+1,INF,dtype=int)
    dp[0]=0
    for i in range(1,n+1):
        w,v=map(int,input().split())
        dp[v:]=np.minimum(dp[v:],dp[:-v]+w)
    for i in range(len(dp)-1, -1, -1):
        if dp[i] <= W:
            print(i)
            break

if __name__ == '__main__':
    main()
Buggy python submission (verdict: Time Limit Exceeded):
n,k=map(int,input().split())
a=list(map(int,input().split()))
dp=[0]*(2*k+1)
for i in range(k+1):
    for j in a:dp[i+j]|=~dp[i]
if dp[k]:
    print('First')
else:
    print('Second')

Fixed submission:
n,k=map(int,input().split())
a=list(map(int,input().split()))
dp=[False]*(2*k+1)
for i in range(k+1):
    for j in a:dp[i+j]|=not dp[i]
if dp[k]:
    print('First')
else:
    print('Second')

Buggy python submission (verdict: Time Limit Exceeded):
n,k=map(int,input().split())
a=list(map(int,input().split()))
dp=[False]*(k+1)
for i in range(k+1):
    for j in range(n):
        if i-a[j]>=0:
            dp[i]|=not dp[i-a[j]]
if dp[k]:
    print('First')
else:
    print('Second')

Fixed submission:
n,k=map(int,input().split())
a=list(map(int,input().split()))
dp=[False]*(2*k+1)
for i in range(k+1):
    for j in a:dp[i+j]|=not dp[i]
if dp[k]:
    print('First')
else:
    print('Second')
Buggy python submission (verdict: Runtime Error):
def resolve():
    n,m=map(int,input().split())
    py=[[0]*3 for _ in range(m)]
    for i in range(m):
        p,y=map(int,input().split())
        py[i][0],py[i][1],py[i][2]=p,y,i
    py.sort()
    ans=[[''] for _ in range(m)]
    cnt=[0]*(n+1)
    for p,y,i in py:
        cnt[p]+=1
        ans[i]='0'*(6-len(str(p)))+str(p)+'0'*(6-len(str(cnt[p])))+str(cnt[p])
    for i in ans:
        print(i)


if __name__ == '__main__':
    resolve()

Fixed submission:
x,y=map(int,input().split())
print(x+y//2)
Buggy python submission (verdict: Runtime Error):
def resolve():
    n,m=map(int,input().split())
    py=[[0]*3 for _ in range(m)]
    for i in range(m):
        p,y=map(int,input().split())
        py[i][0],py[i][1],py[i][2]=p,y,i
    py.sort()
    ans=[[''] for _ in range(m)]
    cnt=[0]*n
    for p,y,i in py:
        cnt[p]+=1
        ans[i]='0'*(6-len(str(p)))+str(p)+'0'*(6-len(str(cnt[p])))+str(cnt[p])
    for i in ans:
        print(i)


if __name__ == '__main__':
    resolve()

Fixed submission:
def resolve():
    n,m=map(int,input().split())
    py=[[0]*3 for _ in range(m)]
    for i in range(m):
        p,y=map(int,input().split())
        py[i][0],py[i][1],py[i][2]=p,y,i
    py.sort()
    ans=[[''] for _ in range(m)]
    cnt=[0]*(n+1)
    for p,y,i in py:
        cnt[p]+=1
        ans[i]='0'*(6-len(str(p)))+str(p)+'0'*(6-len(str(cnt[p])))+str(cnt[p])
    for i in ans:
        print(i)


if __name__ == '__main__':
    resolve()

Buggy python submission (verdict: Runtime Error):
n,m=map(int,input().split())
py=[[0]*3 for _ in range(m)]
for i in range(m):
    p,y=map(int,input().split())
    py[i][0],py[i][1],py[i][2]=p,y,i
py.sort()
ans=[[''] for _ in range(m)]
cnt=[0]*m
for p,y,i in py:
    cnt[p]+=1
    ans[i]='0'*(6-len(str(p)))+str(p)+'0'*(6-len(str(cnt[p])))+str(cnt[p])
for i in ans:
    print(i)

Fixed submission:
def resolve():
    n,m=map(int,input().split())
    py=[[0]*3 for _ in range(m)]
    for i in range(m):
        p,y=map(int,input().split())
        py[i][0],py[i][1],py[i][2]=p,y,i
    py.sort()
    ans=[[''] for _ in range(m)]
    cnt=[0]*(n+1)
    for p,y,i in py:
        cnt[p]+=1
        ans[i]='0'*(6-len(str(p)))+str(p)+'0'*(6-len(str(cnt[p])))+str(cnt[p])
    for i in ans:
        print(i)


if __name__ == '__main__':
    resolve()

Buggy python submission (verdict: Runtime Error):
n,m=map(int,input().split())
py=[[0]*3 for _ in range(m)]
for i in range(m):
    p,y=map(int,input().split())
    py[i][0],py[i][1],py[i][2]=p,y,i
py.sort()
ans=[[''] for _ in range(m)]
cnt=[0]*m
for p,y,i in py:
    cnt[p]+=1
    ans[i]='0'*(6-len(str(p)))+str(p)+'0'*(6-len(str(cnt[p])))+str(cnt[p])
ans.sort()
for i in ans:
    print(i)

Fixed submission:
def resolve():
    n,m=map(int,input().split())
    py=[[0]*3 for _ in range(m)]
    for i in range(m):
        p,y=map(int,input().split())
        py[i][0],py[i][1],py[i][2]=p,y,i
    py.sort()
    ans=[[''] for _ in range(m)]
    cnt=[0]*(n+1)
    for p,y,i in py:
        cnt[p]+=1
        ans[i]='0'*(6-len(str(p)))+str(p)+'0'*(6-len(str(cnt[p])))+str(cnt[p])
    for i in ans:
        print(i)


if __name__ == '__main__':
    resolve()
Buggy python submission (verdict: Runtime Error):
a,b=map(int,input().split())
if ab%2==0:
  print('NO')
else:
  print('Yes')

Fixed submission:
a,b=map(int,input().split())
if a*b%2==0:
  print('No')
else:
  print('Yes')
Buggy python submission (verdict: Runtime Error):
    w=[input() for _ in range(n)]
    chk=[]
    chk.append(w[0])
    ans='Yes'
    for i in range(1,n):
        if w[i-1][-1]!=w[i][0] or (w[i] in chk):
            ans='No'
            break
        chk.append(w[i])
    print(ans)

if __name__ == '__main__':
    resolve()

Fixed submission:
def resolve():
    n=int(input())
    w=[input() for _ in range(n)]
    chk=[]
    chk.append(w[0])
    ans='Yes'
    for i in range(1,n):
        if w[i-1][-1]!=w[i][0] or (w[i] in chk):
            ans='No'
            break
        chk.append(w[i])
    print(ans)

if __name__ == '__main__':
    resolve()
Buggy python submission (verdict: Runtime Error):
h,w=map(int,input().split())
a=[list(map(int,input().split())) for _ in range(h)]
ans=[]
for i in range(h):
    for j in range(w-1):
        if a[i][j]%2==1:
            a[i][j+1]+=1
            ans.append([i+1,j+1,i+1,j+2])
for i in range(h-1):
    if a[i][j]==1:
        a[i+1][j]+=1
        ans.append([i+1,j+1,i+2,j+1])
print(len(ans))
for i in ans:
    print(*i)

Fixed submission:
h,w=map(int,input().split())
a=[list(map(int,input().split())) for _ in range(h)]
ans=[]
for i in range(h):
    for j in range(w-1):
        if a[i][j]%2==1:
            a[i][j+1]+=1
            ans.append([i+1,j+1,i+1,j+2])
for i in range(h-1):
    if a[i][w-1]%2==1:
        a[i+1][w-1]+=1
        ans.append([i+1,w,i+2,w])
print(len(ans))
for i in ans:
    print(*i)

Buggy python submission (verdict: Runtime Error):
h,w=map(int,input().split())
a=[list(map(lambda x:int(x)%2,input().split())) for _ in range(h)]
maxnum=sum(sum(a))//2
ans=[]
bx,by,cnt=0,0,0
if a[0][0]==0:
    flg=0#0はスタートを探しモード
else:
    flg=1
for i in range(1,h*w):
    if (i//w)%2==0:
        x,y=i%w,(i//w)%2
    else:
        x,y=w-1-i%w,(i//w)%2
    if flg==1:
        a[y][x]=(a[y][x]+1)%2
        ans.append([by,bx,y,x])
        cnt+=1
    if maxnum==cnt:
        break
    flg=a[y][x]
    bx,by=x,y
print(len(ans))
for a,b,c,d in ans:
    print(a+1,b+1,c+1,d+1)

Fixed submission:
h,w=map(int,input().split())
a=[list(map(int,input().split())) for _ in range(h)]
ans=[]
for i in range(h):
    for j in range(w-1):
        if a[i][j]%2==1:
            a[i][j+1]+=1
            ans.append([i+1,j+1,i+1,j+2])
for i in range(h-1):
    if a[i][w-1]%2==1:
        a[i+1][w-1]+=1
        ans.append([i+1,w,i+2,w])
print(len(ans))
for i in ans:
    print(*i)