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

Solution (Python):


import sys
from collections import Counter, defaultdict

INF = float('inf')
MOD = 10 ** 9 + 7

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def II(): return int(sys.stdin.readline())
def SI(): return input()


n, m = LI()
YP = [[y, p] for p, y in (LI() for _ in range(m))]

YP2 = sorted(YP)

P = defaultdict(int)
ans = {}
for y, p in YP2:
    P[p] += 1
    l1, l2 = len(str(p)), len(str(P[p]))
    id = '{:06d}{:06d}'.format(p, P[p])
    ans[y] = id

for y, p in YP:
    print(ans[y])

Solution (Python):
from operator import itemgetter
N,M=(int(i) for i in input().split())
data = [[int(i) for i in input().split()] for i in range(M)]

j=0
for i in data:
    i.append(j)
    j=j+1

data.sort(key=itemgetter(1))
data.sort(key=itemgetter(0))

def addzero(n):
    addnum = 6-len(str(n))
    return '0'*addnum+str(n)

pref=0
yearLank=0
for i in data:
    if pref!=i[0]:
        pref=i[0]
        yearLank=1
    i.append(addzero(pref)+addzero(yearLank))
    yearLank = yearLank+1

data.sort(key=itemgetter(2))

for i in data:
    print(i[3])

Solution (Python):
N, M = [int(_) for _ in input().split()]
PY = [[int(_) for _ in input().split()] for _ in range(M)]
PYI = sorted([PY[i] + [i] for i in range(M)], key=lambda xs:xs[1])
count_p = {}
ans = [None] * M
for p, y, i in PYI:
    count_p[p] = count_p.get(p, 0) + 1
    ans[i] = [p, count_p[p]]
[print(str(p).zfill(6)+str(x).zfill(6)) for p, x in ans]

Solution (Python):


import sys
from collections import Counter, defaultdict

INF = float('inf')
MOD = 10 ** 9 + 7

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def II(): return int(sys.stdin.readline())
def SI(): return input()


n, m = LI()
YP = [[y, p] for p, y in (LI() for _ in range(m))]

YP2 = sorted(YP)

P = defaultdict(int)
ans = {}
for y, p in YP2:
    P[p] += 1
    l1, l2 = len(str(p)), len(str(P[p]))
    id = (6 - l1) * '0' + str(p) + (6 - l2) * '0' + str(P[p])
    ans[y] = id

for y, p in YP:
    print(ans[y])

Solution (Python):
N,M = map(int,input().split())
src = [tuple(map(int,input().split())) for i in range(M)]

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

ans = [None] * M
for p in range(len(cs)):
    for i,(_,j) in enumerate(cs[p]):
        s = str(p).zfill(6) + str(i+1).zfill(6)
        ans[j] = s
print(*ans, sep='\n')

Solution (Python):
N,M = map(int,input().split())
src = [tuple(map(int,input().split())) for i in range(M)]

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

ans = [None] * M
for p in range(len(cs)):
    for i,(_,j) in enumerate(cs[p]):
        s = str(p).zfill(6) + str(i+1).zfill(6)
        ans[j] = s
print(*ans, sep='\n')

Solution (Python):
def main():
    N, M = list(map(int, input().split()))

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

    pref_sorted = sorted(enumerate(pref), key=lambda x: x[1])

    idx = [1 for _ in range(N)]
    res = ['' for _ in range(M)]
    for j, (p, y) in pref_sorted:
        res[j] = str(p).zfill(6) + str(idx[p - 1]).zfill(6)
        idx[p - 1] += 1
    for r in res:
        print(r)


if __name__ == '__main__':
    main()

Solution (Python):
N, M = map(int, input().split())
a = [[] for _ in range(N + 1)]

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

ans = [None for _ in range(M)]
for p in range(1, N + 1):
    for e, (y, i) in enumerate(sorted(a[p], key=lambda x: x[0]), 1):
        ans[i] = str(p).zfill(6) + str(e).zfill(6)

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

