Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Time Limit Exceeded):
from collections import deque
from pprint import pprint
import sys
import copy
sys.setrecursionlimit(10**7)
def MI(): return map(int, sys.stdin.readline().split())


def bfs(q, sy, sx, ty, tx):
    visited[sy][sx] = 1
    while len(q) != 0:
        y, x, street, ans = q.popleft()
        # print(street)
        for i in range(4):
            ny = y + dy[i]
            nx = x + dx[i]
            route = copy.copy(street)
            if 0 <= ny <= h-1 and 0 <= nx <= w-1 and visited[ny][nx] == 0:
                require[ny][nx] = require[y][x] + 1
                visited[ny][nx] = 1
                route.append([ny, nx])
                q.append([ny, nx, route, ans+direction[i]])
                if ny == ty and nx == tx:  # 探索終了
                    # pprint(require)
                    # pprint(visited)
                    # pprint(route)
                    y, x, route, ans = q.pop()
                    # pprint(ans)
                    return [route,ans]


sx, sy, tx, ty = MI()
sx += 1000
sy += 1000
tx += 1000
ty += 1000
h = 3000
w = 3000
maze = [[0] * w for _ in range(h)]
dx = [-1, 0, 1, 0]
dy = [0, 1, 0, -1]
direction = ['L', 'U', 'R', 'D']


visited = [[0] * w for _ in range(h)]
require = [[0] * w for _ in range(h)]
que = deque()
que.append([sy, sx, [], ''])
route, ans = bfs(que, sy, sx, ty, tx)
# print(route)
# print(ans)


visited = [[0] * w for _ in range(h)]
require = [[0] * w for _ in range(h)]
for y, x in route:
    visited[y][x] = 1
visited[sy][sx] = visited[ty][tx] = 0

que.clear()
que.append([ty, tx, route, ans])
route, ans = bfs(que, ty, tx, sy, sx)
# print(route)
# print(ans)


visited = [[0] * w for _ in range(h)]
require = [[0] * w for _ in range(h)]
for y, x in route:
    visited[y][x] = 1
visited[sy][sx] = 0
visited[ty][tx] = 0

# pprint(visited)
que.clear()
que.append([sy, sx, route, ans])
route, ans = bfs(que, sy, sx, ty, tx)
# print(route)
# print(ans)


visited = [[0] * w for _ in range(h)]
require = [[0] * w for _ in range(h)]
for y, x in route:
    visited[y][x] = 1
visited[sy][sx] = 0
visited[ty][tx] = 0

que.clear()
que.append([ty, tx, route, ans])
route, ans = bfs(que, ty, tx, sy, sx)
# print(route)
print(ans)


visited = [[0] * w for _ in range(h)]
require = [[0] * w for _ in range(h)]
for y, x in route:
    visited[y][x] = 1
visited[sy][sx] = 0
visited[ty][tx] = 0
# pprint(visited)


Fixed submission:
import sys
def MI(): return map(int, sys.stdin.readline().split())
sx, sy, tx, ty = MI()
dx = tx - sx
dy = ty - sy
print('U'*dy+'R'*dx+'D'*dy+'L'*dx+'L'+'U'*(dy+1)+'R'*(dx+1)+'DR'+'D'*(dy+1)+'L'*(dx+1)+'U')
Buggy python submission (verdict: Runtime Error):
import sys
s = list(input())
check =['dream','dreamer','erase','eraser']
while len(s) >= 8:
    if ''.join(s[-5:]) == check[0]:
        print(s)
        for _ in range(5): s.pop()
        continue
    if ''.join(s[-7:]) == check[1]:
        print(s)
        for _ in range(7): s.pop()
        continue
    if ''.join(s[-5:]) == check[2]:
        print(s)
        for _ in range(5): s.pop()
        continue
    if ''.join(s[-6:]) == check[3]:
        print(s)
        for _ in range(6): s.pop()
        continue
    print('No')
    sys.exit()
