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:
# str(val).zfill(6)
def sort_all_arr_in_dict(dict):
    if len(dict) == 0:
        return {}
    else:
        for k in dict:
            dict[k].sort()
    


if __name__ == "__main__":
    N,M = map(int,input().split())
    prefecture_dict,city_arr = {},[]
    for i in range(M):
        P,Y = map(int,input().split())
        if P in prefecture_dict:
            prefecture_dict[P].append(Y)
        else: 
            prefecture_dict[P] = [Y]
        city_arr.append([P,Y])
    sort_all_arr_in_dict(prefecture_dict)
    for city in city_arr:
        birth_num = (prefecture_dict[city[0]].index(city[1])+1)
        print("{}{}".format(str(city[0]).zfill(6),str(birth_num).zfill(6)))

Submission status: Time Limit Exceeded

Solution code:
# str(val).zfill(6)
def sort_all_arr_in_dict(dict):
    if len(dict) == 0:
        return {}
    else:
        for k,v in dict.items():
            dict[k].sort()
    


if __name__ == "__main__":
    N,M = map(int,input().split())
    prefecture_dict,city_arr = {},[]
    for i in range(M):
        P,Y = map(int,input().split())
        if P in prefecture_dict:
            prefecture_dict[P].append(Y)
        else: 
            prefecture_dict[P] = [Y]
        city_arr.append([P,Y])
    sort_all_arr_in_dict(prefecture_dict)
    for city in city_arr:
        birth_num = (prefecture_dict[city[0]].index(city[1])+1)
        print("{}{}".format(str(city[0]).zfill(6),str(birth_num).zfill(6)))

Submission status: Time Limit Exceeded

Solution code:
import numpy as np

N,M=map(int,input().strip().split())
PY=np.array([list(map(int,input().strip().split())) for _ in range(M)])

l=[[] for n in range(N)]
for m in range(M):
    l[PY[m,0]-1].append(PY[m,1])

dp=[[0 for i in range(max(PY[:,1]))] for j in range(max(PY[:,0]))]
for n in range(N):
    if l[n]:
        l[n].sort()
        for i in range(len(l[n])):
            city="000000"+str(n+1)
            num="000000"+str(i+1)
            dp[n][l[n][i]-1]=str(city[-6:]+num[-6:])
for m in range(M):
    print(dp[PY[m,0]-1][PY[m,1]-1])

Submission status: Time Limit Exceeded

Solution code:
import numpy as np

N,M=map(int,input().strip().split())
PY=np.array([list(map(int,input().strip().split())) for _ in range(M)])

l=[[] for n in range(N)]
for m in range(M):
    tmp=PY[m][0]
    l[tmp-1].append(PY[m][1])

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

dp=[[0 for i in range(max(PY[:,1]))] for j in range(max(PY[:,0]))]
for n in range(N):
    if l[n]:
        for i in range(len(l[n])):
            city="000000"+str(n+1)
            year="000000"+str(i+1)
            dp[n][l[n][i]-1]=str(city[-6:]+year[-6:])
for n in range(len(PY)):
    print(dp[PY[n,0]-1][PY[n,1]-1])

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
N, M = map(int, input().split())
l_1 = [[] for i in range(N+1)]
l_2 = []
for i in range(M):
  p, y = map(int, input().split())
  l_1[p].append(y)
  l_2.append([p, y])
  
for i in range(N+1):
  if l_1[i] != []:
    l = sorted(l_1[i])
    l_1[i] = l
    
for i in range(M):
  c = l_2[i]
  n = l_1[c[0]].index(c[1]) + 1
  ans = str(c[0]).zfill(6) + str(n).zfill(6)
  print(ans)

Submission status: Time Limit Exceeded

Solution code:
n,m = map(int,input().split())
ls = [[] for _ in range(10**5)]
k = 0
di = [list(map(int,input().split())) for _ in range(m)]
for i in range(m):
    ls[di[i][0]-1].append(di[i][1])
    if di[i][0] > k:
        k = di[i][0]
for j in range(k):
    ls[j].sort()
for l in range(m): 
    p = str(10**12 + di[l][0]*(10**6) + ls[di[l][0]-1].index(di[l][1])+1)
    print(p[1:])

