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())
pref_and_year = []
for i in range(M):
    p, y = map(int, input().split())
    pref_and_year.append((p, y))

sorted_indices = sorted(range(len(pref_and_year)),
                        key=lambda k: pref_and_year[k][1])
sorted_perf_and_year = sorted(pref_and_year, key=lambda x: x[1])
count = [0] * N
res = []
for i, x in zip(sorted_indices, sorted_perf_and_year):
    count[x[0]-1] += 1
    auth_number = str(x[0]).zfill(6) + str(count[x[0]-1]).zfill(6)
    res.append((i, auth_number))
res = sorted(res, key=lambda x: x[0])
for x in res:
    print(x[1])

Submission status: Accepted

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

sorted_indices = sorted(range(len(pref_and_year)),
                        key=lambda k: pref_and_year[k][1])
sorted_perf_and_year = sorted(pref_and_year, key=lambda x: x[1])
count = [0 for _ in range(N)]
res = []
for i, x in zip(sorted_indices, sorted_perf_and_year):
    count[x[0]-1] += 1
    auth_number = str(x[0]).zfill(6) + str(count[x[0]-1]).zfill(6)
    res.append((i, auth_number))
res = sorted(res, key=lambda x: x[0])
for x in res:
    print(x[1])

Submission status: Accepted

Solution code:
N, M = map(int, input().split())
lst = list()
for i in range(M):
    P, Y = map(int, input().split())
    lst.append((Y, i, P))
lst.sort()

cnt = [1] * (N + 1)
ans = list()
for Y, i, P in lst:
    id = str(P).zfill(6) + str(cnt[P]).zfill(6)
    cnt[P] += 1
    ans.append((i, id))
ans.sort()
for i, id in ans:
    print(id)

Submission status: Accepted

Solution code:
N, M = map(int, input().split())
L = []
for i in range(M):
  P, Y = map(int, input().split())
  L.append((P, Y, i))
ans = ['']*(M)
L.sort(key=lambda x:(x[0], x[1]))
before = L[0][0]
num = 0
for i in range(M):
  if L[i][0] == before:
    num += 1
    id = '{:06d}'.format(L[i][0]) + '{:06d}'.format(num)
    ans[L[i][2]] = id
  else:
    num = 1
    id = '{:06d}'.format(L[i][0]) + '{:06d}'.format(num)
    ans[L[i][2]] = id
    before = L[i][0]
for city in ans:
  print(city)

Submission status: Accepted

Solution code:
N, M = map(int, input().split())
cities = []
for i in range(0, M):
	P, Y = map(int, input().split())
	cities.append([i, P, Y])
cities.sort(key = lambda v: v[2])
cities.sort(key = lambda v: v[1])
idkeylist = [[cities[0][0], cities[0][1], 1]]
cnt = 2
for i in range(1, M):
	if cities[i][1] != idkeylist[-1][1]:
		idkeylist.append([cities[i][0], cities[i][1], 1])
		cnt = 2
	else:
		idkeylist.append([cities[i][0], cities[i][1], cnt])
		cnt += 1
idkeylist.sort(key = lambda v: v[0])
for i in range(0, M):
	ansP = str(idkeylist[i][1])
	while len(ansP) < 6:
		ansP = '0' + ansP
	ansT = str(idkeylist[i][2])
	while len(ansT) < 6:
		ansT = '0' + ansT
	print(ansP+ansT)

Submission status: Accepted

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

l.sort(key=lambda x:(x[0],x[1]))
#print(l)

ans = []
cnt = 1
for i in range(m):
    number = '{:0=6}'.format(l[i][0])
    if i == 0:
        cnt = 1
    else:
        if l[i-1][0]==l[i][0]:
            cnt += 1
        else:
            cnt = 1
    number += '{:0=6}'.format(cnt)
    ans.append([number,l[i][2]])
    
ans.sort(key=lambda x:x[1])
#print(ans)

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

Submission status: Accepted

Solution code:
import numpy as np

n,m = map(int,input().split())
d = {}
ans = ["" for i in range(m)]

for i in range(m):
    p,y = map(int,input().split())
    if p not in d:
        d[p] = [[y,i]]
    else:
        d[p].append([y,i])