Solution (Python):
import collections
import bisect
n,m=map(int,input().split())
p=[[int(j) for j in input().split()] for i in range(m)]
a=collections.defaultdict(list)
for x,y in sorted(p):
    a[x]+=[y]
for x,y in p:
    z=bisect.bisect(a[x],y)
    print("%06d%06d"%(x,z))

Solution (Python):
n, m = map(int, input().split())
ipy = []

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

ipy.sort(key=lambda x:x[2])
count = {}
order = {}

for i in range(m):
    i, p, y = ipy[i]
    if not p in count:
        count[p] = 0
    count[p] += 1
    order[i, p] = count[p]
    
ipy.sort(key=lambda x: x[0])
    
for i, p, y in ipy:
    print('{:06}{:06}'.format(p, order[i, p]))

Solution (Python):
L = list(map(int,input().split()))
N = L[0]
M = L[1]
PY = list()

for x in range(0,M):
    X = list(map(int,input().split()))
    PY.append((X[0],X[1],x))

sortedPY = sorted(PY, key=lambda x:x[1])
ID = [0 for i in range(N)]

for y in range(0,M):
    n = sortedPY[y][0]
    n = n-1
    ID[n] = ID[n] + 1
    nstr = str(ID[n])
    Pstr = str(sortedPY[y][0])
    while len(nstr) < 6:
        nstr = '0' + nstr
    while len(Pstr) < 6:
        Pstr = '0' + Pstr
    PY[sortedPY[y][2]] = Pstr + nstr
    number = Pstr + nstr

for x in range(0,M):
    print(PY[x])

Solution (Python):
import bisect
N,M=map(int,input().split())
A=[[0] for j in range(N)]
px=[]
for i in range(M):
    p,x=map(int,input().split())
    A[p-1].append(x)
    px.append([p,x])
for m in range(N):
    A[m].sort()
for k in range(M):
    q=bisect.bisect_left(A[px[k][0]-1],px[k][1])
    print("0"*(6-len(str(px[k][0])))+str(px[k][0])+"0"*(6-len(str(q)))+str(q))

Solution (Python):
N, M = input().split()
N = int(N)
M = int(M)
PY = []
for i in range(M):
    P, Y = input().split()
    PY.append((P, Y, i))

sortedPY = sorted(PY, key=lambda x:int(x[1]))

Pwas = [0 for i in range(N)]
for i,x in enumerate(sortedPY):
    P = x[0]
    idx = int(P) - 1
    Pwas[idx] = Pwas[idx] + 1
    PY[x[2]] = P.zfill(6) + str(Pwas[idx]).zfill(6)

for x in PY:
    print(x)

Solution (Python):
class CityData:
    def __init__(self, cityData):
        splitedData = cityData.split(" ")
        self.pref = int(splitedData[0])
        self.year = int(splitedData[1])

    def setRank(self, rank):
        self.rank = rank


firstLine = input().split(" ")
prefs = int(firstLine[0])
cities = int(firstLine[1])

cityDataArray = []
cityRankState = {}

for i in range(cities):
    inputData = input()
    cityDataArray.append(CityData(inputData))

sortedCityDataArray = sorted(cityDataArray, key=lambda x:x.year)

for i in sortedCityDataArray:
    try:
        rank = cityRankState[i.pref]
    except KeyError:
        rank = 0
    i.setRank(rank)
    rank += 1
    cityRankState[i.pref] = rank

for i in cityDataArray:
    print(str(i.pref).rjust(6, '0') + str(i.rank+1).rjust(6, '0'))

Solution (Python):

"""
Created on Fri Jan  4 20:10:14 2019

@author: Yamazaki Kenichi
"""
import bisect

N, M= map(int,input().split())
C = [list(map(int,input().split())) for i in range(M)]

a = [[] for i in range(N)]
for j in range(M):
    a[C[j][0]-1].append(C[j][1])

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

ans = []
for j in range(M):
    l = '0'*(6-len(str(C[j][0])))+str(C[j][0])
    r1 = bisect.bisect_left(a[C[j][0]-1],(C[j][1]))+1
    r = '0'*(6-len(str(r1)))+str(str(r1))
    ans = l + r 
    print(ans)