Submission status: Time Limit Exceeded

Solution code:
n,m=map(int,input().split())
d=[[]]
pl=[]
yl=[]
for i in range(n-1):
    d.append([])
for i in range(m):
    p,y=map(int,input().split())
    pl.append(p)
    yl.append(y)
    d[p-1].append(y)
    d[p-1].sort()
for i  in range(m):
    print(str(pl[i]).zfill(6),end='')
    print(str(d[pl[i]-1].index(yl[i])+1).zfill(6))

Submission status: Time Limit Exceeded

Solution code:
# abc113_c.py
# https://atcoder.jp/contests/abc113/tasks/abc113_c

# C - ID /
# 実行時間制限: 2 sec / メモリ制限: 1024 MB
# 配点: 300点

# 問題文
# Atcoder国には N個の県があり、これらの県には合計で M個の市が属しています。
# 市 iが誕生したのは Yi 年であり、県 Piに属しています。
# ただし、同じ年に誕生した市が複数存在することはないとします。
# それぞれの市に 12桁の認識番号を割り振ることとなりました。
# 市 iが 県 Pi に属する市の中で x 番目に誕生した市のとき、市 i の認識番号の上 6 桁は Pi、下 6 桁は xとなります。
# ただし、Piや x が 6 桁に満たない場合は 6 桁になるまで 0を左に追加するものとします。
# 全ての市の認識番号を求めてください。
# ただし、市が 1つも属さない県がある場合に注意してください。

# 制約
#     1≤N≤10^5
#     1≤M≤10^5
#     1≤Pi≤N
#     1≤Yi≤10^9
#     Yiは全て異なる
#     入力は全て整数

# 入力
# 入力は以下の形式で標準入力から与えられる。
# N M
# P1 Y1
# :
# PM YM

# 出力
# 全ての市の認識番号を市の番号の昇順に出力せよ。

# 入力例 1
# 2 3
# 1 32
# 2 63
# 1 12

# 出力例 1
# 000001000002
# 000002000001
# 000001000001

#     市 1は県 1 に属する市の中で 2 番目に誕生したので、認識番号は 000001000002となります。
#     市 2は県 2 に属する市の中で 1 番目に誕生したので、認識番号は 000002000001となります。
#     市 3は県 1 に属する市の中で 1 番目に誕生したので、認識番号は 000001000001となります。

# 入力例 2
# 2 3
# 2 55
# 2 77
# 2 99

# 出力例 2
# 000002000001
# 000002000002
# 000002000003


def calculation(lines):
    # N = int(lines[0])
    N, M = list(map(int, lines[0].split()))
    values = list()
    for i in range(M):
        values.append(list(map(int, lines[i+1].split())))

    dic = dict()
    for p, y in values:
        if p in dic.keys():
            dic[p].append(y)
        else:
            dic[p] = [y]

    results = list()

    for key in dic:
        dic[key].sort()

    for p, y in values:
        for i, item in enumerate(dic[p]):
            if item == y:
                pos = i+1
        tmp = format(p, '0=6') + format(pos, '0=6')
        results.append(tmp)

    # for i in range(n):
    #     tmp = format(key, '0=6') + format(i+1, '0=6')
    #     results.append(tmp)

    return results


# 引数を取得
def get_input_lines():
    line = input()
    N, M = list(map(int, line.split()))
    lines = list()
    lines.append(line)
    for _ in range(M):
        lines.append(input())
    return lines


# テストデータ
def get_testdata(pattern):
    if pattern == 1:
        lines_input = ['2 3', '1 32', '2 63', '1 12']
        lines_export = ['000001000002', '000002000001', '000001000001']
    if pattern == 2:
        lines_input = ['2 3', '2 55', '2 77', '2 99']
        lines_export = ['000002000001', '000002000002', '000002000003']
    return lines_input, lines_export


# 動作モード判別
def get_mode():
    import sys
    args = sys.argv
    if len(args) == 1:
        mode = 0
    else:
        mode = int(args[1])
    return mode