for key in d.keys():
    temp = d[key]
    temp.sort(key=lambda x:x[0])
    city = key
    if len(list(str(city))) < 7:
        city = "0" * (6 - len(list(str(city)))) + str(city)
    for i in range(len(temp)):
        if len(list(str(i+1))) < 7:
            y = "0"*(6-len(list(str(i+1))))+str(i+1)
            # print(len(list(str(i))))
        ans[temp[i][1]] = city+y

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

Submission status: Accepted

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

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

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

city = [1] * (n + 1)
for i in range(m):
    (i, c, y) = dat[i]
    r = city[c]
    city[c] += 1
    res[i] = "%06d%06d" % (c, r)

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

Submission status: Accepted

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

n, m = map(int, input().split())
l = []
num = [0] * n
ans = [""] * m

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

l.sort()


for p, y, i in l:
    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
n,m=map(int,input().split())
if m==1:
  a,b=map(int,input().split())
  print(str(a).zfill(6)+str(m).zfill(6));sys.exit()
cities=[None]*m
for i in range(m):
  p,y=map(int,input().split())
  cities[i]=[p,y,i]
cities.sort(key=lambda x:x[1]);cities.sort(key=lambda x:x[0])
i=0
c=1
while True:
  cities[i].append(c)
  c+=1
  if i!=m-1 and cities[i][0]!=cities[i+1][0]:c=1
  elif i==m-1:break
  i+=1
cities.sort(key=lambda x:x[2])
for i in cities:
  print(str(i[0]).zfill(6)+str(i[3]).zfill(6))

Submission status: Accepted

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

yp_dic={}
yplist=[]
for i in range(M):
  p,y=map(int,input().split())
  if p not in yp_dic:
    yp_dic[p]=[]
  yp_dic[p].append(y)
  yplist.append((y,p))

all_dic={}
for key in yp_dic:
  yp_dic[key].sort()
  for i,y in enumerate(yp_dic[key]):
    all_dic[y]=i+1

#print(all_dic)
for y,p in yplist:
  id="{:0>6}{:0>6}".format(p,all_dic[y])
  print(id)
  #print(y,p,all_dic[p][y])

Submission status: Accepted

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

p_count = [1] * (N + 1)
for r in sorted(pairs, key=lambda x: x[1]):
    r.append("{:06d}{:06d}".format(r[0], p_count[r[0]]))
    p_count[r[0]] += 1

print("\n".join((r[2] for r in pairs)))

Submission status: Accepted

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

p_count = [1] * (N + 1)
for r in sorted(pairs, key=lambda x: x[1]):
    r.append("{:06d}{:06d}".format(r[0], p_count[r[0]]))
    p_count[r[0]] += 1

for r in pairs:
    print(r[2])

Submission status: Accepted

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

yp_dic={}
yplist=[]
for i in range(M):
  p,y=map(int,input().split())
  if p not in yp_dic:
    yp_dic[p]=[]
  yp_dic[p].append(y)
  yplist.append((y,p))

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

#print(yp_dic)
all_dic={}
for pref,ylist in yp_dic.items():
  pref_dic={}
  for i,y in enumerate(ylist):
    pref_dic[y]=i+1
  all_dic[pref]=pref_dic

#print(all_dic)
for y,p in yplist:
  id="{:0>6}{:0>6}".format(p,all_dic[p][y])
  print(id)
  #print(y,p,all_dic[p][y])

Submission status: Accepted

Solution code:
import bisect
import sys
input = sys.stdin.readline
'''
allinputs = iter(input().splitlines())
input = lambda : next(allinputs)
#'''
N, M = map(int, input().split())
P, Y = [0] * M, [0] * M
city_list = [[] for _ in range(N)]

for i in range(M):
	p, y = map(int, input().split())
	city_list[p - 1].append(y)
	P[i] = p
	Y[i] = y
	
for i in range(N):
	city_list[i].sort()
	
for i in range(M):
	print('{:06}{:06}'.format(P[i], bisect.bisect_right(city_list[P[i] - 1], Y[i])))

Submission status: Accepted

