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: Accepted

Solution code:
from collections import deque
from heapq import heapify,heappop,heappush,heappushpop
from copy import copy,deepcopy
from itertools import product,permutations,combinations,combinations_with_replacement
from collections import defaultdict,Counter
from bisect import bisect_left,bisect_right
# from math import gcd,ceil,floor,factorial
# from fractions import gcd
from functools import reduce
from pprint import pprint
# from statistics import mean,median,mode

INF = float("inf")

def mycol(data,col):
    return [ row[col] for row in data ]

def mysort(data,col,reverse_flag):
    data.sort(key=lambda x:x[col],reverse=reverse_flag)
    return data

def mymax(data):
    M = -1*float("inf")
    for i in range(len(data)):
        m = max(data[i])
        M = max(M,m)
    return M

def mymin(data):
    m = float("inf")
    for i in range(len(data)):
        M = min(data[i])
        m = min(m,M)
    return m

def mycount(ls,x):
    # lsはソート済みであること
    l = bisect_left(ls,x)
    r = bisect_right(ls,x)
    return (r-l)

def myoutput(ls,space=True):
    if space:
        if len(ls)==0:
            print(" ")
        elif type(ls[0])==str:
            print(" ".join(ls))
        elif type(ls[0])==int:
            print(" ".join(map(str,ls)))
        else:
            print("Output Error")
    else:
        if len(ls)==0:
            print("")
        elif type(ls[0])==str:
            print("".join(ls))
        elif type(ls[0])==int:
            print("".join(map(str,ls)))
        else:
            print("Output Error")

def I():
    return int(input())

def MI():
    return map(int,input().split())

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

def CI(n):
    return [ int(input()) for _ in range(n) ]

def LI(n):
    return [ list(map(int,input().split())) for _ in range(n) ]

def S():
    return input()

def MS():
    return input().split()

def RS():
    return list(input().split())

def CS(n):
    return [ input() for _ in range(n) ]

def LS(n):
    return [ list(input().split()) for _ in range(n) ]

n,m = MI()
py = LI(m)

py_new = []
no = 0
for i in range(m):
    no += 1
    p = py[i][0]
    y = py[i][1]
    py_new.append([no,p,y])

py_new_sorted = mysort(py_new,2,False)

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

no = 0
py_now = []
for i in range(m):
    no = py_new_sorted[i][0]
    p = py_new_sorted[i][1] - 1
    y = py_new_sorted[i][2]
    x = len(g[p]) + 1
    py_now.append([no,p,y,x])
    g[p].append(y)

py_now = mysort(py_now,0,False)

for i in range(m):
    p = str( py_now[i][1] + 1 )
    x = str(py_now[i][3])
    p = p.zfill(6)
    x = x.zfill(6)
    a = p + x
    print(a)

Submission status: Accepted

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

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

C = {}
for i in range(N):
    C[i+1] = 0

D = {}

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

ret = {}
for y, p in sorted(D.items(), key=lambda x: x[0]):
    C[p[0]] += 1
    ret[p[1]] = str(p[0]).zfill(6) + str(C[p[0]]).zfill(6)
    
for i, r in sorted(ret.items(), key=lambda x: x[0]):
    print(r)

Submission status: Accepted

Solution code:
import bisect
from collections import defaultdict
n, m = map(int, input().split())
dic = defaultdict(lambda : [])
cities = []
for _ in range(m):
    p, y = map(int, input().split())
    cities.append((p, y))
    dic[p].append(y)
for key, vals in dic.items():
    dic[key] = sorted(vals)
for p, y in cities:
    pos = bisect.bisect_right(dic[p], y)
    print('{:06}{:06}'.format(p, pos))

Submission status: Accepted

Solution code:
n,m=map(int,input().split())
pys=[0]*m
for i in range(m):
	p,y=map(int,input().split())
	pys[i]=(p,y,i)
pys.sort(key=lambda x:x[1])

num=[0]*n
ans=[0]*m
for p,y,i in pys:
	num[p-1]+=1
	ans[i]=str(p).zfill(6)+str(num[p-1]).zfill(6)