# 主処理
def main():
    import time
    started = time.time()
    mode = get_mode()
    if mode == 0:
        lines_input = get_input_lines()
    else:
        lines_input, lines_export = get_testdata(mode)

    lines_result = calculation(lines_input)

    for line_result in lines_result:
        print(line_result)

    # if mode > 0:
    #     print(f'lines_input=[{lines_input}]')
    #     print(f'lines_export=[{lines_export}]')
    #     print(f'lines_result=[{lines_result}]')
    #     if lines_result == lines_export:
    #         print('OK')
    #     else:
    #         print('NG')
    # finished = time.time()
    # duration = finished - started
    # print(f'duration=[{duration}]')


# 起動処理
if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:

NN, MM = list(map(int,input().split()))

data = []
pref = [[] for i in range(NN)]
while True:
    try:
        i = list(map(int, input().split()))
        data.append(i)
        pref[i[0] - 1].append(int(i[1]))
    except EOFError:
        break

for j in range(NN):
    pref[j].sort()

for k in range(len(data)):
    print("{:06d}".format(int(data[k][0])),"{:06d}".format(pref[data[k][0]-1].index(data[k][1])+1),sep="")

#print(pref)

Submission status: Time Limit Exceeded

Solution code:

NN, MM = list(map(int,input().split()))

data = []
pref = [[] for i in range(NN)]
while True:
    try:
        i = list(map(int, input().split()))
        data.append(i)
        pref[i[0] - 1].append(i[1])
    except EOFError:
        break

for j in range(NN):
    pref[j].sort()

for k in range(len(data)):
    print("{:06d}".format(int(data[k][0])),"{:06d}".format(pref[data[k][0]-1].index(data[k][1])+1),sep="")

#print(pref)

Submission status: Time Limit Exceeded

Solution code:
NN, MM = list(map(int,input().split()))

data = []
pref = [[] for i in range(NN)]
while True:
    try:
        i = list(map(int, input().split()))
        data.append(i)
    except EOFError:
        break

for i in range(len(data)):
    pref[data[i][0]-1].append(int(data[i][1]))

for j in range(NN):
    pref[j].sort()

for k in range(len(data)):
    print("{:06d}".format(int(data[k][0])),"{:06d}".format(pref[data[k][0]-1].index(data[k][1])+1),sep="")

#print(pref)

Submission status: Time Limit Exceeded

Solution code:
n,m = map(int,input().split())
l = [list(map(int,input().split())) for _ in range(m)]
#print(l)
k = [[] for i in range(n)]
for j,h in l:
  k[j-1].append(h)
k_so = [[] for i in range(n)]
for i in range(n):
  a = k[i]
  k_so[i] = sorted(a)
#print(k_so)
for j,h in l:
  first = "{:0=6}".format(j)
  second = "{:0=6}".format(k_so[j-1].index(h)+1)
  print(first+second)

Submission status: Time Limit Exceeded

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

for i in range(m):
  p,y=map(int,input().split())
  l[p-1].append(y)
  l2.append([p,y])
for m in l:
  m.sort()

for m in l2:
  print("{:06d}".format(m[0]) +"{:06d}".format(l[m[0]-1].index(m[1])+1))

Submission status: Time Limit Exceeded

Solution code:
N, M = map(int, input().split())
v = [[] for _ in range(10**5+1)]
cities = []

for _ in range(M):
    p, y = map(int, input().split())
    cities.append([p, y])
    v[p].append(y)

for i in v:
    i.sort()

for p, y in cities:
    num = v[p].index(y) + 1
    ans = format(str(p), "0>6") + format(str(num), "0>6")
    print(ans)

Submission status: Time Limit Exceeded

Solution code:
n, m = map(int, input().split())
c_y = {}
l = []
for i in range(m):
    c,y = map(int, input().split())
    l.append(list([c,y]))
    if not c in c_y:
        c_y[c] = []
        c_y[c].append(y)
    else:
        c_y[c].append(y)
    
for k in c_y.keys():
    c_y[k].sort()

for i in range(m):
    print("%06d%06d" % (l[i][0] , c_y[l[i][0]].index(l[i][1]) + 1))

Submission status: Time Limit Exceeded

Solution code:
N,M = map(int, input().split())
q = [[int(j) for j in input().split()] for i in range(M)]
li = [[] for k in range(N+1)]

for i,j in sorted(q, key=lambda x:x[1]):
    li[i].append(j)