Solution code:
from operator import itemgetter

N, M = map(int, input().split()) # 横に2個
City = [[i] + list(map(int, input().split())) for i in range(1, M+1)]


City = sorted(City, key=itemgetter(2))
City = sorted(City, key=itemgetter(1))

ans = []
pre = 1
seq = 0
for c in City:
    y = c[1]
    if y > pre:
        seq = 1
        pre = y
    else:
        seq += 1
    ans.append([c[0], y, seq])

ans.sort(key=itemgetter(0))
for a in ans:
    pre = str(a[1])
    seq = str(a[2])
    print('0'*(6-len(pre)) + pre + '0'*(6-len(seq)) + seq)

Submission status: Accepted

Solution code:
n, m = map(int, input().split())
ls = [[0 for i in range(3)] for j in range(m)]
ans = [""] * m
for i in range(m):
    ls[i][0], ls[i][1] = map(int, input().split())
    ls[i][2] = i
a = sorted(ls, key=lambda x:x[1])
a = sorted(ls)
prefi = ""
cityi = "000001"
for i in range(6 - len(str(a[0][0]))):
    prefi += "0"
prefi += str(a[0][0])
ans[a[0][2]] = prefi + cityi
city = 2
for i in range(1, m):
    prefId = str(a[i][0])
    ansId = a[i][2]
    if(a[i-1][0] != a[i][0]):
        city = 1
    prefi = ""
    cityi = ""
    for i in range(6 - len(str(a[i][0]))):
        prefi += "0"
    prefi += prefId
    for i in range(6 - len(str(city))):
        cityi += "0"
    cityi += str(city)
    ans[ansId] = prefi+cityi
    city += 1
for i in ans:
    print(i)

Submission status: Accepted

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

from operator import itemgetter
n,m = map(int,input().split())
py = [list(map(int,input().split())) for _ in range(m)]
for i in range(m):
    py[i].append(i)
py.sort(key = itemgetter(1))
py.sort(key = itemgetter(0))

x = py[0][0]
c = 0
for i in range(m):
    if x != py[i][0]:
        c = 1
        x = py[i][0]
    else:
        c += 1
    py[i].append(c)
py.sort(key = itemgetter(2))
for i in range(m):
    front = '00000'+str(py[i][0])
    back = '00000'+str(py[i][3])
    print(front[-6:]+back[-6:])

Submission status: Accepted

Solution code:
n,m=map(int,input().split())
py=[]
for i in range(m):
    q=[int(j) for j in input().split()]
    py.append(q+[i])
from operator import itemgetter
py.sort(key=itemgetter(1))
py.sort(key=itemgetter(0))
ans=[]
q=0
c=2
for i,j,k in py:
    p=str(i).rjust(6,'0')
    if q==i:
        y=str(c).rjust(6,'0')
        c+=1
    else:
        y="000001"
        q=i
        c=2   
    ans.append([p+y,k])
from operator import itemgetter
ans.sort(key=itemgetter(1))
for i,j in ans:
    print(i)

Submission status: Accepted

Solution code:
from collections import defaultdict
from operator import itemgetter

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

d = defaultdict(list)
for query_idx in range(m):
    pref_idx, year = map(int, input().split())
    d[pref_idx].append((year, query_idx))

ans = [None] * m
for pref_idx in d.keys():
    d[pref_idx].sort(key=itemgetter(0))
    # 県別誕生年昇順ソート
    for city_idx, (year, query_idx) in enumerate(d[pref_idx], 1):
        ans[query_idx] = '{:0>6}{:0>6}'.format(pref_idx, city_idx)
print(*ans, sep='\n')

Submission status: Accepted

Solution code:
class City:
    def __init__(self, index: int, prefecture: int, year: int):
        self.index = index
        self.prefecture = prefecture
        self.year = year
        self.id = ''

    def __lt__(self, other):
        if self.prefecture != other.prefecture:
            return self.prefecture < other.prefecture
        return self.year < other.year

    def __repr__(self):
        return '({}, {})'.format(self.prefecture, self.year)


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

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

cities.sort()

