Problem:


Score: 300 points

Problem Statement

In Republic of Atcoder, there are N prefectures, and a total of M cities that belong to those prefectures.

City i is established in year Y_i and belongs to Prefecture P_i.

You can assume that there are no multiple cities that are established in the same year.

It is decided to allocate a 12-digit ID number to each city.

If City i is the x-th established city among the cities that belong to Prefecture i, the first six digits of the ID number of City i is P_i, and the last six digits of the ID number is x.

Here, if P_i or x (or both) has less than six digits, zeros are added to the left until it has six digits.

Find the ID numbers for all the cities.

Note that there can be a prefecture with no cities.

Constraints

1 \leq N \leq 10^5

1 \leq M \leq 10^5

1 \leq P_i \leq N

1 \leq Y_i \leq 10^9

Y_i are all different.

All values in input are integers.

Input

Input is given from Standard Input in the following format:

N M
P_1 Y_1
:
P_M Y_M

Output

Print the ID numbers for all the cities, in ascending order of indices (City 1, City 2, ...).

Sample Input 1

2 3
1 32
2 63
1 12

Sample Output 1

000001000002
000002000001
000001000001

As City 1 is the second established city among the cities that belong to Prefecture 1, its ID number is 000001000002.

As City 2 is the first established city among the cities that belong to Prefecture 2, its ID number is 000002000001.

As City 3 is the first established city among the cities that belong to Prefecture 1, its ID number is 000001000001.

Sample Input 2

2 3
2 55
2 77
2 99

Sample Output 2

000002000001
000002000002
000002000003



Sample input:
2 3
1 32
2 63
1 12


Sample output:
000001000002
000002000001
000001000001

Submission status: Time Limit Exceeded

Solution code:
def main():
    from builtins import int, map, list, print
    from collections import defaultdict
    from bisect import bisect_left
    import sys
    sys.setrecursionlimit(10 ** 6)

    input = sys.stdin.readline
    input_list = (lambda: input().rstrip().split())
    input_number = (lambda: int(input()))
    input_number_list = (lambda: list(map(int, input_list())))

    N,M = input_number_list()
    P = []
    Y = []
    city = defaultdict(list)
    for i in range(M):
        p,y = input_number_list()
        P.append(p)
        Y.append(y)
        city[p].insert(bisect_left(city[p],y),y)
    for i in range(M):
        print('{:06}{:06}'.format(P[i],city[P[i]].index(Y[i])+1))
if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
N,M=map(int,input().split())

lists = [[] for _ in range(N)]
items = [list(map(int, input().split())) for _ in range(M)]
for p, y in items:
  lists[p-1].append(y)

for n in range(N):
  lists[n].sort()  

for p, y in items:
  index = lists[p-1].index(y)
  print("{:06g}{:06g}".format(p,index+1))

Submission status: Time Limit Exceeded

Solution code:
N,M=map(int,input().split())

lists = [[] for _ in range(N)]
items = [list(map(int, input().split())) for _ in range(M)]
for p, y in items:
  lists[p-1].append(y)

for n in range(N):
  lists[n].sort()  

for p, y in items:
  index = lists[p-1].index(y)
  f = lambda x: ('0' * (6 - len(str(x))) +  str(x))
  print(f(p) + f(index+1))

Submission status: Time Limit Exceeded

Solution code:
N,M=map(int,input().split())
lists = []
for n in range(N):
  lists.append([])
items = []
for m in range(M):
  p, y = map(int, input().split())
  items.append(tuple([p, y]))
  lists[p-1].append(y)

sorted_lists = []

for l in range(len(lists)):
  sort_list = sorted(lists[l])
  sorted_lists.append(sort_list)

for p, y in items:
  index = sorted_lists[p-1].index(y)
  f = lambda x: ('0' * (6 - len(str(x))) +  str(x))
  print(f(p) + f(index+1))

Submission status: Time Limit Exceeded

Solution code:
n, m = map(int, input().split())
py_dict = dict()
ip_dict = dict()

for i in range(m):
    py_list = list(map(int, input().split()))
    py_list.append(i)
    if py_list[0] in py_dict:
        py_dict[py_list[0]].append(py_list)
    else:
        py_dict[py_list[0]] = [py_list]
    ip_dict[i] = py_list[0]

for item in py_dict:
    tmp_list = py_dict[item]
    tmp_list.sort(key=lambda x: x[1])
    for i in range(len(tmp_list)):
        tmp_list[i].append(i+1)
    tmp_list.sort(key=lambda x: x[2])

for i in range(m):
    p = ip_dict[i]
    t_list = py_dict[p].pop(0)
    b = t_list[3]
    print(str(p).zfill(6) + str(b).zfill(6))