for p,y in q:
    print("{:0=6}".format(p) + "{:0=6}".format(li[p].index(y)+1))

Submission status: Time Limit Exceeded

Solution code:
N,M = map(int, input().split())
# 市 i は　県 n (N)で x 番目に誕生した
li = []
pre = [[] for i in range(N)]
for i in range(M):
    p,y = map(int, input().split())
    pre[p-1].append(y)
    li.append([p,y])
pre = list(map(sorted,pre))
for p,y in li:
    print("{:0=6}".format(p) + "{:0=6}".format(pre[p-1].index(y)+1))

Submission status: Time Limit Exceeded

Solution code:
from collections import defaultdict
import sys
input = sys.stdin.readline

def main():
    N, M = map(int, input().split())
    PY = [tuple(map(int, input().split())) for _ in range(M)]
    result = [None for _ in range(M)]
    p_city = defaultdict(int)
    for py in sorted(PY, key = lambda x: x[1]):
        p_city[py[0]] += 1
        code = str(py[0]).zfill(6) + str(p_city[py[0]]).zfill(6)
        result[PY.index(py)] = code
    print("\n".join(result))


if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
def main():
  n, m = map(int, input().split())
  def zs(num):
    k = 6 - len(str(num))
    return '0' * k + str(num)
  lst = [[-1] for i in range(n + 1)]
  cities = []
  for i in range(m):
    temp = tuple(map(int, input().split()))
    lst[temp[0]].append(temp[1])
    cities.append(temp)
  for l in lst:
    l.sort()
  for tpl in cities:
    a = lst[tpl[0]].index(tpl[1])
    print(zs(tpl[0]) + zs(a))
if __name__ == '__main__':
  main()

Submission status: Time Limit Exceeded

Solution code:
n, m = map(int, input().split())
def zs(num):
  k = 6 - len(str(num))
  return '0' * k + str(num)
lst = [[-1] for i in range(n + 1)]
cities = []
for i in range(m):
  temp = tuple(map(int, input().split()))
  lst[temp[0]].append(temp[1])
  cities.append(temp)
for l in lst:
  l.sort()
for tpl in cities:
  a = lst[tpl[0]].index(tpl[1])
  print(zs(tpl[0]) + zs(a))

Submission status: Time Limit Exceeded

Solution code:
def get_(i):
    zero_len = 6-len(str(i))
    return '0'*zero_len+str(i)

N,M = list(map(int,input().split()))
N_list=[[] for n in range(N)]
M_list=[]

for m in range(M):
    P,Y=list(map(int,input().split()))
    N_list[P-1].append(Y)
    M_list.append([P,Y])
    
for n in N_list:
    n.sort()
    
for m in M_list:
    p=get_(m[0])
    
    i=N_list[m[0]-1].index(m[1])+1
    i=get_(i)
    
    print(p+i)

Submission status: Time Limit Exceeded

Solution code:
def get_(i):
    zero_len = 6-len(str(i))
    return '0'*zero_len+str(i)

N,M = list(map(int,input().split()))
N_list=[[] for n in range(N)]
M_list=[]

for m in range(M):
    P,Y=list(map(int,input().split()))
    N_list[P-1].append(Y)
    M_list.append([P,Y])
    
for n in N_list:
    n.sort()
    
for m in M_list:
    p=get_(m[0])
    
    i=N_list[m[0]-1].index(m[1])+1
    i=get_(i)
    
    print(p+i)

Submission status: Time Limit Exceeded

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

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

for i in range(n):
    lst[i]=sorted(lst[i])

for i in range(m):
    left=str(print_lst[i][0]+1)
    right=str(lst[print_lst[i][0]].index(print_lst[i][1])+1)
    prnt=["0"*(6-len(left)),left,"0"*(6-len(right)),right]
    print("".join(prnt))

Submission status: Time Limit Exceeded

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

for i in range(n):
    lst[i]=sorted(lst[i])

for i in range(m):
    left=str(print_lst[i][0]+1)
    right=str(lst[print_lst[i][0]].index(print_lst[i][1])+1)
    prnt=["0"*(6-len(left)),left,"0"*(6-len(right)),right]
    print("".join(prnt))

Submission status: Time Limit Exceeded