p = 0
cnt = 1
for i in range(M):
    if p != cities[i].prefecture:
        p = cities[i].prefecture
        cnt = 1

    cities[i].id = '{:06d}'.format(p) + '{:06d}'.format(cnt)
    cnt += 1

cities.sort(key=lambda c: c.index)

for c in cities:
    print(c.id)

Submission status: Accepted

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

order=[1]*n
ans=[""]*m
PY=[]
for i in range(m):
    p,y=map(int,input().split())
    PY.append((y,p,i))

PY.sort()
for y,p,i in PY:
    s_p=str(p).zfill(6)
    y_p=str(order[p-1]).zfill(6)
    order[p-1]+=1

    ans[i]=s_p+y_p

for i in ans:
    print(i)

Submission status: Accepted

Solution code:
n,m = map(int,input().split())
py = []
for i in range(m):
    py.append(list(map(int,input().split())))
    py[i].append(i)
py.sort(key=lambda x:x[1])
py.sort(key=lambda x:x[0])
x = py[0][0]
j=0
for i in range(m):
    if x != py[i][0]:
        j = 1
        x = py[i][0]
    else:
        j+=1
    s = str(py[i][0]).zfill(6) + str(j).zfill(6)
    py[i].append(s)
py.sort(key=lambda x:x[2])
for i in range(m):
    print(py[i][3])

Submission status: Accepted

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

city = [[] for i in range(M)]
city_id = ["" for i in range(M)]
count = [0] * N

for i in range(M):
    city[i] = list(map(int, input().split())) + [i]

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

for i in range(M):
     ken, year, num = city[i]
     count[ken-1] += 1
     city_id[num] = "{:0=6}{:0=6}".format(ken, count[ken-1])

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

Submission status: Accepted

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


lst_city = [[] for _ in range(N+1)]
for i, (p, y) in enumerate(src):
    lst_city[p].append((y, i))


ans = [None] * M
for pi, cities in enumerate(lst_city):
    for order, (y, i) in enumerate(sorted(cities)):
        ans[i] = str(pi).zfill(6) + str(order + 1).zfill(6)
print(*ans, sep="\n")

Submission status: Accepted

Solution code:
from operator import itemgetter
n, m = list(map(int, input().split()))
pyl = [tuple(map(int, input().split())) for _ in range(m)]

pyd = {pyl[i]:i for i in range(m)}
pyl.sort(key=itemgetter(1))
pref = {i+1:1 for i in range(n)}

ids = [["", 0] for _ in range(m)]
for i in range(m) :
    py = pyl[i]
    ids[i] = ["{:0=6}".format(py[0])+"{:0=6}".format(pref[py[0]]),
              pyd[py]]
    pref[py[0]] += 1

ids.sort(key=itemgetter(1))
for anid in ids :
    print(anid[0])

Submission status: Accepted

Solution code:
n,m,*py=map(int,open(0).read().split())
py = list(zip(py[::2],py[1::2],range(m)))
py.sort()
p = 0
c = 0
for i in range(m):
    if py[i][0] == p:
        c += 1
        py[i] += tuple([c])
    else:
        c = 1
        p = py[i][0]
        py[i] += tuple([1])
py.sort(key=lambda x:x[2])
[print("{:06}{:06}".format(i[0],i[3])) for i in py]

Submission status: Accepted

Solution code:
a, b = map(int, input().split())
c = []
for i in range(b):
    d, e = map(int, input().split())
    c.append([i, d, e, 0])
c = sorted(c, key=lambda x: x[2], reverse=False)
d = [0] * a
for i in range(b):
    d[c[i][1]-1] += 1
    c[i][3] = d[c[i][1]-1]
c.sort()
for i in range(b):
    print(("000000" + str(c[i][1]))[-6:] + ("000000" + str(c[i][3]))[-6:])

Submission status: Accepted

Solution code:
N, M = map(int, input().split())
py = [list(map(int, input().split())) + [i + 1] for i in range(M)]
py_sort = sorted(py)
py_sort[0][1] = 1
j = 2
for i in range(1, M):
    if py_sort[i - 1][0] != py_sort[i][0]:
        j = 1
    py_sort[i][1] = j
    j += 1