if ''.join(s) == check[0] or ''.join(s) == check[1] or ''.join(s) == check[2] or ''.join(s) == check[3]:
    print('Yes')
else:
    print('No')


Fixed submission:
import sys
s = list(input())
check =['dream','dreamer','erase','eraser']
while len(s) >= 8:
    if ''.join(s[-5:]) == check[0]:
        for _ in range(5): s.pop()
        continue
    if ''.join(s[-7:]) == check[1]:
        for _ in range(7): s.pop()
        continue
    if ''.join(s[-5:]) == check[2]:
        for _ in range(5): s.pop()
        continue
    if ''.join(s[-6:]) == check[3]:
        for _ in range(6): s.pop()
        continue
    print('NO')
    sys.exit()
if ''.join(s) == check[0] or ''.join(s) == check[1] or ''.join(s) == check[2] or ''.join(s) == check[3]:
    print('YES')
else:
    print('NO')
Buggy python submission (verdict: Runtime Error):
n = int(input())
_ = [list(map(int, input().split())) for _ in range(n)]
_.insert(0, [0, 0, 0])

dt = [_[i + 1][0] - _[i][0] for i in range(n)]
dx = [_[i + 1][1] - _[i][1] for i in range(n)]
dy = [_[i + 1][2] - _[i][2] for i in range(n)]

ans = "Yes"

for i in range(n):
    man_d = abs(dx[i]) + abs(dy[i])
    if not (dt[i] >= man_d and (dt [i]- man_d) % 2 == 0):
        ans = "No"

print(ans)

Fixed submission:
a, b=map(int,input().split())
print("Even" if a * b % 2 == 0 else "Odd")
Buggy python submission (verdict: Runtime Error):
n = int(input())
_ = [list(map(int, input().split())) for _ in range(n)]

dt = [0] * n
dx = [0] * n
dy = [0] * n

for i in range(n):
    dt[i] = _[i + 1][0] - _[i][0]
    dx[i] = _[i + 1][1] - _[i][1]
    dy[i] = _[i + 1][2] - _[i][2]

ans = "Yes"

for i in range(n):
    man_d = abs(dx[i]) + abs(dy[i])
    if not (dt[i] >= man_d and (dt [i]- man_d) % 2 == 0):
        ans = "No"

print(ans)

Fixed submission:
n = int(input())
_ = [list(map(int, input().split())) for _ in range(n)]
_.insert(0, [0, 0, 0])

dt = [_[i + 1][0] - _[i][0] for i in range(n)]
dx = [_[i + 1][1] - _[i][1] for i in range(n)]
dy = [_[i + 1][2] - _[i][2] for i in range(n)]

for i in range(n):
    man_d = abs(dx[i]) + abs(dy[i])
    if dt[i] >= man_d and (dt [i]- man_d) % 2 == 0:
        ans = "Yes"
    else:
        ans = "No"
        break

print(ans)
Buggy python submission (verdict: Runtime Error):
a,b = list(map(int,input().split()))
if( a > b ):
    a,b = b,a
if a > 0 and b > 0:
    print("Positive")
elif a <= 0 and b >= 0:
    print("Zero")
else:
    if (abs(a) - abs(b)) % 2 == 0:
        print("Negative")
    else:
        print("Pisitive")-1 1

Fixed submission:
a,b = list(map(int,input().split()))
if( a > b ):
    a,b = b,a
if a > 0 and b > 0:
    print("Positive")
elif a <= 0 and b >= 0:
    print("Zero")
else:
    if (abs(a) - abs(b)) % 2 == 0:
        print("Negative")
    else:
        print("Positive")
Buggy python submission (verdict: Runtime Error):
import heapq
def main(n,m,c):
    cost_map = dict([(i, [])for i in range(1,n+1)])
    for a, b in c:
        if a <= m:
            cost_map[a].append(b)
        
    hp =[]
    ret = 0
    for i in range(1, m+1):
        costs = cost_map[i]
        [heapq.heappush(hp, -c) for c in costs]
        if(len(hp) > 0):
            c = heapq.heappop(hp)
            ret -= c
    return ret