Solution code:
n,m=map(int,input().split())
p=[]
pp=[1]
pp*=n
ans=[]
for i in range(n):
    p.append([])
for i in range(m):
    pi,yi=map(int,input().split())
    p[pi-1].append([yi,pp[pi-1]])
    ans.append([pi-1,pp[pi-1]])
    pp[pi-1]+=1
for i in range(n):
    p[i].sort()
for i in range(m):
    b=len(p[ans[i][0]])
    for j in range(b):
        if ans[i][1]==p[ans[i][0]][j][1]:
            print('{0:06d}{1:06d}'.format(ans[i][0]+1,j+1))
            break

Submission status: Time Limit Exceeded

Solution code:
N, M = map(int, input().split())
PY = [list(map(int, input().split())) for _ in range(M)]

A = [[] for _ in range(N+1)]
for py in PY:
    A[py[0]].append(py[1])

for i in range(N+1):
    A[i] = sorted(A[i])

for py in PY:
    pref = py[0]
    city = A[pref].index(py[1])+1
    print(str(pref).zfill(6) + str(city).zfill(6))

Submission status: Time Limit Exceeded

Solution code:
n,m=map(int,input().split())
inf=[]
pre=[[] for _ in range(n)]
for _ in range(m):
    p,y=map(int,input().split())
    inf.append([p,y])
    pre[p-1].append(y)
for p in range(n): pre[p].sort()
for i in inf: print("{:06}{:06}".format(i[0],1+pre[i[0]-1].index(i[1])))

Submission status: Time Limit Exceeded

Solution code:
n,m=map(int,input().split())
inf=[]
pre=[[] for _ in range(n)]
for _ in range(m):
    p,y=map(int,input().split())
    pre[p-1].append(y)
    inf.append([p,y])
for key,lis in enumerate(pre): pre[key]=sorted(lis)
for i in inf: print("{:06}{:06}".format(i[0],1+pre[i[0]-1].index(i[1])))

Submission status: Time Limit Exceeded

Solution code:
from collections import defaultdict

n,m=map(int,input().split())
inf=[]
pre=defaultdict(list)
for _ in range(m):
    p,y=map(int,input().split())
    pre[p-1].append(y)
    inf.append([p,y])
for key,lis in pre.items(): pre[key]=sorted(lis)
for i in inf: print("{:06}{:06}".format(i[0],1+pre[i[0]-1].index(i[1])))

Submission status: Time Limit Exceeded

Solution code:
n,m = map(int,input().split())
l = []
numl = [[] for i in range(n+1)]
l = [list(map(int,input().split())) for i in range(m)]
 
for i in l:
  numl[i[0]].append(i[1])

for i in numl:
  i.sort()
  
for i in l:
  print(str(i[0]).zfill(6) + str((numl[i[0]].index(i[1]))+1).zfill(6))

Submission status: Time Limit Exceeded

Solution code:
n,m = map(int,input().split())
l = []
numl = [[] for i in range(n+1)]
l = [list(map(int,input().split())) for i in range(m)]

for i in l:
  numl[i[0]].append(i[1])

for i in numl:
  i.sort()
  
for i in l:
  print(str(i[0]).zfill(6) + str((numl[i[0]].index(i[1]))+1).zfill(6))

Submission status: Time Limit Exceeded

Solution code:
import collections

N, M = map(int, input().split())

dic = collections.defaultdict(lambda:[])
pairs = []

for _ in range(M):
  P, Y = map(int, input().split())
  pairs.append((P, Y))
  dic[P].append(Y)

for key in dic:
  dic[key].sort()

while pairs:
  P, Y = pairs.pop(0)
  print(str(P).zfill(6) + str(dic[P].index(Y)+1).zfill(6))

Submission status: Time Limit Exceeded

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

N, M = map(int, input().split())
PY = [tuple(map(int, input().split())) for _ in range(M)]
dic = {}
for p, y in PY:
    dic[p] = (dic.get(p) or []) + [y]
for p, v in dic.items():
    dic[p] = {x: i+1 for i, x in enumerate(sorted(v))}
[print(str(1*10**12+p*10**6+dic[p][y])[1:]) for p, y in PY]

Submission status: Time Limit Exceeded