py = sorted(py_sort, key=lambda x: x[2])
for i in range(M):
    print(str(py[i][0]).zfill(6) + str(py[i][1]).zfill(6))

Submission status: Accepted

Solution code:
from operator import itemgetter
N, M = map(int, input().split())
PY = [list(map(int, input().split()))+[i] for i in range(M)]
PY.sort()
now = 1
cnt = 1
for j in range(M):
    if now != PY[j][0]:
        cnt = 1
        now = PY[j][0]
        PY[j].append(cnt)
    else:
        PY[j].append(cnt)
    cnt += 1
PY.sort(key=itemgetter(2))
for i in range(M):
    print(str(PY[i][0]).zfill(6) + str(PY[i][3]).zfill(6))

Submission status: Accepted

Solution code:
import itertools
import math

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

prefs = []
ids = {}

for i in range(n):
    prefs.append({})

for i in range(m):
    pref_num, year = map(int, input().split())
    prefs[pref_num-1].setdefault(i, year)

for i in range(n):
    sorted_cities = sorted(prefs[i].items(), key=lambda x: x[1])
    for j, city in enumerate(sorted_cities):
        ids.setdefault(city[0], (i, j))


sorted_ids = sorted(ids.items())

for data in sorted_ids:
    print(str(data[1][0]+1).zfill(6)+str(data[1][1]+1).zfill(6))

# city_name: (pref, ~th)

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])

nums = [0] * N
ans = [''] * M

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

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

for a in ans:
    print(a)

Submission status: Accepted

Solution code:
n,m = map(int,input().split())
py = []
for i in range(m):
    py.append(list(map(int,input().split())))
    py[i].append(i)
py.sort(key=lambda x:x[1])
py.sort(key=lambda x:x[0])
x = py[0][0]
j=0
for i in range(m):
    if x != py[i][0]:
        j = 1
        x = py[i][0]
    else:
        j+=1
    s = str(py[i][0]).zfill(6) + str(j).zfill(6)
    py[i].append(s)
py.sort(key=lambda x:x[2])
for i in range(m):
    print(py[i][3])

Submission status: Accepted

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

PY.sort()

l = []
t = 0
for i in range(M):
    if t != PY[i][0]:
        t = PY[i][0]
        cnt = 1
    l.append([str(t).zfill(6) + str(cnt).zfill(6), PY[i][2]])
    cnt += 1

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

for i in range(M):
    print(l[i][0])

Submission status: Accepted

Solution code:
N, M = map(int, input().split())
city = [0]*M
for i in range(M):
    city[i] = [i] * 4
    prefecture, year = map(int, input().split())
    city[i][0], city[i][1] = year, prefecture

city = sorted(city)

ite = [1] * (N+1)
for k in range(M):
    city[k][3] = ite[city[k][1]]
    ite[city[k][1]] += 1
city = sorted(city, key=lambda x: x[2])
for j in range(M):
    print("{:0=12}".format(city[j][1]*1000000+city[j][3]))  # zero padding

Submission status: Accepted

Solution code:
import bisect
import heapq
import itertools
import math
import os
import re
import string
import sys
from collections import Counter, deque, defaultdict
from decimal import Decimal
from fractions import gcd
from functools import lru_cache, reduce
from operator import itemgetter

import numpy as np

if os.getenv("LOCAL"):
    sys.stdin = open("_in.txt", "r")

sys.setrecursionlimit(2147483647)
INF = float("inf")
IINF = 10 ** 18
MOD = 10 ** 9 + 7

N, M = list(map(int, sys.stdin.readline().split()))
P, Y = list(zip(*[map(int, sys.stdin.readline().split()) for _ in range(M)]))

prefs = defaultdict(list)
for p, y in zip(P, Y):
    prefs[p].append(y)

for ys in prefs.values():
    ys.sort()

for p, y in zip(P, Y):
    idx = bisect.bisect_left(prefs[p], y) + 1
    print('{:06d}{:06d}'.format(p, idx))

Submission status: Accepted

Solution code:
import bisect
import heapq
import itertools
import math
import os
import re
import string
import sys
from collections import Counter, deque, defaultdict
from decimal import Decimal
from fractions import gcd
from functools import lru_cache, reduce
from operator import itemgetter

