Buggy python submission (verdict: Time Limit Exceeded):
import sys
input = sys.stdin.readline
from collections import defaultdict
N, M = map(int, input().split())
dic = defaultdict(list)
P_X = [None] * M
for _ in range(M):
  p, x = input().split()
  p, x = int(p), int(x)
  P_X[_] = (p, x)
  dic[p].append(x)
for key in dic:
  dic[key].sort()
for i in range(M):
  print(str(P_X[i][0]).zfill(6) + str((dic[P_X[i][0]].index(P_X[i][1]) + 1)).zfill(6))

Fixed submission:
import sys
input = sys.stdin.readline
import bisect as bs
from collections import defaultdict
N, M = map(int, input().split())
dic = defaultdict(list)
P_X = [None] * M
for _ in range(M):
  p, x = input().split()
  p, x = int(p), int(x)
  P_X[_] = (p, x)
  dic[p].append(x)
for key in dic:
  dic[key].sort()
for i in range(M):
  print(str(P_X[i][0]).zfill(6) + str(bs.bisect_left(dic[P_X[i][0]], P_X[i][1]) + 1).zfill(6))

Buggy python submission (verdict: Time Limit Exceeded):
import sys
input = sys.stdin.readline
from collections import defaultdict
N, M = map(int, input().split())
dic = defaultdict(list)
P_X = []
for _ in range(M):
  p, x = map(int, input().split())
  P_X.append((p, x))
  dic[p].append(x)
for key in dic:
  dic[key] = sorted(dic[key])
for i in range(M):
  print(str(P_X[i][0]).zfill(6) + str((dic[P_X[i][0]].index(P_X[i][1]) + 1)).zfill(6))

Fixed submission:
import sys
input = sys.stdin.readline
import bisect as bs
from collections import defaultdict
N, M = map(int, input().split())
dic = defaultdict(list)
P_X = [None] * M
for _ in range(M):
  p, x = input().split()
  p, x = int(p), int(x)
  P_X[_] = (p, x)
  dic[p].append(x)
for key in dic:
  dic[key].sort()
for i in range(M):
  print(str(P_X[i][0]).zfill(6) + str(bs.bisect_left(dic[P_X[i][0]], P_X[i][1]) + 1).zfill(6))

Buggy python submission (verdict: Time Limit Exceeded):
from collections import defaultdict
N, M = map(int, input().split())
dic = defaultdict(list)
P, X = [], []
for _ in range(M):
  p, x = map(int, input().split())
  P.append(p)
  X.append(x)
  dic[p].append(x)
for key in dic:
  dic[key] = sorted(dic[key])
for i in range(M):
  print(str(P[i]).zfill(6) + str((dic[P[i]].index(X[i]) + 1)).zfill(6))
  


Fixed submission:
import sys
input = sys.stdin.readline
import bisect as bs
from collections import defaultdict
N, M = map(int, input().split())
dic = defaultdict(list)
P_X = [None] * M
for _ in range(M):
  p, x = input().split()
  p, x = int(p), int(x)
  P_X[_] = (p, x)
  dic[p].append(x)
for key in dic:
  dic[key].sort()
for i in range(M):
  print(str(P_X[i][0]).zfill(6) + str(bs.bisect_left(dic[P_X[i][0]], P_X[i][1]) + 1).zfill(6))

Buggy python submission (verdict: Time Limit Exceeded):
from collections import defaultdict
N, M = map(int, input().split())
dic = defaultdict(list)
P, X = [], []
for _ in range(M):
  p, x = map(int, input().split())
  P.append(p)
  X.append(x)
  dic[p].append(x)
for key in dic:
  dic[key] = sorted(dic[key])
for i in range(M):
  print(str(P[i]).zfill(6) + str((dic[P[i]].index(X[i]) + 1)).zfill(6))
  


Fixed submission:
import sys
input = sys.stdin.readline
import bisect as bs
from collections import defaultdict
N, M = map(int, input().split())
dic = defaultdict(list)
P_X = [None] * M
for _ in range(M):
  p, x = input().split()
  p, x = int(p), int(x)
  P_X[_] = (p, x)
  dic[p].append(x)
for key in dic:
  dic[key].sort()
for i in range(M):
  print(str(P_X[i][0]).zfill(6) + str(bs.bisect_left(dic[P_X[i][0]], P_X[i][1]) + 1).zfill(6))