Submission status: Time Limit Exceeded

Solution code:
N, M = map(int, input().split())
PY = [[] for i in range(0, N)]
P = []
Y = []
for i in range(0, M):
    p, y = map(int, input().split())
    P.append(p)
    Y.append(y)
    PY[p-1].append(y)
for i in range(0, N):
    PY[i-1].sort()
for i in range(0, M):
    ans = str(P[i]).zfill(6)+str(PY[P[i]-1].index(Y[i])+1).zfill(6)
    print(ans)

Submission status: Time Limit Exceeded

Solution code:
n, m = map(int, input().split())
pyDic = {}
pyArray = [None] * m
for i in range(m):
    p, y = map(int, input().split())
    pyArray[i] = [p, y]
    if str(p) in pyDic:
        pyDic[str(p)].append(y)
        pyDic[str(p)].sort()
    else:
        pyDic[str(p)] = [y]

for i in range(m):
    print('{:06}'.format(
        pyArray[i][0]) + '{:06}'.format(pyDic[str(pyArray[i][0])].index(pyArray[i][1]) + 1))

Submission status: Time Limit Exceeded

Solution code:
from collections import defaultdict
N, M = map(int, input().split())
PY = []
PYd = defaultdict(list)
for i in range(M):
    x, y = map(int, input().split())
    PYd[x].append(y)
    PY.append((x,y))

for i in PYd.keys():
    PYd[i].sort()

for p,y in PY:
    str_p = str(p).zfill(6)
    index = str(1 + PYd[p].index(y)).zfill(6)
    print(str_p + index)

Submission status: Time Limit Exceeded

Solution code:
def input_int_list():
    return [int(thing) for thing in input().split(" ")]
N,M=input_int_list()
ken_toshi=[input_int_list() for _ in range(M)]
ken_shinotoshi={i+1:sorted([thing[1] for thing in ken_toshi if thing[0]==i+1]) for i in range(N)}

def normalize(num:int):
    return str(num).zfill(6)

for ken,toshi in ken_toshi:
    ans_left=normalize(ken)
    ans_right=normalize(list(ken_shinotoshi[ken]).index(toshi)+1)
    print(ans_left+ans_right)

Submission status: Time Limit Exceeded

Solution code:
n,m = map(int, input().split())

py = []
sorty = [[] for _ in range(n)]
for _ in range(m):
    a= list(map(int, input().split()))
    py.append(a)
    sorty[a[0] - 1].append(a[1])

for i in range(n):
    sorty[i].sort()


for i in range(m):
    k = sorty[py[i][0] - 1].index(py[i][1]) + 1
    kk = str(k).zfill(6)
    pp = str(py[i][0]).zfill(6)
    print(pp + kk)

Submission status: Time Limit Exceeded

Solution code:
# -*- coding: utf-8 -*-

N,M = list(map(int, input().rstrip().split()))
PY_list = [list(map(int, input().rstrip().split())) for i in range(M)]
#-----

# key= int, Number of Prefecture
# value= list, BirthYear of city
pref_dic={}

for p,y in PY_list:
    pref_dic.setdefault(p,[])
    pref_dic[p] += [y]

for k in pref_dic:
    pref_dic[k].sort()

for m in range(M):
    inum_pref = PY_list[m][0]
    inum_city = pref_dic[ inum_pref ].index( PY_list[m][1] ) + 1
    print('{0:06}{1:06}'.format(inum_pref, inum_city))

Submission status: Time Limit Exceeded

Solution code:
from bisect import bisect_left as bl


def f(v):
    v = str(v)
    return '0' * (6 - len(v)) + v


N, M = map(int, input().split())
dic = dict()
PY = []
for i in range(M):
    p, y = map(int, input().split())
    if dic.get(p, False):
        dic[p].append(y)
    else:
        dic[p] = [y]
    PY.append((p, y))

for i in range(1, N + 1):
    if dic.get(i, False):
        dic[i] = sorted(dic[i])

# print('dic', dic, PY)
for i in range(M):
    p, y = PY[i]
    # print('p y', p, y)
    l = dic[p]
    ans = f(p) + f(l.index(y) + 1)
    print(ans)

Submission status: Time Limit Exceeded

Solution code:
n,m = map(int, input().split())
lst = [[] for _ in range(n)]
ly = [[] for _ in range(m)]
for i in range(m):
    p,y = map(int, input().split())
    ly[i] = (p,y)
    lst[p-1].append(y)
for i in range(n):
    lst[i].sort()

# print(ly)
# print(lst)

for i in ly:
    num = lst[i[0]-1].index(i[1])+1
    print(str(i[0]).zfill(6) + str(num).zfill(6))