import numpy as np

if os.getenv("LOCAL"):
    sys.stdin = open("_in.txt", "r")

sys.setrecursionlimit(2147483647)
INF = float("inf")
IINF = 10 ** 18
MOD = 10 ** 9 + 7

N, M = list(map(int, sys.stdin.readline().split()))
P, Y = list(zip(*[map(int, sys.stdin.readline().split()) for _ in range(M)]))

nums = defaultdict(int)
ans = [''] * M
for i in np.lexsort((Y, P)):
    nums[P[i]] += 1
    ans[i] = '{:06d}{:06d}'.format(P[i], nums[P[i]])
print('\n'.join(map(str, ans)))

Submission status: Accepted

Solution code:
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(key=lambda x:(x[0],x[1]))
ans = ["" for i in range(M)]
p = -1
y = 1
for a in A:
    if p!=a[0]:
        y = 1
        p = a[0]
    b = str(a[0]).rjust(6,"0")+str(y).rjust(6,"0")
    ans[a[2]] = b
    y+=1
for i in ans:
    print(i)

Submission status: Accepted

Solution code:
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(key=lambda x:(x[0],x[1]))
ans = ["" for i in range(M)]
p = -1
y = 1
for a in A:
    if p!=a[0]:
        y = 1
        p = a[0]
    b = "0"*(6-len(str(a[0])))+str(a[0])+"0"*(6-len(str(y)))+str(y)
    ans[a[2]] = b
    y+=1
for i in ans:
    print(i)

Submission status: Accepted

Solution code:
n,m = map(int, input().split())
l = [[] for _ in range(n)]
for i in range(m):
    p,y = map(int, input().split())
    l[p-1].append((y, i))
ans = [None]*m
for i,pre in enumerate(l):
    pre.sort()
    for j,(a,b) in enumerate(pre):
        ans[b] = "{:0>6}{:0>6}".format(i+1,j+1)
print("\n".join(ans))

Submission status: Accepted

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

for i in range(m):
    a,b = map(int,input().split())
    ls[a].append((b,i))
ans = [None]*m
for i,l in enumerate(ls):
    l.sort()
    for j,(a,b) in enumerate(l):
        ans[b]= "{:06d}{:06d}".format(i,j+1)
for i in range(m):
    print(ans[i])

Submission status: Accepted

Solution code:
###template###
import sys
def input(): return sys.stdin.readline().rstrip()
from collections import defaultdict, Counter
from itertools import product, groupby, count, permutations, combinations
from math import pi, sqrt, ceil, floor
from collections import deque
from bisect import bisect, bisect_left, bisect_right
from string import ascii_lowercase
import heapq
INF = float("inf")
sys.setrecursionlimit(10**7)
# 4近傍（右, 下, 左, 上）
dy = [0, -1, 0, 1]
dx = [1, 0, -1, 0]
def inside(y: int, x: int, H: int, W: int) -> bool: return 0 <= y < H and 0 <= x < W
def mi(): return map(int, input().split())
def ii(): return int(input())
###template###

N, M = mi()
PYs = []
for i in range(M):
  p, y = mi()
  p -= 1 #0スタートに
  PYs.append((y, p, i)) #PY[2]は市の番号
PYs = sorted(PYs) #誕生した年で昇順ソート

PREFs = [0] * N #PREFs[0~N-1]で各県の市数にアクセス
#各PYsの要素を[属する県番号, 県に所属したときに振られた通し番号, ID]に書き換える
for i, (eachy, eachp, eachi) in enumerate(PYs):
  PREFs[eachp] += 1
  PYs[i] = [eachp+1, PREFs[eachp], eachi] #県番号を1スタートに戻す



#市の番号昇順でソートし直し
from operator import itemgetter
PYs = sorted(PYs, key=itemgetter(2)) #添字が変わっている
for p, num, i in PYs:
  print('{:06}{:06}'.format(p, num))

Submission status: Accepted

Solution code:
N,M = map(int, input().split())
piys = [[] for _ in range(N)] 
for i in range(M):
    p, y = map(int, input().split())
    piys[p-1].append((y,i))
    