if __name__ == "__main__":
    n,m = map(lambda x: int(x), input().strip().split())
    c = [ list(map(lambda x: int(x), input().strip().split())) for i in range(n)]
    print(main(n,m,c))

Fixed submission:
import heapq
def main(n,m,c):
    cost_map = dict([(i, [])for i in range(1,m+1)])
    for a, b in c:
        if a <= m:
            cost_map[a].append(b)
        
    hp =[]
    ret = 0
    for i in range(1, m+1):
        costs = cost_map[i]
        [heapq.heappush(hp, -c) for c in costs]
        if(len(hp) > 0):
            c = heapq.heappop(hp)
            ret -= c
    return ret
if __name__ == "__main__":
    n,m = map(lambda x: int(x), input().strip().split())
    c = [ list(map(lambda x: int(x), input().strip().split())) for i in range(n)]
    print(main(n,m,c))
Buggy python submission (verdict: Runtime Error):
n = int(input().rstrip())
a = int(input().rstrip())
b = int(input().rstrip())

if n == 1:
    print("Hello World")
else:
    print(a+b)


Fixed submission:
n = int(input().rstrip())
if n == 1:
    print("Hello World")
else:
    a = int(input().rstrip())
    b = int(input().rstrip())
    print(a+b)

Buggy python submission (verdict: Runtime Error):
N = int(input())
points = [list(map(int, input().split())) for i in range(N)]


def main(N, points):
    points.sort(key=lambda x: x[2], reverse=True)
    for x in range(101):
        for y in range(101):
            # 初期化
            H = -1
            for point in points:
                h = abs(point[0] - x) + abs(point[1] - y) + point[2]
                if point[2] > 0:
                    if H == -1:
                        H = h
                    elif H != h:
                        H = -1
                        break
                else:
                    if H > h:
                        H = -1
                        break
            if H > 0:
                print(x, y, h)
                return


main(N, points)



Fixed submission:
n = int(input().rstrip())
if n == 1:
    print("Hello World")
else:
    a = int(input().rstrip())
    b = int(input().rstrip())
    print(a+b)
Buggy python submission (verdict: Runtime Error):
h,w,d = map(int, input().split())

from collections import defaultdict
G = defaultdict(list)
for i in range(h):
    l = list(map(int, input().split()))
    for n, item in enumerate(l):
        G[item] = [n,i]




# magic is just distance by 1

# if d is 4,
# 1,5,9 or 2,6,10.. make surplus to categorize
# query comes 10^5, so O(1) or O(logN) is limit -> cumulativesum

dp = [0 for i in range(h*w)]
for i in range((h*w)%d+1): # 1,2,...d
    current_place = i+1
    while current_place + d < h*w:
        x,y = G[current_place]
        next_place = current_place + d
        x1,y1 = G[next_place]
        magic = abs(x-x1) + abs(y-y1)
        dp[next_place] = magic + dp[current_place]
        current_place = next_place

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



Fixed submission:
h,w,d = map(int, input().split())

from collections import defaultdict
G = defaultdict(list)
for i in range(h):
    l = list(map(int, input().split()))
    for n, item in enumerate(l):
        G[item] = [n,i]




# magic is just distance by 1

# if d is 4,
# 1,5,9 or 2,6,10.. make surplus to categorize
# query comes 10^5, so O(1) or O(logN) is limit -> cumulativesum

dp = [0 for i in range(h*w+1)]
for i in range(d): # 0,1,2,...d-1
    current_place = i+1
    while current_place + d <= h*w:
        x,y = G[current_place]
        next_place = current_place + d
        x1,y1 = G[next_place]
        magic = abs(x-x1) + abs(y-y1)
        dp[next_place] = magic + dp[current_place]
        current_place = next_place