for a in ans:
	print(a)

Submission status: Accepted

Solution code:
import sys
from operator import itemgetter

input = sys.stdin.readline


def main():
    N, M = map(int, input().split())
    iPY = [[0] * 3 for _ in range(M)]
    for i in range(M):
        iPY[i][0] = i
        iPY[i][1:] = map(int, input().split())

    iPY.sort(key=itemgetter(2))

    p_count = [0] * (N + 1)
    ans = [""] * M
    for i, P, Y in iPY:
        p_count[P] += 1
        ans[i] = "".join([
            str(P).zfill(6),
            str(p_count[P]).zfill(6)
        ])

    print("\n".join(ans))


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
def main():
    n, m = map(int, input().split())
    py = [list(map(int, input().split())) for _ in range(m)]
    x = sorted(py, key=lambda x:x[1])
    d = {}
    for p, y in x:
        if type(d.get(p)) != dict:
            d[p]  = {}
        d[p][y] = len(d[p]) + 1
    for p, y in py:
        print('{:0=6}{:0=6}'.format(p, d[p][y]))
         
    
if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
from bisect import bisect_left
N, M = map(int, input().split())
G = [[] for _ in range(N)]
P = [0]*M
Y = [0]*M
for i in range(M):
    P[i], Y[i] = map(int, input().split())
    G[P[i]-1].append(Y[i])

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

for i in range(M):
    right = bisect_left(G[P[i]-1], Y[i])+1
    print(str(P[i]).rjust(6, '0')+str(right).rjust(6, '0'))

Submission status: Accepted

Solution code:
n,m=map(int,input().split())
l=[list(map(int,input().split())) for _ in range(m)]
l2=sorted(l,key=lambda x:x[1])
d=dict()
for p,y in l2:
    if not p in d.keys():
        d[p]=dict()
    d[p][y]=len(d[p])+1
for p,y in l:
    print('{}'.format(p).zfill(6)+'{}'.format(d[p][y]).zfill(6))

Submission status: Accepted

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

N,M = map(int,readline().split())
from collections import defaultdict
PY = defaultdict(list)
for i in range(M):
  p,y = map(int,readline().split())
  PY[p].append([y,i])

res = []
for key,value in PY.items():
  value = sorted(value, key = lambda x:x[0])
  for i in range(len(value)):
    res.append([key,i + 1,value[i][1]])

res = sorted(res, key = lambda x:x[2])
for r in res:
  print(str(r[0]).zfill(6) + str(r[1]).zfill(6))

Submission status: Accepted

Solution code:
from operator import itemgetter
N,M=map(int, input().split())
PY = []
for i in range(M):
    P,Y=map(int, input().split())
    PY.append([P,Y,i])
PY.sort(key=lambda x:x[1])
PY.sort(key=lambda x:x[0])
ANS = []
beforeP = PY[0][0]
x = 1
for i in range(M):
    if beforeP != PY[i][0]:
        x = 1
    ANS.append([PY[i][2],'{:0=6}'.format(PY[i][0]) + '{:0=6}'.format(x)])
    beforeP = PY[i][0]
    x += 1

ANS.sort(key=lambda x:x[0])
for i in range(M):
    print(ANS[i][1])

Submission status: Accepted

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 = {}
i, p = 1, PY_sort[0][0]
for v in PY_sort:
    if v[0] != p:
        i, p = 1, v[0]
    id = "%06d%06d"%(p, i)
    ID[v[1]] = id
    i += 1

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

Submission status: Accepted

Solution code:
n,m=map(int,input().split())
pys=[0]*m
for i in range(m):
    p,y=map(int,input().split())
    pys[i]=(p,y,i)
pys.sort(key=lambda x: x[1])

cnt=[0]*n
ans=[0]*m
for p,y,i in pys:
    cnt[p-1]+=1
    ans[i]=str(p).zfill(6)+str(cnt[p-1]).zfill(6)

for i in ans:
    print(i)

Submission status: Accepted

Solution code:
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, tan, asin, acos, atan, radians, degrees#, log2
from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left, insort, insort_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10**9 + 7
#from decimal import *