ans = [None]*M
for p,iys in enumerate(piys):
    iys.sort()
    for k,(y,i) in enumerate(iys):
        ans[i] = "%06d%06d" % (p+1,k+1)
 
for i in ans:
    print(i)

Submission status: Accepted

Solution code:
n,m = map(int,input().split())
li = [0]*m
for i in range(m):
  li[i] = list(map(int,input().split()))
  li[i].append(i)
  li[i].append(0)
li = sorted(li,key=lambda x:x[1])
li = sorted(li,key=lambda x:x[0])
pre = 0
conti = 0
for i in range(m):
  if pre != li[i][0]:
    pre = li[i][0]
    conti = 0
    li[i][3] = str(pre).zfill(6) + str(1).zfill(6)
  else:
    conti += 1
    li[i][3] = str(pre).zfill(6) + str(conti+1).zfill(6)
li = sorted(li,key = lambda x:x[2])
for i in range(m):
  print(li[i][3])

Submission status: Accepted

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

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

ans = [''] * m
p_prev = 0
k = 1
for j in range(m):
    p, y, i = city[j]
    ans[i] += '0' * (6 - len(str(p))) + str(p)
    if p == p_prev:
        k += 1
    else:
        k = 1
        p_prev = p
    ans[i] += '0' * (6 - len(str(k))) + str(k)

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

Submission status: Accepted

Solution code:
import bisect

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

vals = [[] for i in range(N)]

for i in range(M):
    p, y = table[i]
    vals[p-1].append(y)

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

for i in range(M):
    p, y = table[i]
    s = bisect.bisect_left(vals[p-1], y)+1
    print('%06d'%p + '%06d'%s)

Submission status: Accepted

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

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

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

counter = [1 for i in range(N)]

for i in range(M):
    C[i][2] = counter[C[i][1]-1]
    counter[C[i][1]-1] += 1

C = list(sorted(C,key= lambda x: x[0]))

for i in range(M):
    for j in range(6-len(str(C[i][1]))):
        print(0,end = "")
    print(C[i][1],end = "")
    for j in range(6-len(str(C[i][2]))):
        print(0,end = "")
    print(C[i][2])

Submission status: Accepted

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

PY = []
cnt = [0]*N

for i in range(M):
    p, y = map(int, input().split())
    PY.append([i, p, y])
    cnt[p-1] += 1
    
PY = sorted(PY, key=lambda x: x[1])

ans = []

for i in range(N):
    temp_shi = []
    for j in range(cnt[i]):
        temp_shi.append(PY[len(ans)+len(temp_shi)])
    
    temp_shi = sorted(temp_shi, key=lambda x: x[2])
    
    for j in range(cnt[i]):
        ans.append([temp_shi[j][0], str(i+1).zfill(6) + str(j+1).zfill(6)])

ans = sorted(ans, 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())
List = [list(map(int, input().split()))+[_] for _ in range(M)]


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

idx = List[0][0]
id_lst = []
n = 0
for i in range(M):
    if idx==List[i][0]:
        n+=1
        id_lst.append([format(idx, '06')+format(n, '06'), List[i][2]])
    else:
        idx = List[i][0]
        n=1
        id_lst.append([format(idx, '06')+format(n, '06'), List[i][2]])
        
id_lst = sorted(id_lst, key=lambda x:x[1])

for j in range(M):
    print(id_lst[j][0])

Submission status: Accepted

Solution code:
def main():
    N, M = map(int, input().split())
    answer = [0] * M
    pref = {}
    for i in range(M):
        P, Y = map(int, input().split())
        if P not in pref:
            pref[P] = []
        pref[P].append((i, Y))
    for p, arr in pref.items():
        arr.sort(lambda a: a[1])
        for i in range(1, len(arr)+1):
            item = arr[i-1]
            answer[item[0]] = ("0" * 5 + str(p))[-6:]
            answer[item[0]] += ("0" * 5 + str(i))[-6:]
    for i in range(M):
        print(answer[i])


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
N, M = map(int, input().split())
A=[]
count=[1]*1000000
ans=[]
for i in range(M):
    a, b, = map(int, input().split())
    A.append([b, a, i])