Submission status: Time Limit Exceeded

Solution code:
N,M=map(int,input().split())
PY=dict()
P=[]
Y=[]
for _ in range(M):
    Pi,Yi=map(int,input().split())
    P.append(Pi)
    Y.append(Yi)
    if((Pi in PY.keys())==False):
        PY[Pi]=[Yi]
    else:
        PY[Pi].append(Yi)

for i in PY.keys():
    PY[i].sort()

for n in range(M):
    print('{:06}{:06}'.format(P[n],(PY[P[n]].index(Y[n]))+1))

Submission status: Time Limit Exceeded

Solution code:

N,M=map(int,input().split())
PY=dict()
P=[]
Y=[]
for _ in range(M):
    Pi,Yi=map(int,input().split())
    P.append(Pi)
    Y.append(Yi)
    if((Pi in PY.keys())==False):
        PY[Pi]=[Yi]
    else:
        PY[Pi].append(Yi)

for i in PY.keys():
    PY[i].sort()

for n in range(M):
    p,y=P[n],Y[n]
    print('{:06}{:06}'.format(p,(PY[p].index(y))+1))

Submission status: Time Limit Exceeded

Solution code:
N,M=map(int,input().split())
PY=dict()
cnt=[]
for _ in range(M):
    P,Y=map(int,input().split())
    tmp=[P,Y]
    if((P in PY.keys())==False):
        cnt.append(tmp)
        PY[P]=[Y]
    else:
        cnt.append(tmp)
        PY[P].append(Y)


for i in PY.keys():
    PY[i].sort()

for n in cnt:
    p,y=n[0],n[1]
    print('{:06}{:06}'.format(p,(PY[p].index(y))+1))

Submission status: Time Limit Exceeded

Solution code:
N,M=map(int,input().split())
PY=dict()
cnt=[]
for _ in range(M):
    P,Y=map(int,input().split())
    tmp=[P,Y]
    if((P in PY.keys())==False):
        cnt.append(tmp)
        PY[P]=[Y]
    else:
        cnt.append(tmp)
        PY[P].append(Y)

for i in PY.keys():
    PY[i].sort()

for n in cnt:
    p,y=n[0],n[1]

    print('{:06}{:06}'.format(p,(PY[p].index(y))+1))

Submission status: Time Limit Exceeded

Solution code:
n,m = map(int,input().split())
ab = []
cost = [[] for _ in range(n+1)]
for _ in range(m):
    a, b = (int(x) for x in input().split())
    ab.append([a, b])
    cost[a].append(b)

check = [0]*(n+1)

#print(cost)
for i,j in ab:
    if check[i] == 0:
        cost[i].sort()
        check[i] = 1
    ID = cost[i].index(j)+1
    i = str(i)
    i = (6-len(i))*'0'+i
    ID = str(ID)
    ID = (6-len(ID))*'0'+ID
    print(i+ID)

Submission status: Time Limit Exceeded

Solution code:
n,m = map(int,input().split())
ab = []
cost = [[] for _ in range(n+1)]
for _ in range(m):
    a, b = (int(x) for x in input().split())
    ab.append([a, b])
    cost[a].append(b)

for i in range(n+1):
    cost[i].sort()

#print(cost)
for i,j in ab:
    ID = cost[i].index(j)+1
    i = str(i)
    i = (6-len(i))*'0'+i
    ID = str(ID)
    ID = (6-len(ID))*'0'+ID
    print(i+ID)

Submission status: Time Limit Exceeded

Solution code:
n,m = map(int,input().split())
ab = []
cost = [[] for _ in range(n+1)]
for _ in range(m):
    a, b = (int(x) for x in input().split())
    ab.append([a, b])
    cost[a].append(b)
    cost[a].sort()

#print(cost)
for i,j in ab:
    ID = cost[i].index(j)+1
    i = str(i)
    i = (6-len(i))*'0'+i
    ID = str(ID)
    ID = (6-len(ID))*'0'+ID
    print(i+ID)

Submission status: Time Limit Exceeded

Solution code:
import copy
n,m = map(int,input().split())
ab = []
for _ in range(m):
    a, b = (int(x) for x in input().split())
    ab.append([a, b])

cp = copy.copy(ab)

cp = sorted(cp, key=lambda x: x[1])

cost = [[] for _ in range(n+1)]

for i,j in cp:
    cost[i].append(j)

for i,j in ab:
    ID = cost[i].index(j)+1
    i = str(i)
    i = (6-len(i))*'0'+i
    ID = str(ID)
    ID = (6-len(ID))*'0'+ID
    print(i+ID)

Submission status: Time Limit Exceeded