Solution (Python):
N,M = [int(s) for s in input().split()]
data = [[0 for i in range(4)] for j in range(M)]

for i in range(M):
    l = [int(s) for s in input().split()]
    data[i][0],data[i][1] = l[0],l[1]
    data[i][2] = i+1
data.sort()

seq = 1
for i in range(M):
    if i == 0:
        data[0][3] =str(data[0][0]).zfill(6) + "000001"
        seq += 1
    elif data[i][0] == data[i-1][0]:
        data[i][3] = str(data[i][0]).zfill(6) + str(seq).zfill(6)
        seq += 1
    else:
        seq = 1
        data[i][3] = str(data[i][0]).zfill(6) + "000001"
        seq += 1

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

Solution (Python):

def zeros(n): return [0 for i in range(n)]

N, M = [int(x) for x in input().split()]
city = []
for i in range(M):  
    pref, year = [int(x) for x in input().split()]
    city.append([pref, year, i, ''])



city.sort()


nth = zeros(N+1)
for i in range(M):
    pref, year, seq, id = [x for x in city[i]]
    nth[pref] += 1
    city[i][3] = '%06d%06d' % (pref, nth[pref])
    city[i][0] = city[i][2] 
    
    
city.sort()
for i in range(M): print(city[i][3])

Solution (Python):
def pad(n):
  s = str(n)
  while len(s) < 6:
    s = '0' + s
  return s

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

ans = [''] * (M+1)

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

pn = [0] * (N+1)

for y, p, i in ds:
  pn[p] += 1
  ans[i] = pad(p) + pad(pn[p])
print("\n".join(ans))

Solution (Python):
n, m = map(int, input().split())
ipy = []

for i in range(m):
    p, y = map(int, input().split())
    ipy.append([i, p, y])
    
ipy = sorted(ipy, key=lambda x: x[2])

count = {}
order = {}

for i, p, y in ipy:
    if not p in count:
        count[p] = 1
    else:
        count[p] += 1
    order[i, p] = count[p]
    
ipy = sorted(ipy, key=lambda x: x[0])
for i, p, y in ipy:
    print('{:06}{:06}'.format(p, order[i, p]))

Solution (Python):
import bisect
n, m = map(int, input().split())
p = []
y = []
py = []
categorized = [[] for i in range(n+1)]
for i in range(m):
    tmpp, tmpy = map(int, input().split())
    p.append(tmpp)
    y.append(tmpy)
    categorized[tmpp].append(tmpy)

for c in categorized:
    c.sort()
for i in range(m):
    order = bisect.bisect(categorized[p[i]], y[i])
    print('%06d%06d' % (p[i], order))

Solution (Python):
from operator import attrgetter

class City:
    def __init__(self, index, p, year):
        self.index = index
        self.p = p
        self.year = year
        self.rank = 0

n, m = [int(v) for v in input().split()]
city_list = []
for i in range(m):
    p, y = [int(v) for v in input().split()]
    city_list.append(City(i, p, y))

city_list.sort(key=attrgetter('p', 'year'))

p = 1
rank = 0
for i in range(m):
    if city_list[i].p != p:
        p = city_list[i].p
        rank = 1
    else:
        rank += 1
    city_list[i].rank = rank

city_list.sort(key=attrgetter('index'))

for city in city_list:
    print('{0:0>6}{1:0>6}'.format(city.p, city.rank))

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


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


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

Solution (Python):
n,m=list(map(int, input().split()))
PY=[list(map(int, input().split())) + [0] for i in range(m)] 
d={}
for i in sorted(PY, key=lambda x: x[1]):
    if i[0] in d:
        d[i[0]] += 1
    else:
        d[i[0]] = 1
    i[2] = d[i[0]]
for i in PY:
    print(str(i[0]).zfill(6) + str(i[2]).zfill(6))

Solution (Python):
N, M = map(int, input().split())
iPY = []
 