A.sort()

for i in range(M):
    number=A[i][1]*1000000+count[int(A[i][1])]
    ans.append([A[i][2],str(number).zfill(12)])
    count[int(A[i][1])] +=1
ans.sort()

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

Submission status: Accepted

Solution code:
n, m = list(map(int, input().split()))
ipy = []
num = [1 for i in range(n+1)]
ans = ["" for i in range(m)]
for i in range(m):
  p, y = list(map(int, input().split()))
  ipy.append([i, p, y])
ipy.sort(key=lambda x: x[2])
for i in range(m):
  ans[ipy[i][0]] = str(ipy[i][1]).zfill(6)+str(num[ipy[i][1]]).zfill(6)
  num[ipy[i][1]] += 1
for e in ans:
  print(e)

Submission status: Accepted

Solution code:
# coding: utf-8
# Your code here!

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

spy = list(sorted(py+[[p,0] for p in range(n+1)]))

zaatu = {(p,y):i for i, (p,y) in enumerate(spy)}


for p,y in py:
    print(format(p, '06')+format(zaatu[(p,y)]-zaatu[(p,0)], '06'))

Submission status: Accepted

Solution code:
# coding: utf-8
# Your code here!
from bisect import bisect_left


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

spy = list(sorted(py))

for p,y in py:
    l2 = bisect_left(spy,[p,y])
    l1 = bisect_left(spy,[p,0])
    print(format(p, '06')+format(l2-l1+1, '06'))

Submission status: Accepted

Solution code:
n,m = map(int, input().split())
py = [list(map(int, input().split())) + [i] for i in range(m)]
py.sort(key=lambda x: [x[0], x[1]])
ans = []
P = [0] * (n + 1)
for p, y, i in py:
    P[p] += 1
    tmp = str(p).zfill(6) + str(P[p]).zfill(6)
    ans.append([i,tmp])
ans.sort()
for i,a in ans:
    print(a)

Submission status: Accepted

Solution code:
n, m = [int(i) for i in input().split()]
city = []
pref = [0 for i in range(n)]
for i in range(m):
    p, y = [int(_) for _ in input().split()]
    pref[p-1] += 1
    city.append([p,y,i])

city.sort(key = lambda x: (x[0], x[1]))
cnt = 1
for i in range(m):
    city[i].append(cnt)
    if cnt == pref[city[i][0]-1]:
        cnt = 1
    else:
        cnt += 1
city.sort(key = lambda x: x[2])
for i in range(m):
    print(str(city[i][0]).zfill(6)+str(city[i][3]).zfill(6))

Submission status: Accepted

Solution code:
## ABC113C - ID
import sys
input = sys.stdin.readline

def main():
    n, m = list(map(int, input().rstrip().split()))
    ans = [""] * m
    arr = []
    cnt = 1
    for i in range(m):
        p, y = list(map(int, input().split()))
        arr += [(p, y, i)]
    arr = sorted(arr)

    ans[arr[0][2]] = "{:06}{:06}".format(arr[0][0], cnt)
    for i in range(1, m):
        if arr[i - 1][0] == arr[i][0]:
            cnt += 1
        else:
            cnt = 1
        ans[arr[i][2]] = "{:06}{:06}".format(arr[i][0], cnt)

    for i in ans:
        print(i)


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
N,M = map(int,input().split())
para = []
for i in range(M):
    a,b = map(int,input().split())
    para.append([a,b,i])
para.sort(key = lambda x:(x[0],x[1]))
ans = []
memo = [-1 for i in range(N+1)]
for i in range(M):
    if memo[para[i][0]] == -1 :
        cnt = 1
        a = format(para[i][0]).zfill(6) + format(cnt).zfill(6)
        ans.append([a,para[i][2]]) 
        memo[para[i][0]] = 0
    else : 
        cnt += 1
        a = format(para[i][0]).zfill(6) + format(cnt).zfill(6)
        ans.append([a,para[i][2]]) 
ans.sort(key=lambda x:x[1])
for i in range(M):
    print(ans[i][0])