Solution code:
import copy

N,M = map(int,input().split())
pref = [[] for i in range(N)]
id = [[]] * M

for i in range(M):
  p,y = map(int,input().split())
  id[i] = [p,y]
  pref[p - 1].append(y)
  #pref[p - 1] = sorted(pref[p - 1])

for i in range(N):
  pref[i] = sorted(pref[i])

for i in range(M):
  p = id[i][0]
  y = id[i][1]
  order = str(pref[p -  1].index(y) + 1)
  city = str(p)
  ID = ""
  ID += "0" * (6 - len(city)) + city + "0" * (6 - len(order)) + order
  print(ID)

Submission status: Time Limit Exceeded

Solution code:
N,M = map(int,input().split())
pref = [[] for i in range(N)]
id = [[]] * M

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

for i in range(M):
  p = id[i][0]
  y = id[i][1]
  order = str(pref[p -  1].index(y) + 1)
  city = str(p)
  ID = ""
  ID += "0" * (6 - len(city)) + city + "0" * (6 - len(order)) + order
  print(ID)

Submission status: Time Limit Exceeded

Solution code:
n, m = map(int, input().split())
city = []
for i in range(m):
    city.append(list(map(int, input().split())))

sortedcity = sorted(city)
cnt = {}
ans = []

for i in range(m):
    pref = sortedcity[i][0]
    year = sortedcity[i][1]
    if pref in cnt:
        cnt[pref].append(year)
    else:
        cnt[pref] = [year]

for i in range(m):
    pref = city[i][0]
    year = city[i][1]
    num = cnt[pref].index(year) + 1
    tmp = str(pref).zfill(6) + str(num).zfill(6)
    ans.append(tmp)
    print(ans[i])

Submission status: Time Limit Exceeded

Solution code:
N, M = map(int, input().split())
P = [0] * M
Y = [0] * M

data = [[] for i in range(N + 1)]

for i in range(M):
    P[i], Y[i] = map(int, input().split())
    data[P[i]].append(Y[i])

for key in set(P):
    data[key].sort()

for i in range(M):
    x = data[P[i]].index(Y[i]) + 1
    id_number = "{:06}{:06}".format(P[i], x)
    print(id_number)

Submission status: Time Limit Exceeded

Solution code:
N, M = map(int, input().split())
P = [0] * M
Y = [0] * M

pref = {}

for i in range(M):
    P[i], Y[i] = map(int, input().split())
    pref.setdefault(P[i], [])
    pref[P[i]].append(Y[i])

for v in pref.values():
    v.sort()

for i in range(M):
    x = pref[P[i]].index(Y[i]) + 1
    id_number = "{:06}{:06}".format(P[i], x)
    print(id_number)

Submission status: Time Limit Exceeded

Solution code:
n,m=map(int,input().split())
data=[]
p=[0]*n
y=[[] for _ in range(n)]
for i in range(m):
    p_i,y_i=map(int,input().split())
    data.append([p_i,y_i])
    p[p_i-1]+=1
    y[p_i-1].append(y_i)
for i in range(n):
    y[i].sort()
for i in range(m):
    ans_p=data[i][0]
    ans_y=y[ans_p-1].index(data[i][1])+1
    ans_p=(str(ans_p)).zfill(6)
    ans_y=(str(ans_y)).zfill(6)
    print(ans_p+ans_y)

Submission status: Time Limit Exceeded

Solution code:
n,m=map(int,input().split())
data=[]
p=[0]*n
y=[[] for _ in range(n)]
q=[]
for i in range(m):
    p_i,y_i=map(int,input().split())
    data.append([p_i,y_i])
    p[p_i-1]+=1
    y[p_i-1].append(y_i)
for i in range(n):
    if p[i]>1:
        y[i].sort()
for i in range(m):
    ans_p=data[i][0]
    ans_y=y[ans_p-1].index(data[i][1])+1
    ans_p=(str(ans_p)).zfill(6)
    ans_y=(str(ans_y)).zfill(6)
    print(ans_p+ans_y)

Submission status: Time Limit Exceeded

Solution code:
n,m=map(int,input().split())
data=[]
p=[0]*n
y=[[] for _ in range(n)]
q=[]
for i in range(m):
    p_i,y_i=map(int,input().split())
    data.append([p_i,y_i])
    p[p_i-1]+=1
    y[p_i-1].append(y_i)
    if p_i-1 not in q:
        q.append(p_i-1)
for i in q:
    y[i].sort()
for i in range(m):
    ans_p=data[i][0]
    ans_y=y[ans_p-1].index(data[i][1])+1
    ans_p=(str(ans_p)).zfill(6)
    ans_y=(str(ans_y)).zfill(6)
    print(ans_p+ans_y)

