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:
N, M = map(int,input().split())
PY = [list(map(int,input().split()))+[0] for _ in range(M)]
sort_PY = sorted(PY, key = lambda x:x[1])
city = {}
for i in range(M):
  p, y = sort_PY[i][0], sort_PY[i][1]
  if(p in city):
    city[p] += 1
  else:
    city[p] = 1
  sort_PY[i][2] = city[p]
for p, y, z in PY:
  print(str(p).zfill(6)+str(z).zfill(6))

Submission status: Accepted

Solution code:
#ABC113 C
#N個の県に合計M個の市がある
#市iが誕生したのはYi年で県Piに属する
#市iが県Piのなかでx番目に誕生しているとき,上6桁がPiで下6桁がxとなる番号を振りたい
#すべての市に認識番号を振り,iの順に出力せよ
#ただし市が1つも属さない県も存在しうる

#愚直な方針
#[i,Pi,Yi]を要素とする多重リストをつくる
N, M = map(int, input().split(' '))
city = []
for i in range(M):
	#[i,Pi,Yi]からなる多重リストをつくる
	city.append([i+1]+list(map(int, input().split(' '))))

#Pi->Yiの順番に多段階ソート (Piの数のオーダーは10**5)
from operator import itemgetter
city = sorted(city, key=itemgetter(1,2))

#各要素(=リスト)の末尾にxを追加する
#ただしxは要素をたどるごとに1ずつ増やしていくがPiが変わったら1にリセットする
x = 1
for n in range(M):
	if n==0:
		city[n].append(1)
	else:
		if city[n][1] != city[n-1][1]:
			x = 1
		else:
			x += 1
		city[n].append(x)			

#リストをふたたびiでソート
city = sorted(city, key=lambda l: l[0])

#認識番号をゼロパディングしてPi6桁+x6桁で出力
for c in city:
	print(str(c[1]).zfill(6) + str(c[3]).zfill(6))

Submission status: Accepted

Solution code:
N,M=map(int,input().split())
L=[list(map(int,input().split())) for i in range(M)]
for i in range(M):
    L[i].append(i)
L.sort(key=lambda x:x[1])
L.sort(key=lambda x:x[0])
city_num=1#
#12 to 1
#32 to 2
inside_num=1
for i in range(M):
    while L[i][0]!=city_num:
        city_num+=1
        inside_num=1
    L[i][1]=inside_num
    inside_num+=1
#print(L)
L.sort(key=lambda x:x[2])
for l in L:
    print("{:0=6}{:0=6}".format(l[0],l[1]))#0 padding

Submission status: Accepted

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

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

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

city_ids = ["" for i in range(M)]

for P in range(N):
    for x in range(len(cities[P])):
        P_str = str(P + 1)
        x_str = str(x + 1)
        if len(P_str) < 6:
            P_str = "0" * (6 - len(P_str)) + P_str
        if len(x_str) < 6:
            x_str = "0" * (6 - len(x_str)) + x_str
        city_ids[cities[P][x][1]] = P_str + x_str

for i in range(M):
    print(city_ids[i])

Submission status: Accepted

Solution code:
N, M = tuple(map(int,input().split()))
A =[]
for i in range(M):
    A.append(tuple(map(int,input().split())))
prev = [0,0]
dic ={}
for city,year in sorted(A):
    if city != prev[0]:
        prev[1] = 1
    dic[(city,year)] = prev[1]
    prev = [city,prev[1]+1]
for i in A:
    print(str.zfill(str(i[0]),6)+str.zfill(str(dic[i]),6))

Submission status: Accepted

Solution code:
n,m=map(int,input().split())
pys=[]
def make_number(p,x):
    return str(p*10**6+x).zfill(12)
for i in range(m):
    a,b=map(int,input().split())
    pys.append([a,b,i])
pys.sort()
ans=[i for i in range(m)]
c=-1
j=0
for [p,y,s] in pys:
    if c!=p:
        j=1
        c=p
    ans[s]=make_number(p,j)
    j+=1
for i in range(m):
    print(ans[i])

Submission status: Accepted

Solution code:
N, M = [int(x) for x in input().split()]
PY = [[x] + [int(y) for y in input().split()] + [""] for x in range(M)]
PY.sort(key=lambda x: x[2])

rd = [0]*(N+1)
for i, (x, p, y, s) in enumerate(PY):
    rd[p] += 1
    PY[i][3] = str(p).rjust(6, "0") + str(rd[p]).rjust(6, "0")