q = int(input())
for i in range(q):
    l, r = map(int, input().split())
    print(dp[r]-dp[l], flush=True)
Buggy python submission (verdict: Runtime Error):
I = int(input())
L = list(map(int, input().split()))

print(2*I-1, flush=True)

m = 0
for i, item in enumerate(L):
    if abs(item) > abs(m):
        m = item
        m_index = i

for i in range(L):
    print(m_index+1, i+1, flush=True)

if m >= 0:
    for i in range(0, I-1):
        print(i+1, i+2)
else:
    for i in range(I, 0):
        print(i, i-1)


Fixed submission:
I = int(input())
L = list(map(int, input().split()))

print(2*I-1, flush=True)

m = 0
m_index = 0
for i, item in enumerate(L):
    if abs(item) > abs(m):
        m = item
        m_index = i

for i in range(I):
    print(m_index+1, i+1, flush=True)

if m >= 0:
    for i in range(0, I-1):
        print(i+1, i+2)
else:
    for i in range(I, 1, -1):
        print(i, i-1)
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
from collections import Counter
A = []
for i in range(N):
  A.append(int(input()))

sorted_A = sorted(A, reverse=True)  
for a in A:
  tmp_A = list(sorted_A)
  tmp_A.remove(a)
  print(tmp_A[0])

Fixed submission:
N = int(input())
A = []
largest = -1
second_largest = -1
more_than_one_largetst = False

for i in range(N):
  a = int(input())
  A.append(a)
  if largest == a:
    more_than_one_largest = True
  else:
    if largest < a:
      second_largest = largest
      largest = a
      more_than_one_largest = False
    else:
      if second_largest < a:
        second_largest = a
      else:
        pass

for a in A:
  if a != largest:
    print(largest)
  else:
    if more_than_one_largest:
      print(largest)
    else:
      print(second_largest)

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
from collections import Counter
A = []
for i in range(N):
  A.append(int(input()))

sorted_A = sorted(A, reverse=True)  
for a in A:
  tmp_A = list(sorted_A)
  tmp_A.remove(a)
  print(tmp_A[0])

Fixed submission:
N = int(input())
A = []
largest = -1
second_largest = -1
more_than_one_largetst = False

for i in range(N):
  a = int(input())
  A.append(a)
  if largest == a:
    more_than_one_largest = True
  else:
    if largest < a:
      second_largest = largest
      largest = a
      more_than_one_largest = False
    else:
      if second_largest < a:
        second_largest = a
      else:
        pass

for a in A:
  if a != largest:
    print(largest)
  else:
    if more_than_one_largest:
      print(largest)
    else:
      print(second_largest)
Buggy python submission (verdict: Time Limit Exceeded):
N,M = map(int, input().split())

if N==1:
  print(1)
  exit()

A = []
a_prev = None
for i in range(M):
  a_i = int(input())
  if a_prev == a_i:
    print(0)
    exit()
  A.append(a_i)
  a_prev = a_i

N_2 = 1
N_1 = 1  
ans = 0
for i in range(1, N):
  if i in A:
    N_1 = 0
  ans = (N_1 + N_2)%1000000007
  N_2 = N_1
  N_1 = ans
print(ans)


Fixed submission:
N,M = map(int, input().split())

if N==1:
  print(1)
  exit()

A = [0]*N
a_prev = None
for i in range(M):
  a_i = int(input())
  if a_prev == a_i:
    print(0)
    exit()
  A[a_i] = 1  
  a_prev = a_i

N_2 = 1
N_1 = 1  
ans = 0
for i in range(1, N):
  if A[i]==1:
    N_1 = 0
  ans = (N_1 + N_2)%1000000007
  N_2 = N_1
  N_1 = ans
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
N, Q = input().strip().split()
N = int(N)
Q = int(Q)
S = input()