Submission status: Time Limit Exceeded

Solution code:
n,m=map(int,input().split())
data=[]
p=[0]*n
y=[[] for _ in range(n)]
for i in range(m):
    p_i,y_i=map(int,input().split())
    data.append([p_i,y_i])
    p[p_i-1]+=1
    y[p_i-1].append(y_i)
for i in range(n):
    if p[i]!=0:
        y[i].sort()
for i in range(m):
    ans_p=data[i][0]
    ans_y=y[ans_p-1].index(data[i][1])+1
    ans_p=(str(ans_p)).zfill(6)
    ans_y=(str(ans_y)).zfill(6)
    print(ans_p+ans_y)

Submission status: Time Limit Exceeded

Solution code:
n,m = map(int,input().split())
py = []
for i in range(m):
    p,y = map(int,input().split())
    py.append([p,y])
spy = sorted(py,key=lambda x:x[1])

cnt = [0]*n
id = []
for i in spy:
    p,y = i
    cnt[p-1] += 1
    id.append(str(p).zfill(6)+str(cnt[p-1]).zfill(6))

for i in py:
    index = spy.index(i)
    print(id[index])

Submission status: Time Limit Exceeded

Solution code:
import sys

def main():
    N,M = map(int, input().split())
    PY_input = []
    PY_dict = {}
    for _ in range(M):
        p, y = map(int, sys.stdin.readline().split())
        PY_input.append((p, y))
        PY_dict.setdefault(p, []).append(y)

    for i in PY_dict.values():
        i.sort()

    for p, y in PY_input:
        print("{:06}{:06}".format(p, PY_dict[p].index(y)+1))


if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

Solution code:
import sys

def main():
    N,M = map(int, input().split())
    PY_input = []
    PY = [[] for i in range(N+1)]
    for _ in range(M):
        p, y = map(int, sys.stdin.readline().split())
        PY_input.append((p, y))
        PY[p].append(y)

    for i in PY:
        i.sort()

    for p, y in PY_input:
        print("{:06}{:06}".format(p, PY[p].index(y)+1))


if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

Solution code:
n, m = map(int, input().split())
x = [list(map(int, input().split())) for _ in range(m)]

city = [[] for i in range(n)]
for p, y in x:
   city[p-1].append(y)

city = [sorted(city[i]) for i in range(n)]

for i in range(m):
   tmp = city[x[i][0]-1].index(x[i][1])
   print('{:0>6}{:0>6}'.format(x[i][0], tmp+1))

Submission status: Time Limit Exceeded

Solution code:
n, m = map(int, input().split())

city = [[] for i in range(n)]
x = []
for _ in range(m):
   p, y = map(int, input().split())
   city[p-1].append(y)
   x.append([p, y])

city = [sorted(city[i]) for i in range(n)]

for i in range(m):
   tmp = city[x[i][0]-1].index(x[i][1])
   print('{:0>6}{:0>6}'.format(x[i][0], tmp+1))

Submission status: Time Limit Exceeded

Solution code:
import sys
input = sys.stdin.readline

def main():
    n, m = map(int, input().split())
    ls = [[int(_) for _ in input().split()] for _ in range(m)]
    
    lss = sorted(ls, key=lambda x: x[1])

    dp = [[] for _ in range(n)] 

    for i in range(m):
        dp[lss[i][0] - 1].append(lss[i][1])
    
    for k in range(m):
        th = dp[ls[k][0] - 1].index(ls[k][1]) + 1
        print(str(ls[k][0]).zfill(6) + str(th).zfill(6))

if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
import sys
input = sys.stdin.readline

def main():
    n, m = map(int, input().split())
    ls = [[int(_) for _ in input().split()] for _ in range(m)]
    
    dp = [[] for _ in range(n)] 

    for i in range(m):
        dp[ls[i][0] - 1].append(ls[i][1])
    
    for j in range(n):
        dp[j].sort()

    for k in range(m):
        th = dp[ls[k][0] - 1].index(ls[k][1]) + 1
        print(str(ls[k][0]).zfill(6) + str(th).zfill(6))

if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
import sys
input = sys.stdin.readline

n, m = map(int, input().split())
ls = [[int(_) for _ in input().split()] for _ in range(m)]

dp = [[] for _ in range(n)] 

for i in range(m):
    dp[ls[i][0] - 1].append(ls[i][1])

for j in range(n):
    dp[j].sort()

for k in range(m):
    th = dp[ls[k][0] - 1].index(ls[k][1]) + 1
    print(str(ls[k][0]).zfill(6) + str(th).zfill(6))

Submission status: Time Limit Exceeded