PY.sort(key=lambda x: x[0])
for py in PY:
    print(py[3])

Submission status: Accepted

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

cities = [[i, city[0], city[1]] for i, city in enumerate(cities)]
city_count = [0]*(N+1)
cities.sort(key=lambda x: x[2])
ids = []
for city in cities:
    city_count[city[1]] += 1
    ids.append([city[0], '{:0>6}{:0>6}'.format(city[1], city_count[city[1]])])
ids.sort(key=lambda x: x[0])
for city in ids:
    print(city[1])

Submission status: Accepted

Solution code:
from bisect import bisect_right
N,M=map(int,input().split())
PY=[]
record=[[] for i in range(N+1)]
for i in range(M):
    P,Y=map(int,input().split())
    PY.append([P,Y])
    record[P].append(Y)
for i in range(1,N+1):
    record[i].sort()
for i in range(M):
    p,y=PY[i][0],PY[i][1]
    order=bisect_right(record[p],y)
    print(str(p).zfill(6)+str(order).zfill(6))

Submission status: Accepted

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

pys.sort()
ans = []
cur = -1
j = 0
for (p,y,i) in pys:
    if cur != p:
        j = 1
        cur = p
    #print(p,y,i,j)
    ans.append((i,"{:0=6}".format(p) + "{:0=6}".format(j)))
    j = j + 1

ans.sort()
for (i, a) in ans:
    print(a)

Submission status: Accepted

Solution code:
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()
cnt = 1
a = 0
for i in range(M):
    if PY[i][0] == a: cnt += 1
    else: cnt = 1
    a = PY[i][0]
    PY[i][1] = cnt
PY.sort(key=lambda x: x[2])
for i in range(M):
    print(str(PY[i][0]).rjust(6,'0') + str(PY[i][1]).rjust(6,'0'))

Submission status: Accepted

Solution code:
def ans():
  N, M = map(int,input().split())
  PY = [list(map(int,input().split()))+[0] for _ in range(M)]
  sort_PY = sorted(PY, key = lambda x: x[1])
  city = {}
  for i in range(M):
    p, y, z = sort_PY[i][0], sort_PY[i][1], sort_PY[i][2]
    if(p in city):
      city[p] += 1
    else:
      city[p] = 1
    sort_PY[i][2] = city[p]
  for p, y, z in PY:
    print(str(p).zfill(6) + str(z).zfill(6))
ans()

Submission status: Accepted

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

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

def fill(t):
    s = str(t)
    while len(s) < 6:
        s = "0" + s
    return s

Pi.sort(key=lambda x: x[1])
counts = [1] * (N + 1)
for p in Pi:
    city = p[0]
    num = counts[city]
    counts[city] += 1
    p.append(fill(city) + fill(num))

Pi.sort(key=lambda x: x[2])
for p in Pi:
    print(p[3])

Submission status: Accepted

Solution code:
a,b=map(int,input().split())
l=[]
for _ in range(b):
    c,d=map(int,input().split())
    l.append((c,d))
l2=sorted(sorted(l, key=lambda x:x[1]), key=lambda y:y[0])
m=1
count=0
dic={}
for t in l2:
    if t[0] !=m:
        m=t[0]
        count=1
    else:
        count+=1
    dic[t]=count
#print(dic)
for q in l:
    print('{:06d}'.format(q[0])+'{:06d}'.format(dic[q]))

Submission status: Accepted

Solution code:
N,M = (int(x) for x in input().split())
p_arr = []
for _ in range(M):
    p_arr.append(tuple(int(x) for x in input().split()))

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

for i, (p, y) in enumerate(p_arr):
    P_dict[p].append((i+1, y))

P_rank_arr = [0]*(M+1)
for k in P_dict.keys():
    P_dict[k].sort(key=lambda x:x[1])
    for n, (i, _) in enumerate(P_dict[k]):
        P_rank_arr[i] = n+1

for i, (n, _) in enumerate(p_arr):
    print("{:06d}{:06d}".format(n, P_rank_arr[i+1]))

Submission status: Accepted

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

for i in range(m):
  p,y=map(int,input().split())
  a[p-1].append((y,i))
  
for i,b in enumerate(a):
  b.sort()
  for j,(y,k) in enumerate(b):
    ans[k]='%06d%06d' % (i+1,j+1)
    
print(*ans,sep='\n')

Submission status: Accepted