N, M = MAP()
PY = [LIST() for _ in range(M)]
PY_ = deepcopy(PY)
PY_.sort(key = lambda x: (x[0],x[1]))

tmp = 0
i = 0
lis = []
dic = {}
for p, y in PY_:
	if p == tmp:
		i += 1
	else: 
		lis.append([])
		tmp = p
		i = 1
	dic[str(p)+"_"+str(y)] = str(p).zfill(6)+str(i).zfill(6)

for p, y in PY:
	print(dic[str(p)+"_"+str(y)])

Submission status: Accepted

Solution code:
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, tan, asin, acos, atan, radians, degrees#, log2
from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left, insort, insort_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10**9 + 7
#from decimal import *

N, M = MAP()
PY = [LIST() for _ in range(M)]

for i in range(M):
	PY[i].append(i)

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

tmp = 0
cnt = 0
for i in range(M):
	if PY[i][0] != tmp:
		cnt = 1
		tmp = PY[i][0]
	else:
		cnt += 1
	PY[i].append(str(PY[i][0]).zfill(6)+str(cnt).zfill(6))

PY.sort(key = lambda x:x[2])

print(*[PY[i][3] for i in range(M)], sep = "\n")

Submission status: Accepted

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

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

nums = [0] * N
ans = [''] * M
pys.sort(key=lambda x:x[1])

for p, y, i in pys:
    nums[p-1] += 1
    ans[i] = str(p).zfill(6) + str(nums[p-1]).zfill(6)

for an in ans:
    print(an)

Submission status: Accepted

Solution code:
n, m = map(int, input().split())
py = [list(map(int, input().split())) for i in range(m)]
c = [0]*(n + 1)
id = {}

for p, y in sorted(py, key = lambda x: x[1]):
    c[p] += 1
    id[y] =  format(p, "06") + format(c[p], "06")

for p, y in py:
    print(id[y])

Submission status: Accepted

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

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

l.sort()

l[0][1] = 1

for i in range(1, m):
    if l[i][0] == l[i - 1][0]:
        l[i][1] = l[i - 1][1] + 1
    else:
        l[i][1] = 1

sortthird = lambda val: val[2]
l.sort(key = sortthird)

for i in l:
    ans = "0"*(6 - len(i[0])) + i[0] + "0"*(6 - len(str(i[1]))) + str(i[1])
    print(ans)

Submission status: Accepted

Solution code:
import bisect

N, M = map(int, input().split())  # 県数, 市数
birth_list = []  # 県番号, 誕生年のペア
pref_year_list = {}
for i in range(M):
    pi, yi = map(int, input().split())  # 市の県番号, 市の誕生年
    birth_list.append((pi, yi))
    if pi in pref_year_list:
        pref_year_list[pi].append(yi)
    else:
        pref_year_list[pi] = [yi]
for k in pref_year_list.keys():
    pref_year_list[k] = list(sorted(pref_year_list[k]))


for pi, yi in birth_list:
    # 県番号,年から登録順を逆引き
    year_list = pref_year_list[pi]
    i = bisect.bisect(year_list, yi)
    print("%06d%06d" % (pi, i))

Submission status: Accepted

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

PY.sort(key=lambda x:x[1],reverse=False)

KEN = [0]*N
SHIs = []

for i in range(M):
    P = PY[i][0]
    ind = PY[i][2]
    KEN[P-1] += 1
    X = KEN[P-1]
    S = str(P).zfill(6) + str(X).zfill(6)
    SHIs.append([S,ind])

SHIs.sort(key=lambda x:x[1],reverse=False)
for s in SHIs:
    print(s[0])

Submission status: Accepted

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

from collections import defaultdict
dict = defaultdict(list)
for i, (p, d) in enumerate(pd):
    dict[p].append((d, i))

ans = ['' for _ in range(m)]
for key in dict:
    v = dict[key]
    v.sort()

    for i, (y, idx) in enumerate(v):
        tmp = str(key).zfill(6) + str(i + 1).zfill(6)
        ans[idx] = tmp

for a in ans:
    print(a)