Solution code:
n, m = map(int, input().split())
ls = [[int(_) for _ in input().split()] for _ in range(m)]

dp = [[] for _ in range(n)] 

for i in range(m):
    dp[ls[i][0] - 1].append(ls[i][1])

for j in range(n):
    dp[j].sort()

for k in range(m):
    th = dp[ls[k][0] - 1].index(ls[k][1]) + 1
    print(str(ls[k][0]).zfill(6) + str(th).zfill(6))

Submission status: Time Limit Exceeded

Solution code:
n, m = map(int, input().split())
ls = [[int(_) for _ in input().split()] for _ in range(m)]

dp = [[] for _ in range(n)] 

for i in range(m):
    p = ls[i][0]
    y = ls[i][1]
    dp[p - 1].append(y)

for j in range(n):
    dp[j].sort()

for k in range(m):
    p = ls[k][0]
    y = ls[k][1]
    th = dp[p - 1].index(y) + 1
    print(str(p).zfill(6) + str(th).zfill(6))

Submission status: Time Limit Exceeded

Solution code:
N, M = map(int, input().split())
dic = {i: [] for i in range(1, N + 1)} 
XY_list = [None] * M
for i in range(M):
  X, Y = map(int, input().split())
  dic[X].append(Y)
  XY_list[i] = (X, Y)
for j in range(1, N + 1):
  dic[j].sort()
for x in XY_list:
  print(str(x[0]).zfill(6)+str(dic[x[0]].index(x[1]) + 1).zfill(6))

Submission status: Time Limit Exceeded

Solution code:
N, M = map(int, input().split())
City_list = [[] for i in range(N)]
X_list = [None] * M
Y_list = [None] * M
for i in range(M):
  X, Y = map(int, input().split())
  City_list[X - 1].append(Y)
  X_list[i] = X
  Y_list[i] = Y
for j in range(N):
  City_list[j].sort()
for x, y in zip(X_list, Y_list):
  print(str(x).zfill(6)+str(City_list[x - 1].index(y) + 1).zfill(6))

Submission status: Time Limit Exceeded

Solution code:
N, M = map(int, input().split())
dic = {i: [] for i in range(1, N + 1)} 
X_list = [None] * M
Y_list = [None] * M
for i in range(M):
  X, Y = map(int, input().split())
  dic[X].append(Y)
  X_list[i] = X
  Y_list[i] = Y
for j in range(1, N + 1):
  dic[j].sort()
for x, y in zip(X_list, Y_list):
  print(str(x).zfill(6)+str(dic[x].index(y) + 1).zfill(6))

Submission status: Time Limit Exceeded

Solution code:
N, M = map(int, input().split())
dic = {i: [] for i in range(1, N + 1)} 
X_list = []
Y_list = []
for i in range(M):
  X, Y = map(int, input().split())
  dic[X].append(Y)
  X_list.append(X)
  Y_list.append(Y)
for j in range(1, N + 1):
  dic[j].sort()
for x, y in zip(X_list, Y_list):
  print(str(x).zfill(6)+str(dic[x].index(y) + 1).zfill(6))

Submission status: Time Limit Exceeded

Solution code:
def digit6(n):
  if len(str(n))<6:
    return "0"*(6-len(str(n))) + str(n)
  else:
    return str(n)
n,m=map(int,input().split())
py=[list(map(int,input().split())) for i in range(m)]
for i in range(m):
  py[i].append(i)
pre = list(set([py[i][0] for i in range(m)]))
py.sort(key=lambda x: x[1])
for i in pre:
  ct=0
  for j in py:
    if j[0]==i:
      ct += 1
      j.append(digit6(i)+digit6(ct))
py.sort(key=lambda x: x[2])
for i in py:
  print(i[-1])

Submission status: Time Limit Exceeded

Solution code:
def digit6(n):
  if len(str(n))<6:
    return "0"*(6-len(str(n))) + str(n)
  else:
    return str(n)
n,m=map(int,input().split())
py=[list(map(int,input().split())) for i in range(m)]
for i in range(m):
  py[i].append(i)
pre = list(set([py[i][0] for i in range(m)]))
py.sort(key=lambda x: x[1])
for i in pre:
  ct=0
  for j in py:
    if j[0]==i:
      ct += 1
      j.append(digit6(i)+digit6(ct))
py.sort(key=lambda x: x[2])
for i in py:
  print(i[-1])

Submission status: Time Limit Exceeded

Solution code:
n,m = map(int, input().split())
pre = {}
city = []
for i in range(m):
    p,y = map(int, input().split())
    if p not in pre:
        pre[p] = []
    pre[p].append(y)
    city.append((p,y))