Solution code:
def identify(N: int, M: int, PY: list) -> list:
    _PY = [(i, p, y) for i, (p, y) in enumerate(PY)]
    _PY.sort(key=lambda x: x[2])
    _PY.sort(key=lambda x: x[1])

    now_p = 0
    now_o = 1
    ids = []
    for i, p, _ in _PY:
        if p != now_p:
            now_p = p
            now_o = 1
        ids.append((i, '{p:06}{o:06}'.format(p=p, o=now_o)))
        now_o += 1

    return [i for _, i in sorted(ids, key=lambda x: x[0])]


if __name__ == "__main__":
    N, M = map(int, input().split())
    PY = [tuple(int(s) for s in input().split()) for _ in range(M)]
    for ans in identify(N, M, PY):
        print(ans)

Submission status: Accepted

Solution code:
import sys
N,M = map(int,input().split())
data = [[i,list(map(int,sys.stdin.readline().rstrip().split()))] for i in range(M)]

# print(data)
sortdata = sorted(data, key=lambda data:data[1])
# print(sortdata)

cnt = 1
sortdata[0].append(1)
for i in range(1,M):
    if sortdata[i][1][0] == sortdata[i-1][1][0]:
        cnt += 1
    else:
        cnt = 1
    sortdata[i].append(cnt)

sortdata = sorted(sortdata, key=lambda data:data[0])
for i in range(M):
    print(str(sortdata[i][1][0]).rjust(6,'0'),end = "")
    print(str(sortdata[i][2]).rjust(6,'0'))

Submission status: Accepted

Solution code:
N,M = map(int,input().split())
P=[]
for _ in range(M):
  p,y = map(int,input().split())
  P.append((p,y))
d = {}
for p,y in P:
  if p not in d:
    d[p]=[]
  d[p].append(y)
sd = {k:dict(zip(sorted(v),range(1,1+len(v))))
      for k,v in d.items()}
for p,y in P:
  print('%06d%06d' % (p, sd[p][y]))

Submission status: Accepted

Solution code:
import sys

input = sys.stdin.readline

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

Pm = [0] * M
Ym = [0] * M
ym = [0] * M

Am = [[0 for i in range(2)] for j in range(M)]
Cn = [0] * N

D = {}

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

    Pm[i], Ym[i] = P, Y

    ym[i] = Y

    D[Y] = i

ym.sort()

for i in range(M):
    k = D[ym[i]]

    # 0-indexed
    Cn[Pm[k] - 1] += 1
    Am[k] = [Pm[k], Cn[Pm[k] - 1]]

for i in range(M):
    print('{:06d}{:06d}'.format(Am[i][0], Am[i][1]))

Submission status: Accepted

Solution code:
import sys

input = sys.stdin.readline

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

Pm = [0] * M
Ym = [0] * M
ym = [0] * M

Am = [''] * M
Cn = [0] * N

D = {}

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

    Pm[i], Ym[i] = P, Y

    ym[i] = Y

    D[Y] = i

ym.sort()

for i in range(M):
    k = D[ym[i]]

    # 0-indexed
    Cn[Pm[k] - 1] += 1
    Am[k] = str(Pm[k]).rjust(6, '0') + str(Cn[Pm[k] - 1]).rjust(6, '0')

for i in range(M):
    print(Am[i])

Submission status: Accepted

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

Pm = [0] * M
Ym = [0] * M
ym = [0] * M

Am = [''] * M
Cn = [0] * N

D = {}

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

    Pm[i], Ym[i] = P, Y

    ym[i] = Y

    D[Y] = i

ym.sort()

for i in range(M):
    k = D[ym[i]]

    # 0-indexed
    Cn[Pm[k] - 1] += 1
    Am[k] = str(Pm[k]).rjust(6, '0') + str(Cn[Pm[k] - 1]).rjust(6, '0')

for i in range(M):
    print(Am[i])

Submission status: Accepted

Solution code:
N, M = map(int,input().split())
C=[0 for _ in range(M)]
count = [0 for _ in range(N)]
for i in range(M):
  p,y = map(int,input().split())
  C[i] = [i, p, y, 0]

C.sort(key = lambda x:x[2])
for i in C:
  count[i[1]-1] +=1
  i[3] = count[i[1]-1]
for i in sorted(C,key = lambda x:x[0]):
  print("{:06d}{:06d}".format(i[1],i[3]))

Submission status: Accepted