for i in range(M):
    p, y = map(int, input().split())
    iPY.append([i, p, y])
 
city_count = {}
order = {}
 
for i, p, y in sorted(iPY, key=lambda x: x[2]):
    if not p in city_count:
        city_count[p] = 0
    city_count[p] += 1
    order[p, i] = city_count[p]
    
for i, p, y in iPY:
    print('{:06}{:06}'.format(p, order[p, i]))

Solution (Python):
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()

out = [0]*M
cnt = 1
for i in range(len(city)):
	out[city[i][2]] = '{0:06d}{1:06d}'.format(city[i][0], cnt)
	try:
		if city[i+1][0] == city[i][0]: cnt += 1
		else: cnt = 1
	except(IndexError):
		cnt += 1

for o in out:
	print(o)

Solution (Python):
N,M = map(int,input().split())
l_input = []
for i in range(M):
    l_input.append(list(map(int,input().split())))
l_sorted = sorted(l_input,key=lambda x: x[1])
nids = dict()
cities = dict()
l_out = []
for s in l_sorted:
    ni = nids.get(s[0], 0)
    ni += 1
    cities[s[1]] = ni
    nids[s[0]] = ni

for c in l_input:
    print('{0:06}{1:06}'.format(c[0], cities[c[1]]))

Solution (Python):
n, m = map(int, input().split())
li_input = list()
counter = dict()
cities = dict()

for i in range(m):
    li_input.append(list(map(int, input().split())))

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

for c in sorted_city:
    idx = counter.get(c[0], 0)
    cities[c[1]] = idx

    
    counter[c[0]] = idx + 1


for c in li_input:
    print('{0:06}{1:06}'.format(c[0], cities[c[1]] + 1))

Solution (Python):
n, m = [int(i) for i in input().split()]
ipyo = [[i] + [int(_) for _ in input().split()] + [0] for i in range(m)]

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

cnt = [0] * n
for v in ipyo:
    p = v[1]
    cnt[p - 1] += 1
    v[3] = cnt[p - 1]

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

for v in ipyo:
    print('{0:06d}'.format(v[1]) + '{0:06d}'.format(v[3]))

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


PY.sort()
Ans={i:0 for i in range(M)}
counter=0

for i in range(M):
    if i==0:
        counter+=1
    elif PY[i][0]==PY[i-1][0]:
        counter+=1
    else:
        counter=1
    Ans[PY[i][2]]=str(PY[i][0]).zfill(6)+str(counter).zfill(6)
    
for i in range(M):
    print Ans[i]

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

def FillZero(num,f=6):
    s = ""
    s += (f - len(str(num))) * "0"
    s += str(num)
    return(s)

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

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

key0 = l[0][0]
key1 = 0
for i in range(M):
    if key0 == l[i][0]:
        key1 += 1
        l[i][1] = key1
    else:
        key1 = 1
        l[i][1] = key1
        key0 = l[i][0]

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

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

Solution (Python):
from collections import defaultdict


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

    res = []
    for p in cs.keys():
        cs[p].sort()
        for j, (y, i) in enumerate(sorted(cs[p])):
            res.append((i, "{:06d}{:06d}".format(p, j + 1)))

    for t in sorted(res):
        print(t[1])


if __name__ == '__main__':
    main()

Solution (Python):
n, m = map(int, input().split())
ipy = []

for i in range(m):
    p, y = map(int, input().split())
    ipy.append([i, p, y])
    
city_count = {}
order = {}

for i, p, y in sorted(ipy, key = lambda x: x[2]):
    if not p in city_count:
        city_count[p] = 0
    city_count[p] += 1
    order[i, p] = city_count[p]

for i, p, y in ipy:
    print('{:06}{:06}'.format(p, order[i, p]))

Solution (Python):
n,m = map(int,input().split())
py = [list(map(int,input().split())) + [_] for _ in range(m)]
py.sort()
result = ['' for _ in range(m)] 