for k in pre.keys():
    pre[k].sort()

for p,y in city:
    print(str(p).zfill(6) + str(pre[p].index(y)+1).zfill(6))

Submission status: Time Limit Exceeded

Solution code:
import math
import numpy as np
from fractions import gcd
import fractions
import statistics
import collections
from functools import reduce
import itertools
from collections import defaultdict

N,M=map(int, input().split())
city = defaultdict(list)
p = [0] * M
y = [0] * M

for i in range(M):
    p[i],y[i]=map(int, input().split())
    city[p[i]].append(y[i])

city_sorted = defaultdict(list)
year = defaultdict(list)
for key,v in city.items():
    city_sorted[key] = sorted(v)
    for X in city_sorted.values():
        for i,x in enumerate(X):
            year[x] = i+1

for a in range(M):
    print(str(p[a]).zfill(6)+str(year[y[a]]).zfill(6))

Submission status: Time Limit Exceeded

Solution code:
import math
import numpy as np
from fractions import gcd
import fractions
import statistics
import collections
from functools import reduce
import itertools
from collections import defaultdict

N,M=map(int, input().split())
city = defaultdict(list)
p = [0] * M
y = [0] * M

for i in range(M):
    p[i],y[i]=map(int, input().split())
    city[p[i]].append(y[i])

city_sorted = defaultdict(list)
for key,v in city.items():
    city_sorted[key] = sorted(v)

for a in range(M):
    for (i,x) in enumerate(city_sorted[p[a]]):
        if (y[a] == x):
            print(str(p[a]).zfill(6)+str(i+1).zfill(6))
            break

Submission status: Time Limit Exceeded

Solution code:
import math
import numpy as np
from fractions import gcd
import fractions
import statistics
import collections
from functools import reduce
import itertools
from collections import defaultdict

N,M=map(int, input().split())
city = defaultdict(list)
p = [0] * M
y = [0] * M

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

city_sorted = defaultdict(list)
for key,v in city.items():
    city_sorted[key] = sorted(v)

for a in range(M):
    key = p[a]
    for (i,x) in enumerate(city_sorted[key]):
        if (y[a] == x):
            print(str(key).zfill(6)+str(i+1).zfill(6))

Submission status: Time Limit Exceeded

Solution code:
N, M = map(int, input().split())

Years = []
Ps = {}
for _ in range(M):
  P, Y = map(int, input().split())
  Years.append(Y)
  if P in Ps:
    Ps[P].append(Y)
  else:
    Ps[P] = [Y]

A = [0] * M
for i, v in Ps.items():
  for yi, y in enumerate(sorted(v)):
    index = Years.index(y)
    A[index] = str(i).zfill(6)+str(yi+1).zfill(6)
  
for a in A:
  print(a)

Submission status: Time Limit Exceeded

Solution code:
N,M=map(int,input().split())
dic={i+1:[] for i in range(N)}
PY=[]
len_=0
for i in range(M):
    flag=0
    p,y=map(int,input().split())
    len_=len(dic[p])
    if len_==0:
        dic[p]=[y]
    else:
        for j in range(len_):
            if dic[p][j]>y:
                dic[p].insert(j,y)
                flag=1
                break
        if flag==0:
            dic[p].append(y)
    PY.append([p,y])

p,y='',''
ans=[]
for py in PY:
    p=str(py[0])
    y=str(py[1])
    born=dic[int(p)].index(int(y))+1
    print('0'*(6-len(p))+p+'0'*(6-len(str(born)))+str(born))

Submission status: Time Limit Exceeded

Solution code:
N,M=map(int,input().split())
dic={i+1:[] for i in range(N)}
PY=[]
for i in range(M):
    p,y=map(int,input().split())
    dic[p].append(y)
    PY.append([p,y])
for k,v in dic.items():
    v.sort()
    dic[k]=v
p,y='',''
ans=[]
for py in PY:
    p=str(py[0])
    y=str(py[1])
    born=dic[int(p)].index(int(y))+1
    print('0'*(6-len(p))+p+'0'*(6-len(str(born)))+str(born))

Submission status: Time Limit Exceeded

Solution code:
n,m = map(int,input().split())
lst = []
lst2 = [[]for i in range(n)]
for i in range(m):
  p,y = map(int,input().split())
  lst.append([p,y])
  lst2[p-1]+=[y]
for j in range(len(lst2)):
  lst2[j].sort()
for k in range(len(lst)):
  x = lst2[lst[k][0]-1].index(lst[k][1])+1
  print("{:06}{:06}".format(lst[k][0],x))

Submission status: Time Limit Exceeded