Solution code:
N, M = map(int, input().split())
P = [[] for i in range(N)]
data = []
for i in range(M):
    p, y = map(int, input().split())
    data.append([p, y, i])

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

city = 0
for i in range(M):
    if data[i][0] != city:
        city = data[i][0]
        num = 1
    data[i][1] = num
    num += 1
    

data.sort(key=lambda x:x[2])
for d in data:
    print("{:0=6}{:0=6}".format(d[0],d[1]))

Submission status: Accepted

Solution code:
N, M = map(int, input().split())
py_list = [[int(py) for py in input().split()] for i in range(M)]
order_city = [[] for _ in range(N)]
for i, py in enumerate(py_list):
    order_city[py[0]-1].append((i, py[1]))

ans_list = [None]*M

for p, cities in enumerate(order_city):
    for i, city in enumerate(sorted(cities, key=lambda x: x[1])):
        ans_list[city[0]] = "{0:06d}{1:06d}".format(p+1, i+1)

ans = ""
for i in ans_list:
    ans += i+"\n"
 
print(ans[:-1])

Submission status: Accepted

Solution code:
N, M = map(int, input().split())
py_list = [[int(py) for py in input().split()] for i in range(M)]
order_city = [[] for _ in range(N)]
for i, py in enumerate(py_list):
    order_city[py[0]-1].append((i, py[1]))

ans_list = [None]*M

for p, cities in enumerate(order_city):
    for i, city in enumerate(sorted(cities, key=lambda x: x[1])):
        ans_list[city[0]] = "{0:06d}{1:06d}".format(p+1, i+1)
        
for ans in ans_list:
    print(ans)

Submission status: Accepted

Solution code:
from collections import defaultdict
from bisect import bisect_left
N, M = map(int, input().split())
A = []
B = defaultdict(list)
 
for i in range(M):
    p, y = map(int, input().split())
    A.append([p, y])
    B[p].append(y)
 
for key in B.keys():
    B[key].sort()

# print(A,B)
# for a in A:
#     print(a[0],a[1],B[a[0]],bisect_left(B[a[0]],a[1]))
for a in A:
    print("%06d%06d" % (a[0], bisect_left(B[a[0]], a[1])+1))

Submission status: Accepted

Solution code:
N, M = map(int, input().split())
P, Y = zip(*(map(int, input().split()) for _ in range(M)))
ans = ['' for _ in range(M)]
c = [1 for _ in range(N + 1)]

for i, t in sorted(enumerate(zip(P, Y)), key=lambda x: x[1][1]):
  ans[i] = '{:06}{:06}'.format(t[0], c[t[0]])
  c[t[0]] += 1
  
print('\n'.join(ans))

Submission status: Accepted

Solution code:
n,m=map(int, input().split())
pre=[0]*n
c=[[j]+[int(i) for i in input().split()] for j in range(m)]
c=sorted(c, key=lambda city: city[2])
newc=[]
for ci in c:
    pre[ci[1]-1]+=1
    newc.append(ci+[pre[ci[1]-1]])
newc=sorted(newc, key=lambda city: city[0])
for city in newc:
    p=str(city[1])
    cnt=str(city[3])
    ans='0'*(6-len(p))+p+'0'*(6-len(cnt))+cnt
    print(ans)

Submission status: Accepted

Solution code:
N, M = map(int, input().split())
P, Y = zip(*(map(int, input().split()) for _ in range(M)))
ans = ['' for _ in range(M)]
c = [1 for _ in range(N + 1)]
for i, t in sorted(enumerate(zip(P, Y)), key=lambda t: t[1][1]):
    ans[i] = '{:06}{:06}'.format(t[0], c[t[0]])
    c[t[0]] += 1
print('\n'.join(ans))

Submission status: Accepted

Solution code:
import collections,bisect
N,M=map(int,input().split())
PY=[list(map(int,input().split())) for i in range(M)]
x=collections.defaultdict(list)
for city,year in sorted(PY):
    x[city]+=[year]
for city,year in PY:
    num=bisect.bisect(x[city],year)
    print("%06d%06d"%(city,num))

Submission status: Accepted

Solution code:
from operator import itemgetter
N,M = map(int,input().split())
S = [list(map(int,input().split()))+[i] for i in range(M)]

S.sort(key=itemgetter(1))
S.sort(key=itemgetter(0))
p = 0
m = 0
j = 1
while m < M:
    if S[m][0] == p:
        S[m][1] = j
        j += 1
        m += 1
    else:
        p += 1
        j = 1
        continue