Solution code:
n,m=map(int,input().split())
L=[]
for i in range(m):
    L.append(tuple(map(int,input().split())))
T=sorted(L)
p=1
count=1
for i in range(m):
    if p!=T[i][0]:
        count=1
    ind=L.index(T[i])
    L[ind]=(T[i][0],count)
    p=T[i][0]
    count += 1
for i in L:
    num=i[0]*(10**6)+i[1]
    print(str(num).zfill(12))

Submission status: Time Limit Exceeded

Solution code:
n,m = map(int,input().split())
ls = [[0,0] for _ in range(m)]
di = [[] for _ in range(n)]
for k in range(m):
    c,d = map(int,input().split())
    ls[k][0],ls[k][1] = c,d
    di[c-1].append(d)
for i in range(n):
    di[i].sort()
for j in range(m):
    a,b = ls[j][0],ls[j][1]
    p = di[a-1].index(b)
    q = 10**12 + (a)*10**6 +(p+1)
    print(str(q)[1:])

Submission status: Time Limit Exceeded

Solution code:
n,m = map(int,input().split())
ls = [list(map(int,input().split())) for _ in range(m)]
di = [0]*n
for i in range(n):
    new = [e[1] for e in ls if e[0] == i+1]
    new.sort()
    di[i] = new
for j in range(m):
    a,b = ls[j][0],ls[j][1]
    p = di[a-1].index(b)
    q = 10**12 + (a)*10**6 +(p+1)
    print(str(q)[1:])

Submission status: Time Limit Exceeded

Solution code:
n,m = map(int,input().split())
ls = [list(map(int,input().split())) for _ in range(m)]
di = [[] for _ in range(n)]
for i in range(m):
    di[ls[i][0]-1].append(ls[i][1])
    di[ls[i][0]-1].sort()
for k in range(m):
    a = di[ls[k][0]-1].index(ls[k][1])
    q = 10**12 + (ls[k][0])*10**6 +(a+1)
    print(str(q)[1:])

Submission status: Time Limit Exceeded

Solution code:
n,m = map(int,input().split())
ls = [list(map(int,input().split())) for _ in range(m)]
di = [[] for _ in range(n)]
for i in range(m):
    di[ls[i][0]-1].append(ls[i][1])
    di[ls[i][0]-1].sort()
for k in range(m):
    a = di[ls[k][0]-1].index(ls[k][1])
    print(str(ls[k][0]).rjust(6,"0")+str(a+1).rjust(6,"0"))

Submission status: Time Limit Exceeded

Solution code:
n,m = map(int,input().split())
ls = [list(map(int,input().split())) for _ in range(m)]
di = [[] for _ in range(n)]
for i in range(m):
    di[ls[i][0]-1].append(ls[i][1])
for j in range(n):
    di[j].sort()
for k in range(m):
    a = di[ls[k][0]-1].index(ls[k][1])
    print(str(ls[k][0]).rjust(6,"0")+str(a+1).rjust(6,"0"))

Submission status: Time Limit Exceeded

Solution code:
n,m=map(int,input().split())
a=[]
for i in range(m):
  a.append(list(map(int,input().split())))
b=list(zip(*a))
c=sorted(b[1])
d=[0]*n
for i in c:
  j=b[0][b[1].index(i)]-1
  d[j]+=1
  a[b[1].index(i)][1]=d[j]
for i in range(m):
  print('{0:06}{1:06} '.format(a[i][0],a[i][1]))

Submission status: Time Limit Exceeded

Solution code:
dict={}
dict2={}
n,m=map(int,input().split())
for i in range(m):
	p,m=map(int,input().split())
	dict[i]=[p,m]
	if p not in dict2:
		dict2[p]=[m]
	else:
		dict2[p].append(m)
for d in dict:
	a='{:0=6}'.format(dict[d][0])
	c=sorted(dict2[dict[d][0]]).index(dict[d][1])+1
	c='{:0=6}'.format(c)
	print(a+c)

Submission status: Time Limit Exceeded

Solution code:
dict={}
dict2={}
n,m=map(int,input().split())
for i in range(m):
	p,m=map(int,input().split())
	dict[i]=[p,m]
	if p not in dict2:
		dict2[p]=[m]
	else:
		dict2[p].append(m)
		dict2[p].sort()