Submission status: Accepted

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


n, m = map(int, input().split())

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

x = 1
A[0].append(x)
for i in range(1, m):
    if A[i][0] == A[i - 1][0]:
        x += 1
    else:
        x = 1
    A[i].append(x)
A.sort(key = lambda x: x[2])

for a in A:
    p, x = a[0], a[3]
    print(format(p, "06") + format(x, "06"))

Submission status: Accepted

Solution code:
n, m = map(int, input().split())
ans = ['']*m
mat = [list(map(int, input().split())) for _ in range(m)]
d = {}
for idx in range(m):
    p, y = mat[idx]
    y = (y, idx)
    ans[idx] += str(p).zfill(6)
    if p in d:
        d[p].append(y)
    else:
        d[p] = [y]

for v in d.values():
    v.sort(key=lambda x: x[0])
    for i, (_, idx) in enumerate(v):
        i += 1
        ans[idx] += str(i).zfill(6)

for a in ans:
    print(a)

Submission status: Accepted

Solution code:
import bisect

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(bisect.bisect(PYd[p], y)).zfill(6)
    print(str_p+index)

Submission status: Accepted

Solution code:
from collections import defaultdict
import bisect

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

PY = []
PYd = defaultdict(list)

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(bisect.bisect(PYd[p], y)).zfill(6)
    print(str_p+index)

Submission status: Accepted

Solution code:
#import sys
#import numpy as np
#import math
#import itertools
#from fractions import Fraction
#import itertools
from collections import deque
#import heapq
#from fractions  import gcd
#input=sys.stdin.readline
n,m=map(int,input().split())
j=0
l=[[] for _ in range(n)]
ans=[0]*m
for i in range(m):
    p,y=map(int,input().split())
    l[p-1].append((i,y,p))
for i in range(n):
    l[i].sort(key=lambda x:x[1])
for i in range(n):
    for j in range(len(l[i])):
        ans[l[i][j][0]]='%012d' %(l[i][j][2]*10**6+j+1)
print(*ans)

Submission status: Accepted

Solution code:
import sys
import collections
sys.setrecursionlimit(10 ** 8)

def Z(): return int(input())
def ZZ(): return [int(_) for _ in input().split()]

def main():
    N, M = ZZ()
    a = collections.defaultdict(list)
    id = [''] * (M+1)
    for i in range(M):
        p, y = ZZ()
        a[p].append([y, i+1])
    for key in a.keys():
        a[key].sort()
        for j, al in enumerate(a[key], 1):
            y, i = al
            id[i] = '{:0=6}'.format(key) + '{:0=6}'.format(j)
    for i in range(1, M+1): print(id[i])

    return

if __name__ == '__main__':
    main()

Submission status: Accepted

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

N, M = map(int,input().split())
town = [[] for _ in range(N)]
ans = [0] * M

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

for i in range(N):
    town[i].sort()
    for k in range(len(town[i])):
        index = town[i][k][1]
        t = town[i][k][0]
        ans[index] = str(i+1).zfill(6) + str(k+1).zfill(6)

for i in ans:
    print(i)

Submission status: Accepted

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

N, M = map(int,input().split())
town = [[] for _ in range(N)]
ans = [0] * M

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

for i in range(N):
    town[i].sort()
    for k in range(len(town[i])):
        index = town[i][k][1]
        t = town[i][k][0]
        ans[index] = str(i+1).zfill(6) + str(k+1).zfill(6)

for i in ans:
    print(i)

Submission status: Accepted

Solution code:
n,m=map(int, input().split())
a=[list(map(int, input().split())) for _ in range(m)]
c=[0]*-~n
id={}
for p,y in sorted(a,key=lambda x:x[1]):
    c[p]+=1
    id[y]=str(p).zfill(6)+str(c[p]).zfill(6)
for _,y in a:
    print(id[y])

Submission status: Accepted

Solution code:
n,m=map(int, input().split())
a=[list(map(int, input().split())) for _ in range(m)]
c=[0]*-~n
id={}
for p,y in sorted(a,key=lambda x:x[1]):
    c[p]+=1
    id[y]=format(p,"06")+format(c[p],"06")