S.sort(key=itemgetter(2))
for i in range(M):
    print(str(S[i][0]).zfill(6)+str(S[i][1]).zfill(6))

Submission status: Accepted

Solution code:
ri = lambda: int(input())
rl = lambda: list(map(int,input().split()))
rr = lambda N: [ri() for _ in range(N)]
YN = lambda b: print('YES') if b else print('NO')
INF = 10**18

N,M=rl()
P=[0]*M
Y=[0]*M
dic = [[] for _ in range(N+1)]
for i in range(M):
    P[i],Y[i] = rl()
    dic[P[i]] += [Y[i]]

for i in range(N+1):
    dic[i].sort()

import bisect
for i in range(M):
    print("{:0>6}{:0>6}".format(P[i], bisect.bisect_left(dic[P[i]],Y[i])+1))

Submission status: Accepted

Solution code:
import math, string, itertools, fractions, heapq, collections, re,  array, bisect, sys, random, time, copy, functools


sys.setrecursionlimit(10**7)
inf = 10 ** 20
eps = 1.0 / 10**10
mod = 10**9+7
dd = [(-1, 0), (0, 1), (1, 0), (0, -1)]
ddn = [(-1, 0), (-1, 1), (0, 1), (1, 1), (1, 0), (1, -1), (0, -1), (-1, -1)]


def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def pf(s): return print(s, flush=True)


N, M = LI()
P, Y = [], []
for i in range(M):
    j, k = LI()
    P.append(j)
    Y.append(k)

#  N = 10**5
#  M = 10**5
#  P, Y = [], []
#  for i in range(M):
#      P.append(10)
#      Y.append(i*100)

city_records = [[]for i in range(10**6)]
for p, y in zip(P, Y):
    #  print('p,y', p, y)
    #  print('city_records[p]', city_records[p])
    city_records[p].append(y)

#  print(city_records)

for i in range(len(city_records)):
    if city_records[i] == []:
        continue
    city_records[i].sort()

#  print(city_records)

for p, y in zip(P, Y):
    #  order = (city_records[p].index(y)) + 1
    order = bisect.bisect_left(city_records[p], y) + 1
    print(str(p).zfill(6) + str(order).zfill(6))

Submission status: Accepted

Solution code:
import collections,bisect
N,M=map(int,input().split())
PY=[list(map(int,input().split())) for i in range(M)]
a=collections.defaultdict(list)
for city,year in sorted(PY):a[city]+=[year]
for city,year in PY:
    z=bisect.bisect(a[city],year)
    print("%06d%06d"%(city,z))

Submission status: Accepted

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

for i in range(m):
	a[i].append(i)
b = sorted(a)

count = 1

for i in range(m):
	temp = b[i][2]
	b[i].pop(2)
	b[i].insert(0, temp)
	b[i].append(count)
	count += 1
	if i == m - 1:
		continue
	if b[i][1] != b[i + 1][0]:
		count = 1
b.sort()
for i in range(m):
	print(str(b[i][1]).zfill(6) + str(b[i][-1]).zfill(6))

Submission status: Accepted

Solution code:
N,M=map(int,input().split())
L=[[] for i in range(N+1)]
A=[]
for i in range(M):
  P,Y=map(int,input().split())
  L[P].append([i,Y])
for i in range(1,N+1):
  li=sorted(L[i],key=lambda x:x[1])
  k=0
  for city in li:
    k+=1
    A.append([city[0],str(i).zfill(6)+str(k).zfill(6)])
A.sort(key=lambda x:x[0])
for item in A:
  print(item[1])

Submission status: Accepted

Solution code:
import sys
import random

def rd():
        return sys.stdin.readline().rstrip()

def rdi():
        return [ int(x) for x in rd().split() ]


N, M = rdi()

PY = []
for i in range(M):
        p, y = rdi()
        PY.append( (p, y, i) )

spy = sorted(PY)

codes = []
lastp = -1
pj = 0
for k in range(M):
        p, y, i = spy[k]
        if p != lastp:
                lastp = p
                cj = 1
        else:
                cj = cj + 1
        code = "%06d%06d" % (int(p), cj)
        codes.append( (i, code) )

codes = sorted(codes)

for i in range(M):
        print codes[i][1]

Submission status: Accepted

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

l = []
ans = [0] * m

for i in range(m):
    l.append([int(j) for j in input().split()])
    l[i].append(i)