for d in dict:
	a='{:0=6}'.format(dict[d][0])
	c=dict2[dict[d][0]].index(dict[d][1])+1
	c='{:0=6}'.format(c)
	print(a+c)

Submission status: Time Limit Exceeded

Solution code:
import bisect

def main():
    n, m = map(int, input().split())
    py = [list(map(int, input().split())) for _ in range(m)]
    x = [[0] for _ in range(n+1)]
    for p, y in py:
        bisect.insort_left(x[p], y)
    for p, y in py:
        num = x[p].index(y)
        print('{:0=6}{:0=6}'.format(p, num))
         
    
if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
N, M = map(int, input().split())
d = {}
sitios = []
for i in range(M):
  p, y = map(int, input().split())
  sitios.append((p, y))
  if(p in d):
    d[p].append(y)
  else:
    d[p]= [y]
    
for year in d.values():
  year.sort()

for i in range(M):
  p, y = sitios[i]
  ident = "{}".format(p).rjust(6, "0")
  no = d[p].index(y)+ 1
  ident+= "{}".format(no).rjust(6, "0")
  print(ident)

Submission status: Time Limit Exceeded

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

PY_sort = sorted(PY, key=lambda x: x[1])
PY_sort.sort(key=lambda x: x[0])

ID = {}
for i in range(1, n + 1):
    T = [py for py in PY_sort if py[0] == i]
    for i, v in enumerate(T):
        id = "%06d%06d"%(v[0], i + 1)
        ID[v[1]] = id

for p, y in PY:
    print(ID[y])

Submission status: Time Limit Exceeded

Solution code:
import bisect

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

a = {p: [] for p, _ in py}
for p, y in py:
    a[p].append(y)

for p, _ in py:
    a[p].sort()

for p, y in py:
    # t = a[p].index(y) + 1
    t = bisect.bisect_left(a[p], y)+1
    print("{:06}{:06}".format(p, t))

Submission status: Time Limit Exceeded

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

a = {p: [] for p, _ in py}
for p, y in py:
    a[p].append(y)

for p, _ in py:
    a[p].sort()

for p, y in py:
    t = a[p].index(y) + 1
    print("{:06}{:06}".format(p, t))

Submission status: Time Limit Exceeded

Solution code:
N, M = [int(i) for i in input().split()]

PY = []
PYd = {i:[] for i in range(1, N+1)}