for _,y in a:
    print(id[y])

Submission status: Accepted

Solution code:
from collections import defaultdict

n, m = map(int, input().split())
PY = [tuple(map(int, input().split())) for _ in range(m)]
sorted_PY = sorted(PY)
cnt = 1
now = sorted_PY[0][0]
d = defaultdict(int)
for p, y in sorted_PY:
    if now != p:
        cnt = 1
        now = p
    d[y] = (p, cnt)
    cnt += 1

for p, y in PY:
    l, r = map(str, d[y])
    l = '0'*(6-len(l)) + l
    r = '0'*(6-len(r)) + r
    print(l+r)

Submission status: Accepted

Solution code:
import bisect

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 = bisect.bisect_right(d[p], y)
    print(str(p).zfill(6) + str(r).zfill(6))

Submission status: Accepted

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

from operator import itemgetter
PY= sorted(PY,key=itemgetter(1),reverse = False)
PY = sorted(PY,key=itemgetter(0),reverse = False)

B= []
pre = 0
city = 0
for i in range(M):
    if pre != PY[i][0]:
        pre =  PY[i][0]
        city = 1
        B.append([str(pre).rjust(6, '0') + str(city).rjust(6, '0') ,PY[i][2]])
    else:
        city += 1
        B.append([str(pre).rjust(6, '0') + str(city).rjust(6, '0') ,PY[i][2]])

B= sorted(B,key=itemgetter(1),reverse = False)        
for i in range(M):
    print(B[i][0])

Submission status: Accepted

Solution code:
from collections import defaultdict

n, m = map(int, input().split())
PY = [tuple(map(int, input().split())) for _ in range(m)]
sorted_PY = sorted(PY)
cnt = 1
now = sorted_PY[0][0]
d = defaultdict(int)
for p, y in sorted_PY:
    if now != p:
        cnt = 1
        now = p
    d[y] = (p, cnt)
    cnt += 1

for p, y in PY:
    l, r = map(str, d[y])
    if len(l) < 6:
        light = '0'*(6-len(l)) + str(l)
    else:
        light = str(l)
    if len(r) < 6:
        right = '0'*(6-len(r)) + str(r)
    else:
        right = str(r)
    print(light+right)

Submission status: Accepted

Solution code:
import bisect
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(bisect.bisect_right(k[p[i]-1], y[i])).zfill(6)
	ansl.append(d1+d2)
print("\n".join(ansl))

Submission status: Accepted

Solution code:
n,m=map(int,input().split())
d={i:[] for i in range(1,n+1)}
a=['' for i in range(m)]
for i in range(1,m+1):
    p,y=map(int,input().split())
    d[p].append([i,y])
#print(d)
for p,j in d.items():
    j.sort(key=lambda x:x[1])
    for i in range(len(j)):
        a[j[i][0]-1]=format(p,'0>6')+format(i+1,'0>6')
print(*a,sep='\n')

Submission status: Accepted

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


def read():
    N, M = map(int, input().strip().split())
    IPY = []
    for i in range(M):
        p, y = map(int, input().strip().split())
        IPY.append((i, p, y))
    return N, M, IPY


def solve(N, M, IPY):
    X = [1 for i in range(N+1)]
    IPY.sort(key=lambda ipy: ipy[2])
    zipcode = []
    for i, p, y in IPY:
        zipcode.append((i, p, X[p]))
        X[p] += 1
    zipcode.sort()
    for i, p, x in zipcode:
        print("{:06d}{:06d}".format(p, x))


if __name__ == '__main__':
    inputs = read()
    outputs = solve(*inputs)
    if outputs is not None:
        print("%s" % str(outputs))

Submission status: Accepted

Solution code:
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
from operator import itemgetter  
from collections import defaultdict
def main():
    n, m = map(int, readline().split())
    cities = []
    for i in range(m):
        p, y = map(int, readline().split())
        cities.append((i+1, p, y))
    cities.sort(key=itemgetter(2))
    dd = defaultdict(int)
    ansdd = defaultdict(str)
    for i in range(m):
        cid, p, y = cities[i]
        dd[p] += 1
        x = dd[p]
        ansdd[cid] = '{:0=6}'.format(p)+'{:0=6}'.format(x)
    for i in range(1, m+1):
        print(ansdd[i])