#[県, 市, 元の順番]
l2 = sorted(l, key=lambda x:(x[0],x[1]))
cnt = 1

for i in range(m):
    
    l2[i][1] = cnt
    
    if i < m -1 and l2[i][0] == l2[i + 1][0]:
        cnt += 1
    else:
        cnt = 1

    ans[l2[i][2]] = '{:06}{:06}'.format(l2[i][0],l2[i][1])

for s in ans:
    print(s)

Submission status: Accepted

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

citys.sort(key = lambda x:x[1])
nums = [0]*(N+1)
states = [None]*M

for p,y,i in citys:
    nums[p] += 1
    states[i] = [str(p), str(nums[p])]

for s in states:
    print(s[0].zfill(6)+s[1].zfill(6))

Submission status: Accepted

Solution code:
import copy
n,m = map(int, input().split())
town = [[] for _ in range(n+1)]
for i in range(m):
  p,y = map(int, input().split())
  town[p].append((i,y))
res = []
for i in range(1,n+1):
  tw = copy.copy(town[i])
  for j,x in enumerate(sorted(tw, key=lambda x: x[1])):
    res.append((x[0],str(i).zfill(6)+str(j+1).zfill(6)))

for x in sorted(res, key=lambda x: x[0]):
  print(x[1])

Submission status: Accepted

Solution code:
import numpy as np


def solve(string):

    n, m, *py = map(int, string.split())
    py = [(_p, _y) for _p, _y in zip(py[0::2], py[1::2])]
    p = [[] for _ in range(n)]
    for _p, _y in py:
        p[_p - 1].append(_y)
    for i in range(n):
        p[i] = np.argsort(np.argsort(p[i]))

    counter = [0 for _ in range(n)]
    ans = []
    for _p, _y in py:
        ans.append("{:06}{:06}".format(_p, p[_p - 1][counter[_p - 1]] + 1))
        counter[_p - 1] += 1
    return "\n".join(ans)


if __name__ == '__main__':
    n, m = map(int, input().split())
    print(solve("{} {}\n".format(n, m) + "\n".join([input() for _ in range(m)])))

Submission status: Accepted

Solution code:
import numpy as np


n, m = map(int, input().split())
py = [list(map(int, input().split())) for _ in range(m)]
p = [[] for _ in range(n)]
for _p, _y in py:
    p[_p - 1].append(_y)
for i in range(n):
    p[i] = np.argsort(np.argsort(p[i]))

counter = [0 for _ in range(n)]
for _p, _y in py:
    t = "{:06}{:06}".format(_p, p[_p - 1][counter[_p - 1]] + 1)
    print(t)
    counter[_p - 1] += 1

Submission status: Accepted

Solution code:
#encoding:utf-8

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

city_tb_ = sorted(city_tb,key=lambda x:x[1])
# print(city_tb_)

count_cities = [0 for i in range(n+1)]
city_cla = {}
for i in range(m):
    count_cities[city_tb_[i][0]] += 1
    city_cla[str(city_tb_[i][0])+str(city_tb_[i][1])]='{:06d}'.format(city_tb_[i][0])+'{:06d}'.format(count_cities[city_tb_[i][0]])

for i in range(m):
    print(city_cla[str(P[i])+str(Y[i])])

Submission status: Accepted

Solution code:
import bisect

N,M=map(int,input().split())
lists=[list(map(int,input().split())) for _ in range(M)]
dict={}

for l in lists:
    if l[0] not in dict.keys():
        dict[l[0]]=[l[1]]
    else:
        dict[l[0]].append(l[1])

for d in dict.values():
    d.sort()

for l in lists:
    print(str(l[0]).zfill(6)+str(bisect.bisect_right(dict[l[0]],l[1])).zfill(6))

Submission status: Accepted

Solution code:
#ABC113C-ID.py

from sys import stdin

input = stdin.readline

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

Info = []

for i in range(M):
    s = input().split()
    Info.append([i, int(s[0]), int(s[1]), s[0], 'a'])
    while len(Info[i][3]) < 6:
        Info[i][3] = '0' + Info[i][3]

Info.sort(key=lambda x: (x[1],x[2]))

j = 0
k = Info[0][1]
for i in range(M):
    if k == Info[i][1]:
        j += 1
        Info[i][4] = str(j)
        while len(Info[i][4]) < 6:
            Info[i][4] = '0' + Info[i][4]
    else:
        k = Info[i][1]
        j = 1
        Info[i][4] = str(j)
        while len(Info[i][4]) < 6:
            Info[i][4] = '0' + Info[i][4]