for q_i in range(Q):
  l, r = input().strip().split()
  l = int(l)-1
  r = int(r)  
  subs = S[l:r]
  answer = 0
  for j, c in enumerate(subs):
    if j==0:
      pass
    else:
      if subs[j] == 'C' and subs[j-1] == 'A':
        answer += 1
  print(answer)

Fixed submission:
N, Q = input().strip().split()
N = int(N)
Q = int(Q)
S = input()

counts = [0 for _ in range(len(S))]
for i in range(1, len(S)):
  if S[i] == 'C' and S[i-1] == 'A':
    counts[i] = counts[i-1] + 1
  else:
    counts[i] = counts[i-1]
    
for q_i in range(Q):
  l, r = input().strip().split()
  l = int(l)-1
  r = int(r)-1  
  print(counts[r] - counts[l])

Buggy python submission (verdict: Time Limit Exceeded):
N, Q = input().strip().split()
N = int(N)
Q = int(Q)
S = input()

for q_i in range(Q):
  l, r = input().strip().split()
  l = int(l)-1
  r = int(r)  
  print(S.count("AC", l, r))
 

Fixed submission:
N, Q = input().strip().split()
N = int(N)
Q = int(Q)
S = input()

counts = [0 for _ in range(len(S))]
for i in range(1, len(S)):
  if S[i] == 'C' and S[i-1] == 'A':
    counts[i] = counts[i-1] + 1
  else:
    counts[i] = counts[i-1]
    
for q_i in range(Q):
  l, r = input().strip().split()
  l = int(l)-1
  r = int(r)-1  
  print(counts[r] - counts[l])
Buggy python submission (verdict: Time Limit Exceeded):
S = list(map(str, input()))
len_S_orig = len(S)
while True:
  #print('-----')
  #print(S)
  i = 1
  while i<= len(S)-1:
    #print(i)
    if S[i-1] != S[i]:
      S[i-1] = 'x'
      S[i] = 'x'
      i += 2
    else:
      i += 1
      pass

  # del all 'x's from the list 
  len_S_before = len(S)
  #print(S)
  S = [si for si in S if si != 'x']
  len_S_after = len(S)
  #print(S)
  if len_S_before == len_S_after:
    break
  
print(len_S_orig - len(S))