a = 1 
b = 1 
for i in range(m):
    if py[i][0] != a:
        b=1
        a = py[i][0] 
        result[py[i][2]] = str(a).zfill(6) + str(b).zfill(6)
        b+=1
    else:
        result[py[i][2]] = str(a).zfill(6) + str(b).zfill(6)
        b+=1

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

Solution (Python):
import numpy as np

N,M=map(int,input().split())
P=[0]*M
Y=[0]*M
ans=[0]*M
cityList=[[] for i in range(N)]

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

for i in range(M):
    cityList[P[i]-1].append((P[i],Y[i],i))

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

for i in range(N):
    for j,item in enumerate(cityList[i]):
        ans[item[2]]="%06d%06d" % (item[0],j+1)

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

Solution (Python):
from bisect import bisect_left

N, M = map(int, input().split())
P, Y = [], []
v = [[] for _ in range(N+1)]

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

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

for x, y in zip(P, Y):
    print ("%06d" % x, end = "")
    print ("%06d" % int(bisect_left(v[x], y) + 1))

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

sorted_inputs = {}
ans = [None]*M

for i in range(M):
    P, Y = map(int, input().split())
    if sorted_inputs.get(P) is None:
        sorted_inputs[P] = [(Y, i)]
    else:
        sorted_inputs[P].append((Y, i))

for pref, l in sorted_inputs.items():
    l.sort() 
    for j, (Y, i) in enumerate(l):
        first = str(pref).rjust(6, '0')
        latter = str(j+1).rjust(6, '0')
        ans[i] = first + latter

for item in ans:
    print(item)

Solution (Python):
N, M = list(map(int, input().split()))
py = []

for i in range(M):
    py.append(list(map(int, input().split())) + [i])
py.sort()

result = ['' for i in range(M)]

n = 0
count = 1
for i in range(M):
    if py[i][0] != n:
        count = 1
        n = py[i][0]
    result[py[i][2]] = str(py[i][0]).zfill(6) + str(count).zfill(6)
    count += 1

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

Solution (Python):


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

arr = []
town = [[0]*2 for i in range(M)] 
count = [0]*(N+1)
for i in range(M):
    p,y= map(int,input().split())
    arr.append([i,p,y])

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

for i in arr:
    temp = i[1]
    town[i[0]][0] = temp
    town[i[0]][1] = count[i[1]]+1
    count[i[1]] += 1

for i in town:
    print(str(i[0]).zfill(6)+str(i[1]).zfill(6))

Solution (Python):
N,M=map(int,input().split())
P=[[] for i in range(M)]
Y=[1 for i in range(N+1)]
for i in range(M):
    a,b=map(int,input().split())
    P[i].append(i)
    P[i].append(a)
    P[i].append(b)
P.sort(key=lambda x:x[2])
for i in range(M):
    P[i].append(str(P[i][1]*1000000+Y[P[i][1]]))
    Y[P[i][1]]+=1
P.sort(key=lambda x:x[0])
for i in range(M):
    print(P[i][3].zfill(12))

Solution (Python):
import bisect

N, M = map(int, input().split())
P = [0 for _ in range(M)]
Y = [0 for _ in range(M)]
y_p = [[] for _ in range(N+1)]
for i in range(M):
    P[i], Y[i] = map(int, input().split())
    y_p[P[i]].append(Y[i])

for p in set(P):
    y_p[p].sort()

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

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

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

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

num = None
i   = 0
for a in aa:
    if a[0] == num:
        i += 1
        a.append('{:0=6}{:0=6}'.format(a[0], i))
    else:
        i = 1
        num = a[0]
        a.append('{:0=6}{:0=6}'.format(a[0], i))

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

for a in aa: print(a[3])

Solution (Python):
N, M = list(map(int, input().split()))
PY = [list(map(int, input().split())) + [i, 0] for i in range(M)] 
d = {}
for i in sorted(PY, key=lambda x: x[1]):
    if i[0] in d:
        d[i[0]] += 1
    else:
        d[i[0]] = 1
    i[3] = d[i[0]]
for i in PY:
    print(str(i[0]).zfill(6) + str(i[3]).zfill(6))

