Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
N,K,S=[int(i) for i in input().split()]
res=[S%10**9+1]*N
for i in range(K):
    res[i]=S
print(*res)

N, K, S = map(int, input().split())


Fixed submission:
N,K,S=[int(i) for i in input().split()]
res=[S%10**9+1]*N
for i in range(K):
    res[i]=S
print(*res)

Buggy python submission (verdict: Runtime Error):
N,K,S=[int(i) for i in input().split()]
res=[10**9-1]*N
for i in range(K):
    res[i]=S
print(*res)

N, K, S = map(int, input().split())


Fixed submission:
N,K,S=[int(i) for i in input().split()]
res=[S%10**9+1]*N
for i in range(K):
    res[i]=S
print(*res)

Buggy python submission (verdict: Runtime Error):
N,K,S=[int(i) for i in input().split()]
res=[10**9]*N
for i in range(K+1):
    res[i]=S
print(res)


Fixed submission:
N,K,S=[int(i) for i in input().split()]
res=[S%10**9+1]*N
for i in range(K):
    res[i]=S
print(*res)
Buggy python submission (verdict: Runtime Error):
from collections import deque

H,W=[int(i) for i in input().split()]
# c=[[i for i in input().split()] for _ in range(h)]
C=list(input() for _ in range(H))
C=list(list(i) for i in C) #visited_listを用いずに壁にしていく方法ではリスト化が必要

def bfs(maze,s1,s2,g1,g2):
    for y in range(H):
        for x in range(W):
            if maze[y][x]!='#':
                maze[y][x]=10**9

    maze[s1][s2]=0
    que=deque([[s1,s2]])
    while que:
        y,x=que.popleft()
        for i,j in [(1,0),(0,1),(-1,0),(0,-1)]:
            nexty,nextx=y+i,x+j
            if nexty >= 0 and nexty < H and nextx >= 0 and nextx < W:
                dist=maze[nexty][nextx]
                if dist!='#':
                    if dist>maze[y][x]+1:
                        maze[nexty][nextx]=maze[y][x]+1
                        que.append([nexty,nextx])
    return maze[g1][g2]

ans=0
for s1,c_w in enumerate(C):
    for s2,c in enumerate(c_w):
        if C[s1][s2]!="#":
            for g1,c_w in enumerate(C):
                for g2,c in enumerate(c_w):
                    if C[g1][g2]!="#":
                        temp=bfs(C,s1,s2,g1,g2)
                        ans=max(temp,ans)
print(ans)


Fixed submission:
z="ABCDEFGHIJKLMNOPQRSTUVWXYZ".lower()
c=input()
print(z[z.find(c)+1])
Buggy python submission (verdict: Runtime Error):
import itertools

N=int(input())
P=[int(i) for i in input().split()]
Q=[int(i) for i in input().split()]

D=list(range(1,N+1))
dict=[]

for i,j in enumerate(itertools.permutations(D)):
    P,Q,j=list([*P]),list([*Q]),list([*j])
    if j==P:
        p=i
    if j==Q:
        q=i
print(abs(p-q))

Fixed submission:
import itertools

N=int(input())
P=[int(i) for i in input().split()]
Q=[int(i) for i in input().split()]

D=list(range(1,N+1))
dict=[]

for i,j in enumerate(itertools.permutations(D)):
    j=list(j)
    if j==P:
        p=i
    if j==Q:
        q=i
print(abs(p-q))

Buggy python submission (verdict: Runtime Error):
import itertools

N=int(input())
P=[int(i) for i in input().split()]
Q=[int(i) for i in input().split()]

D=list(range(1,N+1))
dict=[]

for i,j in enumerate(itertools.permutations(D)):
    P,Q,j=[*P],[*Q],[*j]
    if j==P:
        p=i
    if j==Q:
        q=i
print(abs(p-q))

Fixed submission:
import itertools

N=int(input())
P=[int(i) for i in input().split()]
Q=[int(i) for i in input().split()]

D=list(range(1,N+1))
dict=[]

for i,j in enumerate(itertools.permutations(D)):
    j=list(j)
    if j==P:
        p=i
    if j==Q:
        q=i