Fixed submission:
S = list(map(str, input()))
num_0 = S.count('0')
num_1 = S.count('1')
print(min(num_0, num_1)*2)
Buggy python submission (verdict: Runtime Error):
n = input()
print(n.replace('1', '_').replace('9', '1').replace('_', '9')

Fixed submission:
n = input()
print(n.replace('1', '_').replace('9', '1').replace('_', '9'))
Buggy python submission (verdict: Runtime Error):
s = [int x for x in input().split()]
max_int = s.pop(s.index(max(s)))
print(max_int * 10 + sum(s))

Fixed submission:
s = [int(x) for x in input().split()]
max_int = s.pop(s.index(max(s)))
print(max_int * 10 + sum(s))
Buggy python submission (verdict: Runtime Error):
S = input()
K = int(input())

if set(S[:K]) == '1':
  print(1)
else:
  idx = 0
  while True:
    if S[idx] != '1':
      print(S[idx])
      exit()
    idx+=1

Fixed submission:
S = str(input())
K = int(input())

if len(S) == 1:
  print(S)
  exit()

if set(S[:K]) == set(['1']):
  print(1)
  exit()
else:
  for idx in range(K):
    if S[idx] != '1':
      print(S[idx])
      exit()
Buggy python submission (verdict: Runtime Error):
N, K = map(int, input())
if N%K == 0:
  print(0)
else:
  print(1)
  

Fixed submission:
N, K = map(int, input().split())
if N%K == 0:
  print(0)
else:
  print(1)
Buggy python submission (verdict: Runtime Error):
C1 = input()
C2 = input()
C3 = input()
print(C[0]+C[1]+C[2])

Fixed submission:
C1 = input()
C2 = input()
C3 = input()
print(C1[0]+C2[1]+C3[2])
Buggy python submission (verdict: Runtime Error):
N = int(input())
S = [int(x) for x in input().split()]
if 'Y' in S:
  print("Four")
else:
  print("Three")
  

Fixed submission:
N = int(input())
S = [x for x in input().split()]
if 'Y' in S:
  print("Four")
else:
  print("Three")
Buggy python submission (verdict: Runtime Error):
N,A,B=map(int, input().split())
print(min(N*A, B)

Fixed submission:
N,A,B=map(int, input().split())
print(min(N*A, B))
Buggy python submission (verdict: Runtime Error):
R = int(input())
G = int(intpu())
print(2*G-R)

Fixed submission:
R = int(input())
G = int(input())
print(2*G-R)
Buggy python submission (verdict: Runtime Error):
n,m=map(int, input())
print((n-1)*(m-1))

Fixed submission:
n,m=map(int, input().split())
print((n-1)*(m-1))
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A = []
for i in range(N):
  A.append(int(input()))

visited = [0]
steps = 0

while steps<N:
  curr_i = visited[-1]
  curr_val = A[curr_i]
  if curr_i == 1:
    print(steps)
    exit()
  else:
    next_i = curr_val - 1
    if next_i in visited:
      print(-1)
      exit()
    else:
      steps+=1
      visited.append(curr_val -1)
print(-1)


Fixed submission:
N = int(input())
A = []
for i in range(N):
  A.append(int(input()))

visited = [0]
steps = 0

while steps<N:
  curr_i = visited[-1]
  curr_val = A[curr_i]
  if curr_i == 1:
    print(steps)
    exit()
  else:
    steps+=1
    visited.append(curr_val -1)
print(-1)
Buggy python submission (verdict: Runtime Error):
x = int(input())

s = x//11

if 11*s == x:
  print(s*2)
elif x <= 11*s + 6:
  print(s*2+1)
else:
  print(S*2+2)


Fixed submission:
x = int(input())
 
s = x//11
 
if 11*s == x:
  print(s*2)
elif x <= 11*s + 6:
  print(s*2+1)
else:
  print(s*2+2)
Buggy python submission (verdict: Runtime Error):
N=int(input())
S=input()
x = 0
max_x = 0
for s_i in S:
  if s_i = "I":
    x += 1
  else:
    x -= 1
  max_x = max(max_x, x)
print(max_x)

Fixed submission:
N=int(input())
S=input()
x = 0
max_x = 0
for s_i in S:
  if s_i == "I":
    x += 1
  else:
    x -= 1
  max_x = max(max_x, x)
print(max_x)
Buggy python submission (verdict: Runtime Error):
S = dict()
S['a'] = list(input())[::-1]
S['b'] = list(input())[::-1]
S['c'] = list(input())[::-1]
p = 'a'
while S[p]:
  p = S[p].pop()  
print(p.upper())

Fixed submission:
a=int(input())
b=int(input())
h=int(input())
print(int((a+b)*h/2))
Buggy python submission (verdict: Runtime Error):
S = dict()
S['a'] = list(input())[::-1]
S['b'] = list(input())[::-1]
S['c'] = list(input())[::-1]
p = 'a'
while S[]:
  p = S[p].pop()  
print(player.upper())

Fixed submission:
Sa=list(input())
Sb=list(input())
Sc=list(input())
S = [Sa, Sb, Sc]
Ans = ["A", "B", "C"]
idx = ['a', 'b', 'c']
p = 'a'

def take_turn(i):
  if len(S[i])==0:
    print(Ans[i])
    exit()
  else:
    p = S[i].pop(0)
    return p
    
while True:
  p = take_turn(idx.index(p))

Buggy python submission (verdict: Runtime Error):
S = dict()
S['a'] = list(input())[::-1]
S['b'] = list(input())[::-1]
S['c'] = list(input())[::-1]
 p = 'a'
while S[]:
  p = S[p].pop()  
print(player.upper())

Fixed submission:
Sa=list(input())
Sb=list(input())
Sc=list(input())
S = [Sa, Sb, Sc]
Ans = ["A", "B", "C"]
idx = ['a', 'b', 'c']
p = 'a'

def take_turn(i):
  if len(S[i])==0:
    print(Ans[i])
    exit()
  else:
    p = S[i].pop(0)
    return p
    
while True:
  p = take_turn(idx.index(p))
Buggy python submission (verdict: Time Limit Exceeded):
N,M = map(int, input().split())
P = []
Y = []
O = [[] for i in range(N)]

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

for o in O:
    o.sort()

for i,p in enumerate(P):
    s = (6 - len(str(p))) * "0"
    s += str(p)
    s += (6 - len(str((O[p-1].index(Y[i])) + 1))) * "0"
    s += str((O[p-1].index(Y[i])) + 1)
    print( s )

Fixed submission:
N,M = map(int, input().split())
O = []

for i in range(M):
    p,y = map(int, input().split())
    O.append([i+1, p, y])
O.sort(key=lambda x:x[2])
count=[0 for i in range(N)]

ans = []
for o in O:
    count[o[1]-1]+=1
    ans.append([o[0], o[1], count[o[1]-1]])
ans.sort(key=lambda x:x[0])

for v in ans:
    a1 = str(v[1])
    s = (6 - len(a1)) * "0"
    s += a1
    a2 = str(v[2])
    s += (6 - len(a2)) * "0"
    s += a2
    print( s )

Buggy python submission (verdict: Time Limit Exceeded):
N,M = map(int, input().split())
P = []
Y = []
O = [[] for i in range(N)]

for i in range(M):
    p,y = map(int, input().split())
    P.append(p)
    Y.append(y)
    O[p-1].append(y)
    O[p-1].sort()

for i,p in enumerate(P):
    s = (6 - len(str(p))) * "0"
    s += str(p)
    s += (6 - len(str((O[p-1].index(Y[i])) + 1))) * "0"
    s += str((O[p-1].index(Y[i])) + 1)
    print( s )

Fixed submission:
N,M = map(int, input().split())
O = []

for i in range(M):
    p,y = map(int, input().split())
    O.append([i+1, p, y])
O.sort(key=lambda x:x[2])
count=[0 for i in range(N)]

ans = []
for o in O:
    count[o[1]-1]+=1
    ans.append([o[0], o[1], count[o[1]-1]])
ans.sort(key=lambda x:x[0])

for v in ans:
    a1 = str(v[1])
    s = (6 - len(a1)) * "0"
    s += a1
    a2 = str(v[2])
    s += (6 - len(a2)) * "0"
    s += a2
    print( s )

Buggy python submission (verdict: Runtime Error):
N,M = map(int, input().split())
P = []
Y = []
O = [[] for i in range(N)]

for i in range(M):
    p,y = map(int, input().split())
    P.append(p)
    Y.append(y)
    O[p-1].append(y)
    O[p-1].sort()

for i,p in enumerate(P):
    s = (6 - len(str(p))) * "0"
    s += str(p)
    s += (6 - len(str((O[p-1].index(Y[p-1])) + 1))) * "0"
    s += str((O[p-1].index(Y[i])) + 1)
    print( s )

Fixed submission:
N,M = map(int, input().split())
O = []

for i in range(M):
    p,y = map(int, input().split())
    O.append([i+1, p, y])
O.sort(key=lambda x:x[2])
count=[0 for i in range(N)]

ans = []
for o in O:
    count[o[1]-1]+=1
    ans.append([o[0], o[1], count[o[1]-1]])
ans.sort(key=lambda x:x[0])

for v in ans:
    a1 = str(v[1])
    s = (6 - len(a1)) * "0"
    s += a1
    a2 = str(v[2])
    s += (6 - len(a2)) * "0"
    s += a2
    print( s )