Solution (Python):

if __name__ == '__main__':
    ken_num, city_num = list(map(int, input().split()))
    data = []
    for i in range(city_num):
        element = list(map(int, input().split()))
        element.append(i)
        data.append(element)

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

    count = 1
    ken_num = 1
    ans_data = {}

    for i in range(city_num):
        number = data[i][2]
        if data[i][0] != ken_num:
            count = 1
            ken_num = data[i][0]
        chr = "{0:06d}".format(ken_num) + "{0:06d}".format(count)
        ans_data.update({number:chr})
        count += 1

    for i in range(city_num):
        print(ans_data[i])

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

city_to_pref, city_to_birth, pref_to_birth_list = {}, {}, defaultdict(list)
pref_counter = Counter()
city_id = {}
for i in range(m):
    pref, birth = map(int, input().split())
    city_to_pref[i] = pref
    city_to_birth[i] = birth
    pref_to_birth_list[pref].append(birth)


def get_city_index(i, pref):
    birth = city_to_birth[i]
    return pref_birth_to_id[pref][birth]


def give_id(i):
    p = city_to_pref[i]
    x = get_city_index(i, p) + 1
    return '{:0=6}{:0=6}'.format(p, x)


pref_birth_to_id = defaultdict(lambda : defaultdict(int))
for pref, births in pref_to_birth_list.items():
    for i, birth in enumerate(sorted(births)):
        pref_birth_to_id[pref][birth] = i

for i in range(m):
    print(give_id(i))

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

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

cnt = 1
prev_p = 0
for i in py:
    p, y = i[1][0], i[1][1]
    if prev_p == p:
        cnt += 1
    else:
        cnt = 1

    ans = str(p).zfill(6) + str(cnt).zfill(6)
    i.append(ans)
    prev_p = p

py = sorted(py, key=lambda x: x[0])
for i in py:
    print(i[2])

Solution (Python):




if __name__ == "__main__":
    N, M = map(int, input().split())
    city_list = []
    for i in range(M):
        p, y = map(int, input().split())
        city_list.append([i, p, y])

    city_count = {}
    order_dic = {}
    for i, p, y in sorted(city_list, key = lambda x: x[2]):
        if not p in city_count:
            city_count[p] = 0
        city_count[p] += 1
        order_dic[i, p] = city_count[p]

    for i, p, y in city_list:
        print("{:06}{:06}".format(p, order_dic[i,p]))

Solution (Python):
class City:
    def __self__(self, prefecture = 0, year = 0, rowid = 0):
        self.prefecture = prefecture
        self.year = year
        self.rowid = rowid
    def __lt__(self, rhs):
        if self.prefecture < rhs.prefecture or (self.prefecture == rhs.prefecture and self.year < rhs.year):
            return True
        return False

def solution(cities):
    n = len(cities)
    foo = [None for i in range(n)]
    cities = sorted(cities)
    prev, offset = -1, 0
    for i in range(n):
        if cities[i].prefecture != prev:
            prev = cities[i].prefecture
            offset = 1
        foo[cities[i].rowid] = '%06d%06d' % (cities[i].prefecture, offset)
        offset += 1
    return foo

def main():
    n, m = [int(i) for i in input().strip().split()]
    cities = [City() for i in range(m)]
    for i in range(m):
        p, y = [int(i) for i in input().strip().split()]
        cities[i].prefecture = p
        cities[i].year = y
        cities[i].rowid = i
    foo = solution(cities)
    for row in foo:
        print(row)

if __name__ == '__main__':
    main()

Solution (Python):
N,M=map(int, input().split(" "))
city=[]

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

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

index=1
for i in range(M):
    if i>0:
        if city[i-1][1] != city[i][1]:
            index=1
    
    city[i][2]=index
    index+=1

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

for i in range(M):
    print(str(city[i][1]).zfill(6)+str(city[i][2]).zfill(6))

Solution (Python):
n, m = map(int, input().split())
ipy = []

for i in range(m):
    p, y = map(int, input().split())
    ipy.append([i, p, y])
    