print(abs(p-q))
Buggy python submission (verdict: Time Limit Exceeded):
N,K=[int(i) for i in input().split()]
R,S,P=[int(i) for i in input().split()]
T=list(input())
M={"r":P,"s":R,"p":S}

done=[]
point=0
for i in range(K):
    temp=T.pop(0)
    point+=M[temp]
    done.append(temp)

# print(T)
# print(done)

while T:
    temp=T.pop(0)
    back=done.pop(0)
    # print(temp,back)
    if temp!=back:
        point+=M[temp]
        done.append(temp)
    else:
        done.append('u')

print(point)


Fixed submission:
N,K=[int(i) for i in input().split()]
R,S,P=[int(i) for i in input().split()]
T=list(input())
M={"r":P,"s":R,"p":S}

done=[]
point=0
for i in range(K):
    temp=T[i]
    point+=M[temp]
    done.append(temp)

# print(T)
# print(done)

for j in range(K,N):
    temp=T[j]
    back=done[j-K]
    # print(temp,back)
    if temp!=back:
        point+=M[temp]
        done.append(temp)
    else:
        done.append('u')

print(point)
Buggy python submission (verdict: Runtime Error):
import math
n,a,b=map(int,input().split())


def dfs(n,a,b,count):
    if not (b-a)%2:
        return (b-a)//2
    if a==1:
        return math.ceil(b//2)+count
    if b==n:
        return math.ceil((n-a)//2)+count
    if n-b<a:
        return dfs(n,a+1,b+1,count+1)
    if n-b>=a:
        return dfs(n,a-1,b-1,count+1)
print(dfs(n,a,b,0))

Fixed submission:
n,a,b=map(int,input().split())

a_length=a-1
b_length=n-b

if not (b-a)%2:
    print((b-a)//2)
elif b_length>=a_length:
    print(a+(b-a-1)//2)
elif b_length<a_length:
    print(n-b+1+(b-a-1)//2)
Buggy python submission (verdict: Runtime Error):
import math
print(math.celi(int(input()))-1)


Fixed submission:
import math
print(math.ceil(int(input())/2)-1)

Buggy python submission (verdict: Runtime Error):
import math
print(math.celi(int(input())-1)
      

Fixed submission:
import math
print(math.ceil(int(input())/2)-1)
Buggy python submission (verdict: Time Limit Exceeded):
n,m=map(int,input().split())
a = sorted([int(i) for i in input().split()])[::-1]
ans = 0

while m > 0:
    a[0] = a[0]//2
    m-=1
    for i in range(n-1):
        if a[i] < a[i+1]: a[i],a[i+1] = a[i+1],a[i]
        else: break
print(sum(a))

Fixed submission:
import heapq

n,m=map(int,input().split())
a = sorted([int(i) for i in input().split()])
a = list(map(lambda x: x*(-1), a))
heapq.heapify(a)

while m > 0:
    t = heapq.heappop(a)*(-1)//2
    heapq.heappush(a,-t)
    m-=1
print(-sum(a))

Buggy python submission (verdict: Time Limit Exceeded):
import bisect

n,m=map(int,input().split())
a = sorted([int(i) for i in input().split()])
ans = 0
while m > 0:
    temp = a[-1]//2
    a = a[:-1]
    index=bisect.bisect_left(a,temp)
    a.insert(index,temp)
    m-=1
print(sum(a))

Fixed submission:
import heapq

n,m=map(int,input().split())
a = sorted([int(i) for i in input().split()])
a = list(map(lambda x: x*(-1), a))
heapq.heapify(a)

while m > 0:
    t = heapq.heappop(a)*(-1)//2
    heapq.heappush(a,-t)
    m-=1
print(-sum(a))

Buggy python submission (verdict: Time Limit Exceeded):
n,m=map(int,input().split())
a = sorted([int(i) for i in input().split()])
ans = 0
while m > 0:
    a[-1] = a[-1]//2
    m-=1
    a.sort()
print(sum(a))

Fixed submission:
import heapq

n,m=map(int,input().split())
a = sorted([int(i) for i in input().split()])
a = list(map(lambda x: x*(-1), a))
heapq.heapify(a)

while m > 0:
    t = heapq.heappop(a)*(-1)//2
    heapq.heappush(a,-t)
    m-=1
print(-sum(a))
Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
h=list(map(int,input().split()))
count=0
for i in range(n-1):
    temp=0
    for j in range(n-i-1):
        if h[i+j]>=h[i+j+1]:
            temp+=1
        else: break
    count=max(count,temp)
print(count)


Fixed submission:
import bisect
n=int(input())
h=list(map(int,input().split()))

count=0
temp=0
for i in range(n-1):
    if h[i]>=h[i+1]:
        temp+=1
        count=max(count,temp)
    else:
        temp=0

print(count)

Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
h=list(map(int,input().split()))
count=0
for i in range(n-1):
    temp=0
    for j in range(n-i-1):
        if h[i+j]>=h[i+j+1]:
            temp+=1
        else: break
    count=max(count,temp)
print(count)


Fixed submission:
import bisect
n=int(input())
h=list(map(int,input().split()))

count=0
temp=0
for i in range(n-1):
    if h[i]>=h[i+1]:
        temp+=1
        count=max(count,temp)
    else:
        temp=0

print(count)
Buggy python submission (verdict: Time Limit Exceeded):
import sys
sys.setrecursionlimit(10 ** 6)
n , q = map(int,input().split())
point = [0] * n
edge = [[] for i in range(n)]

for i in range(n-1):
    a,b = map(int, input().split())
    a -= 1
    b -= 1
    edge[a].append(b)
    edge[b].append(a)

for _ in range(q):
    a , b = map(int,input().split())
    point[a-1] += b

def dfs(now, last=-1):
    for nxt in edge[now]:
        if nxt==last: continue
        point[nxt] += point[now]
        dfs(nxt, now)
dfs(0)
print(*point)

Fixed submission:
import sys
sys.setrecursionlimit(10 ** 6)
def input():
    return sys.stdin.readline()[:-1]

n , q = map(int,input().split())
point = [0] * n
edge = [[] for i in range(n)]

for i in range(n-1):
    a,b = map(int, input().split())
    a -= 1
    b -= 1
    edge[a].append(b)
    edge[b].append(a)

for _ in range(q):
    a , b = map(int,input().split())
    point[a-1] += b

def dfs(now, last=-1):
    for nxt in edge[now]:
        if nxt==last: continue
        point[nxt] += point[now]
        dfs(nxt, now)
dfs(0)
print(*point)

Buggy python submission (verdict: Runtime Error):
n,q= [int(i) for i in input().split()]

edge = [[] for i in range(n)]
for i in range(n-1):
    a,b = map(int, input().split())
    a -= 1
    b -= 1
    edge[a].append(b)
    edge[b].append(a)

def dfs(now, last, x):
    global node
    node[now]+=x
    for nxt in edge[now]:
        if nxt == last: continue
        if nxt > now: dfs(nxt, now, x)

node=[0] * (n)
for _ in range(q):
    p,x=[int(i) for i in input().split()]
    dfs(p-1, -1, x)
print(node)
    



Fixed submission:
import sys
sys.setrecursionlimit(10 ** 6)
def input():
    return sys.stdin.readline()[:-1]

n , q = map(int,input().split())
point = [0] * n
edge = [[] for i in range(n)]

for i in range(n-1):
    a,b = map(int, input().split())
    a -= 1
    b -= 1
    edge[a].append(b)
    edge[b].append(a)

for _ in range(q):
    a , b = map(int,input().split())
    point[a-1] += b

def dfs(now, last=-1):
    for nxt in edge[now]:
        if nxt==last: continue
        point[nxt] += point[now]
        dfs(nxt, now)
dfs(0)
print(*point)
Buggy python submission (verdict: Time Limit Exceeded):
n,*a=map(int,open(0).read().split())

for i in range(n):
    temp=a[i]
    b=sorted(a)[::-1]
    if temp!=b[0]:
        print(b[0])
    else:
        print(b[1])


Fixed submission:
n,*a=map(int,open(0).read().split())

b=sorted(a)[::-1]
for i in range(n):
    if a[i]!=b[0]:
        print(b[0])
    else:
        print(b[1])

Buggy python submission (verdict: Time Limit Exceeded):
n,*a=map(int,open(0).read().split())
for i in range(n):
    temp = a[i]
    a[i] = 0
    print(max(a))
    a[i]=temp


Fixed submission:
n,*a=map(int,open(0).read().split())

b=sorted(a)[::-1]
for i in range(n):
    if a[i]!=b[0]:
        print(b[0])
    else:
        print(b[1])

Buggy python submission (verdict: Time Limit Exceeded):
n,*a=map(int,open(0).read().split())
for i in range(n):
    temp = a[i]
    a[i] = 0
    print(max(a))
    a[i]=temp


Fixed submission:
n,*a=map(int,open(0).read().split())

b=sorted(a)[::-1]
for i in range(n):
    if a[i]!=b[0]:
        print(b[0])
    else:
        print(b[1])
Buggy python submission (verdict: Time Limit Exceeded):
l,r=map(int,input().split())
count=2019
for i in range(l,r):
    for j in range(i+1,r+1):
        count=min(count,(i*j)%2019)
        if i*j%2019==0:
            break

print(count)


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

Buggy python submission (verdict: Runtime Error):
l,r=map(int,input().split())
for i in range(l,r):
    for j in range(i+1,r+1):
        count=min(count,(i*j)%2019)
        if i*j%2019==0:
            break

print(count)


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

Buggy python submission (verdict: Runtime Error):
l,r=map(int,input().split())
print(l,r)
for i in range(l,r):
    for j in range(i+1,r+1):
        count=min(count,(i*j)%2019)
        if i*j%2019==0:
            break

print(count)


Fixed submission:
l,r=map(int,input().split())
count=2019
for i in range(l,r):
    for j in range(i+1,r+1):
        count=min(count,(i*j)%2019)
        if i*j%2019==0:
            break
    if i*j%2019==0:
        break
print(count)
Buggy python submission (verdict: Runtime Error):
N = int(input())
a = [int(i) for i in input().split()]
t = sum(a)-2*sum(a[1::2])
b = [t]
for i in range(1,N+1):
    t = 2*a[i-1] - t
    b += [t
print(*b[:N])

Fixed submission:
N = int(input())
a = [int(i) for i in input().split()]

b=[0]*(N+1)
b[0] = sum(a)-2*sum(a[1::2])
for i in range(1,N+1):
    b[i] = 2*a[i-1] - b[i-1]
print(*b[:N])

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
a = [int(i) for i in input().split()]

b=[0]*(N+1)
for b0 in range(2*a[0]+1):
    b[0] = b0
    for i in range(1,N+1):
        b[i] = 2*a[i-1] - b[i-1]
    if b[0] == b[N]: break
print(*b[:N])

Fixed submission:
N = int(input())
a = [int(i) for i in input().split()]

b=[0]*(N+1)
b[0] = sum(a)-2*sum(a[1::2])
for i in range(1,N+1):
    b[i] = 2*a[i-1] - b[i-1]
print(*b[:N])
Buggy python submission (verdict: Runtime Error):
import math
a,b,c,d=map(int,input().split())
x=b-(b//c+b//d-b//(c*d/math.gcd(c,d)))
y=(a-1)-((a-1)//c+(a-1)//d-(a-1)//(c*d/math.gcd(c,d)))

print(int(x-y))

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

def lcm(a, b):
    return a * b // gcd (a, b)

a,b,c,d=map(int,input().split())
b_num=b//c + b//d - b//lcm(d,c)
a_num=(a-1)//c + (a-1)//d - (a-1)//lcm(d,c)

print(b-(a-1)-(b_num-a_num))

Buggy python submission (verdict: Runtime Error):
import math
a,b,c,d=map(int,input().split())
x=b-(b//c+b//d-b//(c*d/math.gcd(c,d)))
y=(a-1)-((a-1)//c+(a-1)//d-(a-1)//(c*d/math.gcd(c,d)))

print(int(x-y))

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

def lcm(a, b):
    return a * b // gcd (a, b)

a,b,c,d=map(int,input().split())
b_num=b//c + b//d - b//lcm(d,c)
a_num=(a-1)//c + (a-1)//d - (a-1)//lcm(d,c)

print(b-(a-1)-(b_num-a_num))

Buggy python submission (verdict: Runtime Error):
import numpy as np
a,b,c,d=map(int,input().split())
ab=np.array(range(a,b+1))
print(np.count_nonzero((ab%c)*(ab%d)))


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

def lcm(a, b):
    return a * b // gcd (a, b)

a,b,c,d=map(int,input().split())
b_num=b//c + b//d - b//lcm(d,c)
a_num=(a-1)//c + (a-1)//d - (a-1)//lcm(d,c)

print(b-(a-1)-(b_num-a_num))

Buggy python submission (verdict: Runtime Error):
import numpy as np
a,b,c,d=map(int,input().split())
ab=np.array(range(a,b+1))
print(np.count_nonzero((ab%c)*(ab%d)))


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

def lcm(a, b):
    return a * b // gcd (a, b)

a,b,c,d=map(int,input().split())
b_num=b//c + b//d - b//lcm(d,c)
a_num=(a-1)//c + (a-1)//d - (a-1)//lcm(d,c)

print(b-(a-1)-(b_num-a_num))

Buggy python submission (verdict: Runtime Error):
import numpy as np
a,b,c,d=map(int,input().split())
ab=np.array(range(a,b+1))
print(np.count_nonzero((ab%c)*(ab%d)))


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

def lcm(a, b):
    return a * b // gcd (a, b)

a,b,c,d=map(int,input().split())
b_num=b//c + b//d - b//lcm(d,c)
a_num=(a-1)//c + (a-1)//d - (a-1)//lcm(d,c)

print(b-(a-1)-(b_num-a_num))
Buggy python submission (verdict: Runtime Error):
N,M=map(int,input().split())
a=list(map(int,open(0).read().split()))

b=[0]*(N+2)
b[0]=1
b[1]=1

for j in range(M):
    b[a[j]]=-1

for i in range(2,N+2):
    if b[i] !=-1:
        if b[i-1]!=-1:
            b[i]+=b[i-1]
        if b[i-2]!=-1:
            b[i]+=b[i-2]
print(b[-2]%(1000000007))

Fixed submission:
N,M=[int(i) for i in input().split()]
a=[int(input()) for _ in range(M)]

b=[0]*(N+2)
b[0]=1
b[1]=1

for j in range(M):
    b[a[j]]=-1

for i in range(2,N+2):
    if b[i] !=-1:
        if b[i-1]!=-1:
            b[i]+=b[i-1]
        if b[i-2]!=-1:
            b[i]+=b[i-2]
print(b[-2]%(1000000007))
Buggy python submission (verdict: Time Limit Exceeded):
import re
n,q=map(int,input().split())
s=input()

a=[0]*(n+1)
for i in range(0,n+1):
    # print(s[0:i])
    a[i]+=len(re.findall("AC",s[0:i]))

for i in range(q):
    l,r=[int(i) for i in input().split()]
    print(a[r]-a[l])

Fixed submission:
import re
n,q=map(int,input().split())
s=input()

a=[0]*(n+1)
for i in range(1,n+1):
    # print(s[i-1:i+1])
    if s[i-1:i+1]=="AC":
        a[i]=a[i-1]+1
    else:
        a[i]=a[i-1]

for i in range(q):
    l,r=[int(i) for i in input().split()]
    print(a[r-1]-a[l-1])

Buggy python submission (verdict: Time Limit Exceeded):
import re
n,q=map(int,input().split())
s=input()

a=[0]*(n+1)
for i in range(0,n+1):
    # print(s[0:i])
    a[i]+=len(re.findall("AC",s[0:i]))

for i in range(q):
    l,r=[int(i) for i in input().split()]
    print(a[r]-a[l])

Fixed submission:
import re
n,q=map(int,input().split())
s=input()

a=[0]*(n+1)
for i in range(1,n+1):
    # print(s[i-1:i+1])
    if s[i-1:i+1]=="AC":
        a[i]=a[i-1]+1
    else:
        a[i]=a[i-1]

for i in range(q):
    l,r=[int(i) for i in input().split()]
    print(a[r-1]-a[l-1])

Buggy python submission (verdict: Time Limit Exceeded):
import re
n,q=map(int,input().split())
s=input()

for i in range(q):
    l,r=[int(i)-1 for i in input().split()]
    string=s[l:r+1]
    ans=re.findall("AC",string)
    print(len(ans))

Fixed submission:
import re
n,q=map(int,input().split())
s=input()

a=[0]*(n+1)
for i in range(1,n+1):
    # print(s[i-1:i+1])
    if s[i-1:i+1]=="AC":
        a[i]=a[i-1]+1
    else:
        a[i]=a[i-1]

for i in range(q):
    l,r=[int(i) for i in input().split()]
    print(a[r-1]-a[l-1])

Buggy python submission (verdict: Time Limit Exceeded):
import re
n,q=map(int,input().split())
s=list(input())

for i in range(q):
    l,r=[int(i)-1 for i in input().split()]
    string="".join(s[l:r+1])
    ans=re.findall("AC",string)
    print(len(ans))

Fixed submission:
import re
n,q=map(int,input().split())
s=input()

a=[0]*(n+1)
for i in range(1,n+1):
    # print(s[i-1:i+1])
    if s[i-1:i+1]=="AC":
        a[i]=a[i-1]+1
    else:
        a[i]=a[i-1]

for i in range(q):
    l,r=[int(i) for i in input().split()]
    print(a[r-1]-a[l-1])

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

count=0
for i in range(q):
    l,r=[int(i)-1 for i in input().split()]
    for j in range(l,r):
        if s[j]=="A":
            if s[j+1]=="C":
                count+=1
    print(count)
    count=0

Fixed submission:
import re
n,q=map(int,input().split())
s=input()

a=[0]*(n+1)
for i in range(1,n+1):
    # print(s[i-1:i+1])
    if s[i-1:i+1]=="AC":
        a[i]=a[i-1]+1
    else:
        a[i]=a[i-1]

for i in range(q):
    l,r=[int(i) for i in input().split()]
    print(a[r-1]-a[l-1])
Buggy python submission (verdict: Runtime Error):
n,m=map(int,input().split())
food=list(range(1,m+1))
for i in range(n):
    k,*a=map(int,input().split())
    food &= set(a)
print(len(food))

Fixed submission:
n,m=map(int,input().split())
food=set(range(1,m+1))
for i in range(n):
    k,*a=map(int,input().split())
    food &= set(a)
print(len(food))
Buggy python submission (verdict: Runtime Error):
N,M=[int(i) for i in input().split()]
PY=[[] for _ in range(N)]
py=[]

for i in range(M):
    p,y=[int(i) for i in input().split()]
    py.append((p,y))
    PY[p-1].append(y)

for i in range(N):
    PY[i].sort()

for i in range(M):
    p,y=py.pop(0)
    #print(PY[p].index(y))
    p_zero=6-len(str(p))
    y_zero=6-len(str(PY[p].index(y)))
    print("0"*p_zero + str(p) + "0"*y_zero + str(PY[p].index(y)+1))


Fixed submission:
N,M=[int(i) for i in input().split()]
PY=[[] for _ in range(N)]
py=[]

for i in range(M):
    p,y=[int(i) for i in input().split()]
    PY[p-1].append((y,i))

ans=[None]*M
for j,py in enumerate(PY): #jが県番号
    py.sort()
    for k,(y,i) in enumerate(py):
        ans[i]=str(j+1).zfill(6) + str(k+1).zfill(6)

print(*ans,sep="\n")

Buggy python submission (verdict: Time Limit Exceeded):
N,M=[int(i) for i in input().split()]
PY=[[] for _ in range(N)]
py=[]

for i in range(M):
    p,y=[int(i) for i in input().split()]
    p-=1
    py.append((p,y))
    PY[p].append(y)
    PY[p]=sorted(PY[p])

for i in range(M):
    p,y=py.pop(0)
    p_zero=6-len(str(p))
    y_zero=6-len(str(PY[p].index(y)))
    print("0"*p_zero + str(p+1) + "0"*y_zero + str(PY[p].index(y)+1))


Fixed submission:
N,M=[int(i) for i in input().split()]
PY=[[] for _ in range(N)]
py=[]

for i in range(M):
    p,y=[int(i) for i in input().split()]
    PY[p-1].append((y,i))

ans=[None]*M
for j,py in enumerate(PY): #jが県番号
    py.sort()
    for k,(y,i) in enumerate(py):
        ans[i]=str(j+1).zfill(6) + str(k+1).zfill(6)

print(*ans,sep="\n")
Buggy python submission (verdict: Runtime Error):
n,m=map(int,input().split())
food=list(range(1,m+1))
for i in range(n):
    k,*a=map(int,input().split())
    food &= set(a)
print(len(food))

Fixed submission:
n,m,x,*a=map(int,open(0).read().split())
map=[0]*(n+1)
for i in a: map[i]=1
print(min(sum(map[0:x]),sum(map[x:n])))
Buggy python submission (verdict: Runtime Error):
n=int(input())
s=[input() for i in range(n)]
m=int(input())
t=[input() for j in range(m)]
l=list(set(s))

esult=max(0,max(s.count(i)-t.count(i) for i in l))
print(result)

Fixed submission:
n=int(input())
s=[input() for i in range(n)]
m=int(input())
t=[input() for j in range(m)]

result=0
for item in s:
    temp=s.count(item)-t.count(item)
    if result<temp:
        result=temp

print(result)
Buggy python submission (verdict: Runtime Error):
from collections import deque
import sys
sys.setrecursionlimit(10 ** 6)
def input():
    return sys.stdin.readline()[:-1]

H,W=[int(i) for i in input().split()]
C=[input() for _ in range(H)]
C=[list(i) for i in C] 

ans = 10**9

visited_list = [[10**9]*W for _ in range(H)]
stack = deque([[0, 0, 0]])
visited_list[0][0] = 0

w_cnt=0
for c in C: w_cnt += c.count(".")

def seek(, visited_list, stack):
    global ans
    flag = 0
    while len(stack) > 0:
        h, w, cnt = stack.pop()
        if h == H-1 and w == W-1 and ans > cnt:
            ans = cnt
            flag = 1
            continue
        for j, k in ([1, 0], [0, 1], [-1, 0], [0, -1]):
            new_h, new_w = h+j, w+k
            if new_h < 0 or new_h >= H or new_w < 0 or new_w >= W:
                continue
            if  [new_h][new_w] != "#" and visited_list[new_h][new_w] > cnt + 1:
                visited_list[new_h][new_w] = cnt + 1
                stack.append([new_h, new_w, cnt+1])
    if flag: 
        ans = w_cnt-(ans+1)
        return ans
    else: return -1

print(seek(C, visited_list, stack))

Fixed submission:
from collections import deque
import sys
sys.setrecursionlimit(10 ** 6)
def input():
    return sys.stdin.readline()[:-1]

H,W=[int(i) for i in input().split()]
C=[input() for _ in range(H)]
C=[list(i) for i in C] 

ans = 10**9

visited_list = [[10**9]*W for _ in range(H)]
stack = deque([[0, 0, 0]])
visited_list[0][0] = 0

w_cnt=0
for c in C: w_cnt += c.count(".")

def dfs(town, visited_list, stack):
    global ans
    flag = 0
    while len(stack) > 0:
        h, w, cnt = stack.pop()
        if h == H-1 and w == W-1 and ans > cnt:
            ans = cnt
            flag = 1
            continue
        for j, k in ([1, 0], [0, 1], [-1, 0], [0, -1]):
            new_h, new_w = h+j, w+k
            if new_h < 0 or new_h >= H or new_w < 0 or new_w >= W:
                continue
            if  town[new_h][new_w] != "#" and visited_list[new_h][new_w] > cnt + 1:
                visited_list[new_h][new_w] = cnt + 1
                stack.append([new_h, new_w, cnt+1])
    if flag: 
        ans = w_cnt-(ans+1)
        return ans
    else: return -1

print(dfs(C, visited_list, stack))