if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
from bisect import bisect_left
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(bisect_left(city_list[p], 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: Accepted

Solution code:
from bisect import bisect_left
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(bisect_left(city_list[p], city[i][1]))
    #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: Accepted

Solution code:
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
from itertools import permutations, accumulate, combinations, combinations_with_replacement
from math import sqrt, ceil, floor, factorial
from bisect import bisect_left, bisect_right, insort_left, insort_right
from copy import deepcopy
from operator import itemgetter
from functools import reduce, lru_cache  # @lru_cache(None)
from fractions import gcd
import sys
def input(): return sys.stdin.readline().rstrip()
def I(): return int(input())
def Is(): return (int(x) for x in input().split())
def LI(): return list(Is())
def TI(): return tuple(Is())
def IR(n): return [I() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def TIR(n): return [TI() for _ in range(n)]
def S(): return input()
def Ss(): return input().split()
def LS(): return list(S())
def SR(n): return [S() for _ in range(n)]
def SsR(n): return [Ss() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
sys.setrecursionlimit(10**6)
MOD = 10**9+7
INF = 10**18
# ----------------------------------------------------------- #

def compress(A):
    return {element: i+1 for i, element in enumerate(sorted(set(A)))}

n, m = Is()
PY = TIR(m)
A = [list() for _ in range(n+1)]
for p, y in PY:
    A[p].append(y)
B = [compress(a) for a in A]

for p, y in PY:
    ans = str(p).zfill(6) + str(B[p][y]).zfill(6)
    print(ans)

Submission status: Accepted

Solution code:
if __name__ == "__main__":
    N, M = map(int, input().split())
    T = []
    for i in range(M):
        p, y = map(int, input().split())
        T.append((p, y, i))
    T.sort()
    ID = []
    cp = -1
    count = -1
    for p, y, i in T:
        if p != cp:
            cp = p
            count = 1
        ID.append((i, "0"*(6-len(str(cp)))+str(cp)+"0"*(6-len(str(count)))+str(count)))
        count += 1
    ID.sort()
    for i , id in ID:
        print(id)

Submission status: Accepted

Solution code:
N, M = map(int, input().split())
cnt = [1 for _ in range(N)] #市の申請順を管理する
l = []

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

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

for i in range(M):
    p = l[i][0] #県
    x = str(cnt[p-1]) #市ができた順位
    cnt[p-1] += 1

    str_p = str(p)
    while len(str_p) != 6:
        str_p = "0" + str_p

    while len(x) != 6:
        x = "0" + x
    
    l[i][0] = str_p
    l[i][1] = x

l = sorted(l, key=lambda x:x[2])

for i, j, _ in l:
    print(i+j)

Submission status: Accepted

Solution code:
from collections import defaultdict
n, m = map(int, input().split())

d = defaultdict(list)
for i in range(m):
    p, y = map(int, input().split())
    d[p].append([i, y])

for i in range(1, n + 1):
    tmp = d[i]
    tmp.sort(key=lambda x: x[1])
    for i, j in enumerate(tmp):
        j.append(i + 1)

ans = []
for a, b in d.items():
    for i in b:
        i.append(a)
        ans.append(i)

for _, _, c, p in sorted(ans):
    print("{:06}{:06}".format(p, c))

Submission status: Accepted

Solution code:
from collections import defaultdict
d = defaultdict(list)


def sortpy(y):
    return {x: i for i, x in enumerate(sorted(y), 1)}


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

for p, y in py:
    d[p].append(y)

nd = {p: sortpy(y) for p, y in d.items()}

for p, y in py:
    print('{:06g}{:06g}'.format(p, nd[p][y]))

Submission status: Accepted

Solution code:
n, m = list(map(int, input().split()))
yp = []
for i in range(m):
  y, p = list(map(int, input().split()))
  yp.append([i+1, y, p])
  
yp.sort(key=lambda x: x[2])
counter = [1]*n
for i in range(m):
  num1 = "0"*(6-len(str(yp[i][1]))) + str(yp[i][1])
  junban = str(counter[yp[i][1]-1])
  counter[yp[i][1]-1] += 1
  num2 = "0"*(6-len(junban)) + junban
  yp[i].append(num1+num2)
  
yp.sort(key=lambda x: x[0])
for i in range(m):
  print(yp[i][3])

Submission status: Accepted

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

for i in range(m):
    x[i].append(i)

# 県ごとに格納
v=[[] for i in range(n+1)]
# 答えを格納
ans=[0 for i in range(m)]

for i in range(m):
    v[x[i][0]].append(x[i])

for i in range(n+1):
    v[i].sort()
#print(v)
for i in range(n+1):
    for j in range(len(v[i])):
        # 上６桁
        l=str(0)*(6-len(str(i)))+str(i)
        ans[v[i][j][2]]=l+str(0)*(6-len(str(j+1)))+str(j+1)

for i in range(m):
    print(ans[i])

Submission status: Accepted

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

P = []
Y = []

d = {}
ans = [0] * M
for i in range(1,N+1):
    d[i] = []

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

for k in d.keys():
    d[k] = sorted(d[k], key=lambda x: x[1])
    for i in range(len(d[k])):
        ans[d[k][i][0]] = '{}{}'.format(str(k).zfill(6),str(i+1).zfill(6))

for i in range(len(ans)):
    print(ans[i])

Submission status: Accepted

Solution code:
n, m = map(int, input().split())
cnt = [[] for _ in range(n + 1)]
for i in range(m):
    p, y = map(int, input().split())
    cnt[p].append((y, i))
buf = [None] * m
for p, l in enumerate(cnt):
    if not l:
        continue
    l.sort()
    for j, (y, i) in enumerate(l):
        buf[i] = '{:06d}{:06d}'.format(p, j + 1)
print('\n'.join(buf))

Submission status: Accepted

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

for i  in range(m):
    p,y = map(int,input().split())
    cnt[p].append((y,i))
buf = [None] * m
for p,l in enumerate(cnt):
    if not l:
        continue
    l.sort()
    for j,(y,i) in enumerate(l):
        buf[i] = '{:06d}{:06d}'.format(p,j + 1)
print('\n'.join(buf))

"""
n, m = map(int, input().split())
cnt = [[] for _ in range(n + 1)]
for i in range(m):
    p, y = map(int, input().split())
    cnt[p].append((y, i))
buf = [None] * m
for p, l in enumerate(cnt):
    if not l:
        continue
    l.sort()
    for j, (y, i) in enumerate(l):
        buf[i] = '{:06d}{:06d}'.format(p, j + 1)
print('\n'.join(buf))
"""

Submission status: Accepted

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

x = [[] for _ in range(N)]
a = [None] * M
for i in range(M):
    P, Y = map(int, input().split())
    x[P-1].append(Y)
    a[i] = (P, Y)

y = {}
for i in range(N):
    x[i].sort()
    for j, Y in enumerate(x[i]):
        y[(i+1, Y)] = j + 1
for i in range(M):
    print('{}{}'.format(str(a[i][0]).zfill(6), str(y[a[i]]).zfill(6)))

Submission status: Accepted

Solution code:
def mips():
  return map(int,input().split())
def rev(data):
    a = data[0]
    data[0] = data[1]
    data[1] = a
    return None
N,M = mips()
data = dict()
for i in range(M):
    pref,year = mips()
    if pref not in data:
        data[pref] = [[year,i+1,pref]]
    else:
        data[pref].append([year,i+1,pref])
ans = []
for pref in data:
    data[pref].sort()
    for i in range(len(data[pref])):
        data[pref][i][0] = i+1
        rev(data[pref][i])
        ans.append(data[pref][i])
ans.sort()
for i in range(M):
    ken = str(ans[i][2])
    when = str(ans[i][1])
    ken,when = format(ken,'0>6'),format(when,'0>6')
    print(ken+when)