city_count = {}
order = {}

for i, p, y in sorted(ipy, key = lambda x: x[2]):
    if not p in city_count:
        city_count[p] = 0
    city_count[p] += 1
    order[i, p] = city_count[p]

for i, p, y in ipy:
    print('{:06}{:06}'.format(p, order[i, p]))

Solution (Python):
n, m = list(map(int, input().split()))
city_list = []

for i in range(m):
    pm, ym = list(map(int, input().split()))
    city_list.append([i,pm,ym])

city_count = {}
city = {}

for i,p,y in sorted(city_list, key=lambda x: x[2]):
    if not p in city_count:
        city_count[p] = 1
    else:
        city_count[p] += 1
    city[i,p] = city_count[p]

for i,p,y in city_list:
    print("{:0=6}{:0=6}".format(p, city[i,p]))

Solution (Python):
n, m = map(int, input().split())
ipy = []

for i in range(m):
    p, y = map(int, input().split())
    ipy.append([i, p , y])
    
city_count = {}
city = {}
    
for i, p, y in sorted(ipy, key=lambda x: x[2]):
    if not p in city_count:
        city_count[p] = 1
    else:
        city_count[p] += 1
    city[i, p] = city_count[p]

for i, p, y in ipy:
    print('{:06}{:06}'.format(p, city[i, p]))

Solution (Python):







def six(n):
    n_str = str(n)
    while len(n_str) < 6:
        n_str = "0" + n_str

    return n_str


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

id_list = [None] * M
dic_P = {}
info = []
info_idx = 0

for i in range(M):
    P, Y = map(int, input().split())
    if P in dic_P.keys():
        info[dic_P[P]].append([i, P, Y])
    else:
        dic_P[P] = info_idx
        info_idx += 1
        info.append([[i, P, Y]])

for group in info:
    group.sort(key=lambda a_i: a_i[2], reverse=False)
    for i, pair in enumerate(group):
        id = six(pair[1]) + six(i+1)
        id_list[pair[0]] = id

for id in id_list:
    print(id)

Solution (Python):







def six(n):
    n_str = str(n)
    while len(n_str) < 6:
        n_str = "0" + n_str

    return n_str


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

id_list = [None] * M
dic_P = {}
info = []
info_idx = 0

for i in range(M):
    P, Y = map(int, input().split())
    id_list[i] = [P, Y, ""]
    if P in dic_P.keys():
        info[dic_P[P]].append([i, P, Y])
    else:
        dic_P[P] = info_idx
        info_idx += 1
        info.append([[i, P, Y]])

for group in info:
    group.sort(key=lambda a_i: a_i[2], reverse=False)
    for i, pair in enumerate(group):
        id = six(pair[1]) + six(i+1)
        id_list[pair[0]] = id

for id in id_list:
    print(id)

Solution (Python):
from operator import itemgetter
N, M = map(int, input().split())
c=[]
for i in range(M):
	c.append(list(map(int, input().split())))
for i in range(M):
	c[i].append(i)
C = sorted(sorted(c,key=itemgetter(1)), key=itemgetter(0))
x = 0
for i in range(M):
	if i > 0  and C[i][0] - C[i-1][0] != 0:
		x = 1
	else:
		x += 1
	C[i].append(x)
c = sorted(C, key=itemgetter(2))
for i in range(M):
	print("{:06d}{:06d}".format(c[i][0], c[i][3]))

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

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

num = None
count = 1

for i in range(len(ipy)):
    if num == None:
        num = ipy[i][1]

    if num != ipy[i][1]:
        count = 1
        num = ipy[i][1]

    bangou = str(ipy[i][1]).zfill(6) + str(count).zfill(6)

    ipy[i].append(bangou)

    count += 1

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

for i in range(len(ipy)):
    print(ipy[i][3])

Solution (Python):
import itertools
N, M = map(int, input().split())

v = [[] for i in range(N)]
for i in range(M):
    Pi, Yi = map(int, input().split())
    v[Pi-1].append((Yi, i))