for i in range(M):
    x, y = [int(i) for i in 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(PYd[p].index(y)+1).zfill(6)
    print(str_p+index)

Submission status: Time Limit Exceeded

Solution code:
import collections

N, M = map(int, input().split())

dic = collections.defaultdict(lambda:[])
pairs = []

for _ in range(M):
  P, Y = map(int, input().split())
  pairs.append((P, Y))
  dic[P].append(Y)

for key in dic:
  dic[key].sort()
  dic[key] = {v:i+1 for i,v in enumerate(dic[key])}

while pairs:
  P, Y = pairs.pop(0)
  print(str(P).zfill(6) + str(dic[P][Y]).zfill(6))

Submission status: Time Limit Exceeded

Solution code:
n, m = map(int, input().split())
li = []
d = {}
for _ in range(m):
    p, y = map(int, input().split())
    li.append([p, y])
    if p not in d:     
        d[p] = [y]
    else:
        d[p].append(y)
for k, v in d.items():
    v.sort()
for p, y in li:
    r = d[p].index(y) + 1
    print(str(p).zfill(6) + str(r).zfill(6))

Submission status: Time Limit Exceeded

Solution code:
n,m=map(int,input().split())
k=[[] for _ in range(n)]
p=[0 for _ in range(m)]
y=[0 for _ in range(m)]
for i in range(m):
	a,b = map(int,input().split())
	y[i] = b
	p[i] = a
	k[a-1].append(b)
for i in range(n):
	k[i].sort()
ansl = []
for i in range(m):
	d1 = str(p[i]).zfill(6)
	d2 = str(k[p[i]-1].index(y[i])+1).zfill(6)
	ansl.append(d1+d2)
print("\n".join(ansl))

Submission status: Time Limit Exceeded

Solution code:
n, m = map(int, input().split())
city_list = [[0] for _ in range(n + 1)]
city = [[]]
for _ in range(m):
    p, y = map(int, input().split())
    city_list[p].append(y)
    city.append([p, y])
for i in range(1, n + 1):
    city_list[i].sort()
for i in range(1, m + 1):
    ID = ''
    p = city[i][0]
    order = str(city_list[p].index(city[i][1]))
    p = str(p)
    ID = ID + ('0' * (6 - len(p)))
    ID += p
    ID += ('0' * (6 - len(order)))
    ID += order
    print(ID)

Submission status: Time Limit Exceeded

Solution code:
n, m = map(int, input().split())
city_list = [[0] for _ in range(n + 1)]
city = [[]]
for _ in range(m):
    p, y = map(int, input().split())
    city_list[p].append(y)
    city.append([p, y])
for i in range(1, n + 1):
    city_list[i].sort()
for i in range(1, m + 1):
    ID = ''
    p = city[i][0]
    order = str(city_list[p].index(city[i][1]))
    p = str(p)
    for _ in range(6 - len(p)):
        ID += '0'
    ID += p
    for _ in range(6 - len(order)):
        ID += '0'
    ID += order
    print(ID)

Submission status: Time Limit Exceeded

Solution code:
n,m=map(int,input().split())
a=[[]*i for i in range(n)]
tmp=[]
for i in range(m):
    p,y=map(int,input().split())
    p-=1
    a[p].append([y,i])
for k in range(n):
    if len(a[k])>0:
        a[k].sort()
        for j in a[k]:
            u=str(k+1).zfill(6)
            d=str(a[k].index(j)+1).zfill(6)
            ans=u+d
            tmp.append([ans,j[1]])
tmp.sort(key=lambda x:x[1])
for b in tmp:
    print(b[0])

Submission status: Time Limit Exceeded

Solution code:
from sys import stdin, setrecursionlimit


def main():
    input = stdin.buffer.readline
    n, m = map(int, input().split())
    py = [list(map(int, input().split())) for _ in range(m)]

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

    for p, y in py:
        summary[p - 1].append(y)

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

    for p, y in py:
        print(str(p).zfill(6), str(summary[p - 1].index(y) + 1).zfill(6), sep='')


if __name__ == "__main__":
    setrecursionlimit(10000)
    main()

Submission status: Time Limit Exceeded

Solution code:
from sys import stdin, setrecursionlimit


def main():
    input = stdin.buffer.readline
    n, m = map(int, input().split())
    py = [list(map(int, input().split())) for _ in range(m)]

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

    for p, y in py:
        summary[p - 1].append(y)

    for i in range(n):
        summary[i] = sorted(summary[i])

    for p, y in py:
        print(str(p).zfill(6), str(summary[p - 1].index(y) + 1).zfill(6), sep='')


if __name__ == "__main__":
    setrecursionlimit(10000)
    main()

Submission status: Time Limit Exceeded

Solution code:
#!/usr/bin/env python3
import sys

"""
ABC113_C ID 学び：
 python の0埋め　s.rjust(digit,0) でいける
 sortを県ごとにしないといけない、とわかれば、input, sort , outputの３段かいに別れる
どんな配列を持てばいいかは事前に考える。
実際にそこまで立てて、inputをローカルでやると良い
"""

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
n, m = map(int, input().split())
lis_p = [[] for _ in range(n)]  # 県pに属する市の誕生年が入る
city = [[0, 0] for _ in range(m)]  # p と　idx
idx_p = []  # 何番目にそのcity が県pに追加されたかを記憶
# input
for i in range(m):
    p, y = map(int, input().split())
    city[i][0] = p - 1
    city[i][1] = len(lis_p[p - 1])
    lis_p[p - 1].append(y)
for pref in range(n):
    k = len(lis_p[pref])
    # print(lis_p[pref])
    idx = []
    if k > 0:
        lis_p[pref], idx = zip(*sorted(zip(lis_p[pref], range(k))))
    idx_p.append(list(idx))
#print(lis_p, idx_p)
for i in range(m):
    # string になおす必要がある rjust
    print(str(city[i][0] + 1).rjust(6, "0"), end="")
    print(str(1 + idx_p[city[i][0]].index(city[i][1])).rjust(6, "0"))