Info.sort()

for i in range(M):
    print(Info[i][3] + Info[i][4])

Submission status: Accepted

Solution code:
def search(l,x):
    min_ = 0
    max_ = len(l) - 1
    k = int((min_+max_)/2)
    while(abs(min_-max_) > 1):
        if l[k] > x:
            max_ = k
        elif l[k] < x:
            min_ = k
        else:
            max_ = k
            min_ = k
            break

        k = int((min_+max_)/2)

    if l[max_] == x:
        return max_
    return min_


#print(search([1,5,6,8,12,17,100,101,150],101))
N,M = (int(i) for i in input().split())  

kens = []
ps = [0] * M
ys = [0] * M
for _ in range(N):
    kens.append([])
for i in range(M):
    p,y = (int(i) for i in input().split())
    ps[i] = p
    ys[i] = y
    kens[p-1].append(y)

#print(len(kens))
kens_s = [0] * N
for i in range(N):
    kens_s[i] = sorted(kens[i])

for i in range(M):
    #print(ps[i]-1)
    num = search(kens_s[ps[i]-1],ys[i]) + 1
    print('{0:06d}'.format(ps[i]) + '{0:06d}'.format(num))

Submission status: Accepted

Solution code:
N,M=map(int,input().split())
p_y=[]
for i in range(M):
    p,y=map(int,input().split())
    p_y.append([i+1,p,y])

p_c=[0]*N
p_y.sort(key=lambda x:x[2])
for k,a in enumerate(p_y):
    p_c[a[1]-1]+=1
    p_y[k].append(p_c[a[1]-1])
p_y.sort(key=lambda x:x[0])
for b in p_y:
    print(str(b[1]).zfill(6)+str(b[3]).zfill(6))

Submission status: Accepted

Solution code:
N,M=map(int,input().split())
p_y=[]
for i in range(M):
    p,y=map(int,input().split())
    p_y.append([i+1,p,y])

p_count=[0]*N
p_y.sort(key=lambda x:x[2])
for num,a in enumerate(p_y):
    p_count[a[1]-1]+=1
    p_y[num].append(p_count[a[1]-1])
p_y.sort(key=lambda x:x[0])
for b in p_y:
    print(str(b[1]).zfill(6)+str(b[3]).zfill(6))

Submission status: Accepted

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

class ID:
    def __init__(self,p,y,i):
        self.p = p
        self.y = y
        self.i = i
        self.ID1 = None
        self.ID2 = None

    def ID(self):
        for i in range(1,7):
            if self.ID1 < 10**i:
                self.ID1 = "0"*(6-i) + str(self.ID1)
                break
        for i in range(1,7):
            if int(self.ID2) < 10**i:
                self.ID2 = "0"*(6-i) + str(self.ID2)
                break
        
        return self.ID1 + self.ID2

cities = []
for i in range(0,M):
    P,Y = map(int,input().split())
    cities.append(ID(P,Y,i))
cities.sort(key = lambda x: x.y)
counter = [-1]

for i in range(0,N):
    counter.append(1)

for c in cities:
    c.ID1 = c.p
    c.ID2 = counter[c.p]
    counter[c.p] = counter[c.p] + 1

cities.sort(key = lambda x: x.i)

for i in range(0,M):
    print(cities[i].ID())

Submission status: Accepted

Solution code:
N, M = map(int, input().split())
dic = {}
cnt = [1]*N
for m in range(M):
  dic[m] = list(map(int, input().split()))
l = sorted([d for d in dic.items()], key=lambda x:x[1][1])
for m in range(len(l)):
  l[m][1].append(cnt[l[m][1][0]-1])
  cnt[l[m][1][0]-1] += 1
for d in dic.values():
  print("{:06d}{:06d}".format(d[0], d[2]))

Submission status: Accepted

Solution code:
n,m=map(int, input().split())
l=[]
for i in range(m):
    l.append(list(map(int, input().split())))
    l[i].append(i)
l.sort(key=lambda x:(x[0],x[1]))
t=1
l[0].append(str(l[0][0]).zfill(6)+str(1).zfill(6))
for i in range(1,m):
    if l[i][0]>l[i-1][0]:
        t=1
        l[i].append(str(l[i][0]).zfill(6)+str(1).zfill(6))
    else:
        t+=1
        l[i].append(str(l[i][0]).zfill(6)+str(t).zfill(6))