ids = []
for ps,p in zip(v,range(len(v))):
    for c,i in zip(sorted(ps, key=(lambda x:x[0])), range(len(ps))):
        ids.append(('{0:06d}{1:06d}'.format(p+1,i+1) ,c[1]))

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

Solution (Python):
N,M = map(int,input().split(" "))
dic = {}
for i in range(M):
    P,Y = map(int,input().split(" "))
    if not P in dic: 
        dic[P] = [(Y,i)]
    else:
        dic[P].append((Y,i))

ans = [0] * M
for key in dic.keys():
    dic[key].sort(key=lambda x:x[0])
    l = len(dic[key])
    for i in range(l):
        ans[dic[key][i][1]] = (key,i+1)

for i in range(len(ans)):
    print('{:0=6}'.format(ans[i][0]) + '{:0=6}'.format(ans[i][1]))

Solution (Python):
n , m = map(int, input().split())
ipy = []

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

city_count = {}
order = {}

for i, p, y in sorted(ipy, key=lambda x: x[2]):
    if not p in city_count:
        city_count[p] = 0
    city_count[p] += 1
    order[p, i] = city_count[p]
    
for i, p, y in ipy:
    print('{:06}{:06}'.format(p, order[p, i]))

Solution (Python):
from operator import itemgetter, attrgetter

N, M = list(map(int,input().strip().split()))
ar = []
ans = []
num = 0

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

ar.sort(key=itemgetter(0,1))

for i in ar:
    a,b,c = i
    if num != a:
        num = a
        num2 = 0
    num2 += 1
    ans.append([str(num).zfill(6)+str(num2).zfill(6),c])

ans.sort(key=itemgetter(1))

for i in range(M):
    py,c = ans[i]
    print(py)

Solution (Python):
NM = input().split()

N = int(NM[0])
M = int(NM[1])

PY = []
for i in range(1,M+1):
    sc = input()
    PY.append([int(sc.split()[0]),int(sc.split()[1]),i])

P_city = {}
for i in PY:
    if not i[0] in P_city:
        P_city[i[0]] = []
    P_city[i[0]].append([i[1],i[2]])
    
ans = {}
for i,j in P_city.items():
    j.sort()
    for index,k in enumerate(j):
        ans[k[1]] = str(i).zfill(6)+str(index+1).zfill(6)

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

Solution (Python):
from collections import defaultdict

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

Q=[]

for i in range(M):
  P,Y=map(int,input().split())
  Q.append([P,Y,i])
  
Q = sorted(Q,key=lambda x:x[1])
Q = sorted(Q,key=lambda x:x[0])

nowP=Q[0][0]
nownum=0

for l in Q:
  s=str(l[0]).zfill(6)
  if l[0]==nowP:
    nownum+=1
  else:
    nowP=l[0]
    nownum=1
  s+=str(nownum).zfill(6)
  l.append(s)
  
Q = sorted(Q,key=lambda x:x[2])

for l in Q:
  print(l[3])

Solution (Python):
import sys
input = sys.stdin.readline
n, m = map(int, input().split())
cities = []
for _ in range(m):
  cities.append(list(map(int, input().split())))
sort_cities = sorted(cities, key=lambda x:x[1])
pre = [0 for _ in range(n)]
ans = {}
for city in sort_cities:
  pre[city[0]-1]+=1
  st_city = str(city[0])
  st_pre = str(pre[city[0]-1])
  len_0 = (6-len(st_city))*'0'
  ans[len_0+st_city+str(city[1])] = len_0+st_city+(6-len(st_pre))*'0'+st_pre
for a in cities:
  print(ans[(6-len(str(a[0])))*'0'+str(a[0])+str(a[1])])

Solution (Python):
import bisect

N, M = map(int, input().split())
P = [0 for _ in range(M)]
Y = [0 for _ in range(M)]
y_p = [[] for _ in range(N+1)]
for i in range(M):
    P[i], Y[i] = map(int, input().split())
    y_p[P[i]].append(Y[i])

for p in set(P):
    y_p[p].sort()

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