Solution code:
n,m = map(int,input().split())
lst = [[]for i in range(m)]
lst2 = [[]for i in range(n)]
for i in range(m):
  p,y = map(int,input().split())
  lst[i] = [p,y]
  lst2[p-1]+=[y]
for j in range(len(lst2)):
  lst2[j] = sorted(lst2[j])
for k in range(len(lst)):
  x = lst2[lst[k][0]-1].index(lst[k][1])+1
  print("{:06}{:06}".format(lst[k][0],x))

Submission status: Time Limit Exceeded

Solution code:
n,m = map(int,input().split())
lst = [[]for i in range(m)]
lst2 = [[]for i in range(n)]
for i in range(m):
  p,y = map(int,input().split())
  lst[i] = [p,y]
  lst2[p-1]+=[y]
for j in range(len(lst2)):
  lst2[j] = sorted(lst2[j])
for k in range(len(lst)):
  x = lst2[lst[k][0]-1].index(lst[k][1])+1
  print("0"*(6-len(str((lst[k][0]))))+str(lst[k][0])+"0"*(6-len(str(x)))+str(x))

Submission status: Time Limit Exceeded

Solution code:
n,m = map(int,input().split())
l = []
for i in range(m):
    ken,year = map(int,input().split())
    l.append([ken,year])
for i in l:
    num = 1
    for j in range(len(l)):
        if l[j][0] == i[0] and l[j][1] < i[1]:
            num+=1
    print(str(i[0]).zfill(6)+str(num).zfill(6))

Submission status: Time Limit Exceeded

Solution code:
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))

Submission status: Time Limit Exceeded

Solution code:
def two_int():
    N, K = map(int, input().split())
    return N,K

def one_int():
    return int(input())

def one_str():
    return input()

def many_int():
    return list(map(int, input().split()))
import sys
input = sys.stdin.readline

N,M = two_int()

inputs =[]

dicts={}

for i in range(M):
    P,S = two_int()
    inputs.append([P,S])
    
    if P not in dicts:
        dicts[P]=[]
    
    if S not in dicts[P]:
        dicts[P].append(S)
    


#各県でsort
pref_strs={}
for k, v in dicts.items():
    dicts[k]=sorted(dicts[k])
    pref_strs[k]=str(k).zfill(6)



import bisect

for i in inputs:
    P,S=i
    
    city_index = bisect.bisect_right(dicts[P], S)
    city_str=str(city_index)
    
    print(pref_strs[P]+city_str.zfill(6))

Submission status: Time Limit Exceeded

Solution code:
def two_int():
    N, K = map(int, input().split())
    return N,K

def one_int():
    return int(input())

def one_str():
    return input()

def many_int():
    return list(map(int, input().split()))
import sys
input = sys.stdin.readline

N,M = two_int()

inputs =[]

dicts={}

for i in range(M):
    P,S = two_int()
    inputs.append([P,S])
    
    if P not in dicts:
        dicts[P]=[]
    
    if S not in dicts[P]:
        dicts[P].append(S)
    


#各県でsort
for k, v in dicts.items():
    dicts[k]=sorted(dicts[k])



import bisect

for i in inputs:
    P,S=i
    pref_str=str(P)
    
    city_index = bisect.bisect_right(dicts[P], S)
    city_str=str(city_index)
    
    print(pref_str.zfill(6)+city_str.zfill(6))

Submission status: Time Limit Exceeded

Solution code:
def two_int():
    N, K = map(int, input().split())
    return N,K

def one_int():
    return int(input())

def one_str():
    return input()

def many_int():
    return list(map(int, input().split()))

N,M = two_int()

inputs =[]

dicts={}

for i in range(M):
    P,S = two_int()
    inputs.append([P,S])
    
    if P not in dicts:
        dicts[P]=[]
    
    if S not in dicts[P]:
        dicts[P].append(S)
    


#各県でsort
for k, v in dicts.items():
    dicts[k]=sorted(dicts[k])



import bisect

for i in inputs:
    P,S=i
    pref_str=str(P)
    
    city_index = bisect.bisect_right(dicts[P], S)
    city_str=str(city_index)
    
    print(pref_str.zfill(6)+city_str.zfill(6))

Submission status: Time Limit Exceeded

Solution code:

N, M = map(int, input().split())
cities = []
prefectures = [[] for _ in range(N+1)]

for i in range(M):
  p, y = map(int, input().split())
  cities.append((y, p))

for (y, p) in sorted(cities):
  prefectures[p].append(y)

for (y, p) in cities:
  x = prefectures[p].index(y) + 1
  pid = "00000" + str(p)
  xid = "00000" + str(x)
  print(pid[::-1][:6][::-1] + xid[::-1][:6][::-1])