l.sort(key=lambda x:x[2])
for i in range(m):
    print(l[i][3])

Submission status: Accepted

Solution code:

# coding: utf-8

# In[133]:


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

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


# In[134]:


data.sort(key= lambda x: x[1])
data.sort()


# In[135]:


num = 1

for i in range(m):
    if i == 0:
        data[i][1] = num
        num += 1
    else:
        if data[i][0] == data[i-1][0]:
            data[i][1] = num
            num += 1
        else:
            data[i][1] = 1
            num = 2


# In[136]:


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


# In[137]:


for i in range(m):
    p = str(data[i][0]).zfill(6)
    num = str(data[i][1]).zfill(6)
    print(p+num)

Submission status: Accepted

Solution code:
from collections import defaultdict
from bisect import bisect_left

N, M = map(int, input().split())
A = []
B = defaultdict(list)

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

for key in B.keys():
    B[key].sort()

for a in A:
    print("%06d%06d" % (a[0], bisect_left(B[a[0]], a[1])+1))

Submission status: Accepted

Solution code:
import numpy as np

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

order = (np.array(Y)).argsort()
n_list = [0]*N
m_list = [0]*M
for i in order:
  n_list[P[i]-1]+=1
  m_list[i] = n_list[P[i]-1]
  
for i in range(M):
  l = len(str(P[i]))
  pi = "0"*(6-l)+str(P[i])
  lx = len(str(m_list[i]))
  x = "0"*(6-lx)+str(m_list[i])
  print(pi+x)

Submission status: Accepted

Solution code:
n, m = map(int, input().split())
# 県の個数, 市の個数
py = []
for i in range(m):
    p, y = map(int, input().split())
    py.append((i, p, y))


py.sort(key=lambda tup: tup[2])
# 年でsort
#print(py)

c = {}
newpy = []
for i in py:
    index = i[0]
    ken = i[1]
    year = i[2]
    if ken in c:
        c[ken] += 1
        order = c[ken]
    else:
        c[ken] = 1
        order = 1
    newpy.append((index, ken, order))
#print(c)

newpy.sort(key=lambda tup: tup[0])
#print(newpy)
for i in newpy:
    print("{:0=6}{:0=6}".format(i[1], i[2]))

Submission status: Accepted

Solution code:
N, M = map(int, input().split())
A = []
B = []
for i in range(M):
    p, y = map(int, input().split())
    A.append([p, y, i])
A.sort()

cur = 1
cnt = 1
for i in range(M):
    if A[i][0] == cur:
        A[i].append(cnt)
        cnt += 1
    else:
        cur = A[i][0]
        cnt = 1
        A[i].append(cnt)
        cnt += 1
A.sort(key=lambda x: x[2])

for a in A:
    print("%06d%06d" % (a[0], a[3]))

Submission status: Accepted

Solution code:
n, m = map(int, input().split())
inputs = []
for i in range(m):
  p, y = map(int, input().split())
  inputs.append([i, p, y, 0])

inputs = sorted(inputs, key = lambda i:i[2])
count = [0 for i in range(n)]
for i in inputs:
  count[i[1]-1] += 1
  i[3] = count[i[1]-1]

inputs = sorted(inputs, key = lambda i:i[0])

for i in inputs:
  print('{0[1]:06}{0[3]:06}'.format(i))

Submission status: Accepted

Solution code:
N,M = list(map(int,input().split()))
l=[]
for i in range(M):
    l.append(list(map(int,input().split())))
for j in range(M):
    l[j].append(j)
l.sort(key=lambda x:(x[0],x[1]))

l[0].append(1)
for k in range(1,M):
    if l[k][0] == l[k-1][0]:
        l[k].append(l[k-1][3]+1)
    else:
        l[k].append(1)

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

for m in range(M):
    s='00000' + str(l[m][0])
    t='00000' + str(l[m][3])
    print(s[len(s)-6:len(s)]+t[len(t)-6:len(t)])

Submission status: Accepted

Solution code:
n, m = map(int, input().split())
tmp = [list(map(int, input().split())) for i in range(m)]
city = [[] for i in range(n+1)]
answers = [''] * m

for i, (pref, year) in enumerate(tmp):
    city[pref].append([year, i])

for i in range(n+1):
    for j, (year, index) in enumerate(sorted(city[i])):
        ans = str(i).zfill(6) + str(j+1).zfill(6)
        answers[index] = ans

print(*answers, sep='\n')