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:
# https://abc113.contest.atcoder.jp/tasks/abc113_c
def pad(n):
    return '{:0>6}'.format(n)


N, M = map(int, input().split())
work = [None for _ in range(M)]
orig = [None for _ in range(M)]  # retains original order
for i in range(M):
    Pi, Yi = map(int, input().split())
    data = [Pi, Yi, 1, i]
    work[i] = data
    orig[i] = data

work.sort(key=lambda x: x[1])  # sort by year
work.sort(key=lambda x: x[0])  # sort by prefectures

for i in range(1, M):
    if work[i][0] == work[i - 1][0]:
        work[i][2] = work[i - 1][2] + 1

ans = []
for di in orig:
    ans.append(pad(di[0]) + pad(di[2]))
print('\n'.join(ans))

Submission status: Accepted

Solution code:
# https://abc113.contest.atcoder.jp/tasks/abc113_c
def pad(n):
    return '{:0>6}'.format(n)


N, M = map(int, input().split())
data = [None for _ in range(M)]
for i in range(M):
    Pi, Yi = map(int, input().split())
    data[i] = [Pi, Yi, 1, i]

data.sort(key=lambda x: x[1])  # sort by year
data.sort(key=lambda x: x[0])  # sort by prefectures

for i in range(1, M):
    if data[i][0] == data[i - 1][0]:
        data[i][2] = data[i - 1][2] + 1

data.sort(key=lambda x: x[-1])  # original order
ans = []
for di in data:
    ans.append(pad(di[0]) + pad(di[2]))
print('\n'.join(ans))

Submission status: Accepted

Solution code:
# https://abc113.contest.atcoder.jp/tasks/abc113_c
def pad(n):
    return '{:0>6}'.format(n)


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

data = [[P[i], Y[i], 1, i] for i in range(M)]
data.sort(key=lambda x: x[1])  # sort by year
data.sort(key=lambda x: x[0])  # sort by prefectures

for i in range(1, M):
    if data[i][0] == data[i - 1][0]:
        data[i][2] = data[i - 1][2] + 1

data.sort(key=lambda x: x[-1])  # original order
ans = []
for di in data:
    ans.append(pad(di[0]) + pad(di[2]))
print('\n'.join(ans))

Submission status: Accepted

Solution code:
# https://abc113.contest.atcoder.jp/tasks/abc113_c
def pad(n):
    return '{:0>6}'.format(n)


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

data = [[P[i], Y[i], 1, i] for i in range(M)]
data.sort(key=lambda x: x[1])  # sort by year
data.sort(key=lambda x: x[0])  # sort by prefectures

for i in range(1, M):
    if data[i][0] == data[i - 1][0]:
        data[i][2] = data[i - 1][2] + 1

data.sort(key=lambda x: x[-1])  # original order
for di in data:
    print(pad(di[0]) + pad(di[2]))

Submission status: Accepted

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

dic = {}
for j in range(n+1):
    dic[j] = 1

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


for k in range(m):
    arr[k] += [dic[arr[k][0]]]
    dic[arr[k][0]] += 1

arr.sort(key = lambda x : x[2])
    
for v in range(m):
    print("{:06d}{:06d}".format(arr[v][0],arr[v][3]))

Submission status: Accepted

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

info_list = []

for i in range(m):
    pi, yi = map(int, input().split())
    info_list.append([i+1, pi, yi])
# print(info_list)

from operator import itemgetter
info_list.sort(key = itemgetter(2))
# print(info_list)


xth = [1 for i in range(1, n+1)]
# print(xth)

for info in info_list:
    info.append(str(info[1]).zfill((6)) + str(xth[info[1]-1]).zfill(6))
    xth[info[1]-1]+=1


info_list.sort(key = itemgetter(0))

for ele in info_list:
    print(ele[3])

Submission status: Accepted

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

array = []
for i in range(m):
    temp = list(map(int, input().split()))
    temp.append(i)
    array.append(temp)

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

count = 1
eq = True

for i in range(m):
    if eq is False:
        count = 1
    array[i][1] = count
    count += 1
    if i != m - 1:
        if array[i][0] == array[i + 1][0]:
            eq = True
        else:
            eq = False

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

for i in range(m):
    out = '%06d' % array[i][0] + '%06d' % array[i][1]
    print(out)

Submission status: Accepted

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

dict_p = {}
dict_c = {}

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

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

Submission status: Accepted

Solution code:
import sys
stdin = sys.stdin

sys.setrecursionlimit(10**5)

def li(): return map(int, stdin.readline().split())
def li_(): return map(lambda x: int(x)-1, stdin.readline().split())
def lf(): return map(float, stdin.readline().split())
def ls(): return stdin.readline().split()
def ns(): return stdin.readline().rstrip()
def lc(): return list(ns())
def ni(): return int(stdin.readline())
def nf(): return float(stdin.readline())

n,m = li()
py = []
for _ in range(m):
    py.append(list(li()))
    
towns = [[] for _ in range(n+1)]
table = [{} for _ in range(n+1)]
for p,y in py:
    towns[p].append(y)
    
for i in range(n+1):
    if len(towns[i]) > 0:
        towns[i].sort()
        
for i in range(n+1):
    if len(towns[i]) > 0:
        for j, tj in enumerate(towns[i]):
            table[i].update({tj: j+1})
            
for p,y in py:
    print(str(p).zfill(6) + str(table[p][y]).zfill(6))

Submission status: Accepted

Solution code:
N, M = map(int,input().split())
P = [[] for k in range(N)]
A = [0 for k in range(M)]

for k in range(M):
    s, t = map(int,input().split())
    P[s-1].append([t,k])

for k in range(N):
    P[k].sort()
    for l in range(len(P[k])):
        A[P[k][l][1]] = str(k+1).zfill(6) + str(l+1).zfill(6)

for a in A:
    print("".join(a))

Submission status: Accepted

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

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

pref = city[0][0]
num = 0
for i in range(m):
    if city[i][0] == pref:
        num += 1
        P = str(city[i][0]).zfill(6)
        Y = str(num).zfill(6)
        id.append([P+Y, city[i][2]])
    else:
        num = 1
        pref = city[i][0]
        P = str(city[i][0]).zfill(6)
        Y = str(num).zfill(6)
        id.append([P + Y, city[i][2]])

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

Submission status: Accepted

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


N, M = [int(elem) for elem in fin().split()]
cities = [[int(elem) for elem in fin().split()] for _ in range(M)]
sorted_cities = sorted(cities, key= lambda x: x[1])

num_cities_in_pref = defaultdict(int)
years_to_identification = dict()
for pref, year in sorted_cities:
    num_cities_in_pref[pref] += 1
    years_to_identification[year] = "{:06}{:06}".format(pref, num_cities_in_pref[pref])

for _, year in cities:
    print(years_to_identification[year])

Submission status: Accepted

Solution code:
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))

ans = [None]*M
for pi,cities in enumerate(cs):
    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:
N , M = map(int, input().split())
field = []
for i in range(M):
    p,y = map(int, input().split())
    field.append((y, p, i))
field.sort()

sum = [0 for i in range(N)]
field2 = []

for i in range(M):
	sum[field[i][1]-1] += 1
	field2.append((field[i][2], field[i][1], sum[field[i][1]-1]))
field2.sort()
for i in range(M):
	print(str(field2[i][1]).zfill(6)+str(field2[i][2]).zfill(6))

Submission status: Accepted

Solution code:
import sys as sys

lines =  input().split()
n = int(lines[0])
m = int(lines[1])

py = []
od = {}

#lines = sys.stdin.readlines()

for i in range(0,m):


    #l =  lines[i].split()
    l = input().split()
    p = int(l[0])
    y = int(l[1])
    
    if p in od :
        od[p].append([i,y])
    else:
        od[p] = [[i,y]]

a = []
for p in od.keys():
    od[p].sort(key=lambda x:x[1])
    r = 1

    for o in od[p]:
        cs = ""

        tmp = p
        digit = 0
        while tmp > 0 :        
            digit += 1
            tmp = tmp // 10
        
        l = 6-digit
        for j in range(l):
            cs += '0'
        cs += str(p)

        tmp = r 
        digit = 0
        while tmp > 0 :        
            digit += 1
            tmp = tmp // 10

        l = 6-digit
        for j in range(l):
            cs += '0'
        cs += str(r)        

        a.append([o[0],cs])
        r += 1

a.sort(key=lambda x:x[0])
for aa in a:
    print(aa[1])

Submission status: Accepted

Solution code:
n,m=map(int,input().split())
p=[]
for i in range(m):
    t1,t2=map(int,input().split())
    p.append([i,t1,t2])
p.sort(key=lambda x:x[2])
c=[1 for i in range(n+1)]
num=[]
for i,pre,yea in p:
    tmp=str(pre).zfill(6)+str(c[pre]).zfill(6)
    num.append([i,tmp])
    c[pre]+=1
num.sort()
for i in num:
    print(i[1])

Submission status: Accepted

Solution code:
n, m = map(int, raw_input().split())
v = []
for i in range(m):
    p, y = map(int, raw_input().split())
    v.append((i, p, y))
v = sorted(v, key=lambda _: _[2])
D = {p: 1 for p in range(1,n+1)}
w = []
for i, p, y in v:
    x = D[p]
    D[p] += 1
    w.append((i, "%06d%06d" % (p, x)))
for i, code in sorted(w):
    print code

Submission status: Accepted

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

D = []
for i in range(M):
    P, Y = map(int, input().split())
    D.append((i, P, Y))
D.sort(key=lambda x: x[2])

X = [1 for _ in range(N+1)]
A = []
for i, p, y in D:
    A.append((i, "{0:06d}{1:06d}".format(p, X[p])))
    X[p] += 1
A.sort()
for i, x in A:
    print(x)

Submission status: Accepted

Solution code:
from operator import itemgetter

n, m = map(int, input().split())
city = []
pre = set()
for i in range(m):
    p, y = map(int, input().split())
    city.append((p, y, i))
    pre.add(p)
city.sort(key=itemgetter(0, 1))
ans = []
now = city[0][0]
count = 1
for i in range(m):
    if city[i][0] != now:
        now = city[i][0]
        count = 1
    bangou = "0" * (6 - len(str(now))) + str(now) +\
             "0" * (6 - len(str(count))) + str(count)
    ans.append((city[i][2], bangou))
    count += 1
for i in sorted(ans):
    print(i[1])

Submission status: Accepted

Solution code:
from operator import itemgetter

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

A.sort(key=itemgetter(1,2))

prev = 0
no = 1
for i in range(m):
    if A[i][1] != prev:
        no = 1
        prev = A[i][1]
    else:
        no += 1
    A[i][2] = no

A.sort(key=itemgetter(0))
for a in A:
    print("%06d%06d" % (a[1], a[2]))

Submission status: Accepted

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

all_cities = []
pref = {}
for _ in range(M):
    Pi, Yi = map(int, input().split())

    # [ 誕生年,  認識番号 ]
    city = [Yi, None]

    all_cities.append(city)

    if Pi not in pref:
        pref[Pi] = []
    pref[Pi].append(city)

for pref_id, pref_cities in pref.items():
    for city_id, city in enumerate(sorted(pref_cities, key=lambda c: c[0])):
        city[1] = "{:06}{:06}".format(pref_id, city_id + 1)

for city in all_cities:
    print(city[1])

Submission status: Accepted

Solution code:
n,m=map(int,input().split())
l=[]
k=['_']*m
x=[1]*(n+1)
for i in range(m):
    a,b=map(int,input().split())
    l.append([i,a,b])
y=sorted(l,key=lambda c:c[2])
for i in y:
    k[i[0]]=str(i[1]).zfill(6)+str(x[i[1]]).zfill(6)
    x[i[1]]+=1
for i in k:
    print(i)

Submission status: Accepted

Solution code:
from sys import stdin
import numpy as np

s_in = lambda: stdin.readline()[:-1]  # s = s_in()
d_in = lambda: int(stdin.readline())  # N = d_in()
ds_in = lambda: list(map(int, stdin.readline().split()))  # List = ds_in()
N, M = ds_in()
info_list = []
for _ in range(M):
    info_list.append(ds_in())
info_list = np.array(info_list)
ordered = np.argsort(info_list[:, 1])
pref_count = np.zeros(N)
ans_list = ['' for _ in range(M)]
for i in ordered:
    pref = info_list[i, 0]
    pref_count[pref - 1] += 1
    ans_list[i] = '%06d%06d' % (pref, pref_count[pref - 1])
for a in ans_list:
    print(a)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
from sys import stdin
import numpy as np

s_in = lambda: stdin.readline()[:-1]  # s = s_in()
d_in = lambda: int(stdin.readline())  # N = d_in()
ds_in = lambda: list(map(int, stdin.readline().split()))  # List = ds_in()


N, M = ds_in()

info_list = []
for _ in range(M):
    info_list.append(ds_in())
info_list = np.array(info_list)

ordered = np.argsort(info_list[:, 1])
pref_count = np.zeros(N)
ans_list = ['' for _ in range(M)]
for i in ordered:
    pref = info_list[i, 0]
    pref_count[pref - 1] += 1
    ans_list[i] = '%06d%06d' % (pref, pref_count[pref - 1])

for a in ans_list:
    print(a)

Submission status: Accepted

Solution code:
n,m=map(int,input().split())
l=[[] for i in range(n)]
for i in range(m):
    p,y=input().split()
    l[int(p)-1].append(y.zfill(10)+str(i).zfill(6))
for i in range(n):
    l[i].sort()
s=[0]*m
for i in range(n):
    for j in range(len(l[i])):
        s[int(l[i][j][10:16])]=str(i+1).zfill(6)+str(j+1).zfill(6)
for i in s:
    print(i)

Submission status: Accepted

Solution code:
n,m=map(int,input().split())
l=[{} for k in range(n)]
for i in range(m):
    p,y=map(int,input().split())
    l[p-1][y]=i
for k in range(n):
    l[k]=sorted(l[k].items(), key=lambda x:x[0])
s=[0]*m
for k in range(n):
    for r, p in enumerate(l[k]):
        s[p[1]]=[k,r]
for i in s:
    print('{:06}{:06}'.format(i[0]+1,i[1]+1))

Submission status: Accepted

Solution code:
n,m=map(int,input().split())
l=[{} for k in range(n)]
for i in range(m):
    p,y=map(int,input().split())
    l[p-1][y]=i
for k in range(n):
    l[k]=sorted(l[k].items(), key=lambda x:x[0])
s=[0]*m
for k in range(n):
    for r, p in enumerate(l[k]):
        s[p[1]]=str(k+1).zfill(6)+str(r+1).zfill(6)
for i in s:
    print(i)

Submission status: Accepted

Solution code:


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

data = [[] for i in range(n)]

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

ans = [0 for i in range(m)]
for i in range(n):
    data[i].sort()
    for j in range(len(data[i])):
        _id = "0"*(6-len(str(i+1)))+str(i+1)+"0"*(6-len(str(j+1)))+str(j+1)
        ans[data[i][j][1]] = _id

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

Submission status: Accepted

Solution code:
if __name__ == '__main__':
    N, M = map(int, input().split())

    ans = [None] * M
    prefMap = {}
    for i in range(M):
        P, Y = map(int, input().split())

        if P in prefMap:
            prefMap[P].append((Y, i))
        else:
            prefMap[P] = [(Y, i)]

    for P, L in prefMap.items():
        L.sort()

        for j, (y, i) in enumerate(L):
            ans[i] = str(P).zfill(6) + str(j + 1).zfill(6)

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

Submission status: Accepted

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

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

    for v in dic.values():
        v.sort(key=lambda x:x[0])

    l = [0 for i in range(m)]
    last_k = n+1
    for k, v in dic.items():
        if k != last_k:
            j = 1
        for V in v:
            P = str(k)
            O = str(j)
            len_P = len(P)
            len_O = len(O)
            i = V[1]
            l[i] = "0"*(6-len_P) + P + "0"*(6-len_O) + O
            j += 1
            
    for num in l:
        print(num)

if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
from operator import itemgetter

def main():
    num_prefecture, num_city = map(int, input().rstrip().split())
    
    prefecture_list = [[] for i in range(num_prefecture)]
    
    '''prefecture_list[prefecture_number-1] = [[city index, born year], ...]'''
    for idx_city in range(num_city):
        p_belong, y_born = map(int, input().rstrip().split())
        prefecture_list[p_belong - 1].append([idx_city, y_born]) # convert p_belong so that index starts from 0
    
    # sort in the order of city birth year in an each prefecture
    prefecture_list = [sorted(each_prefecture_list, key = itemgetter(1)) for each_prefecture_list in prefecture_list]
    
    id_list = []
    for idx_p, each_prefecture_list in enumerate(prefecture_list):
        for city_order, [idx_city, y_born] in enumerate(each_prefecture_list):
            id_num = str(idx_p + 1).zfill(6) + str(city_order + 1).zfill(6)
            id_list.append([idx_city, id_num])
    
    # sort in the order of city number
    id_list.sort(key = itemgetter(0))
    
    for id_num in id_list:
        print(id_num[1])
    
if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
from operator import itemgetter

def main():
    num_prefecture, num_city = map(int, input().rstrip().split())
    
    prefecture_list = [[] for i in range(num_prefecture)]
    
    '''prefecture_list[prefecture_number-1] = [[city index, born year], ...]'''
    for idx_city in range(num_city):
        p_belong, y_born = map(int, input().rstrip().split())
        prefecture_list[p_belong - 1].append([idx_city, y_born]) # convert p_belong so that index starts from 0
    
    # sort in the order of city birth year in an each prefecture
    prefecture_list = [sorted(each_prefecture_list, key = itemgetter(1)) for each_prefecture_list in prefecture_list]
    
    id_list = []
    for idx_p, each_prefecture_list in enumerate(prefecture_list):
        for city_order, [idx_city, y_born] in enumerate(each_prefecture_list):
            id_first = str(idx_p + 1).zfill(6)
            id_end = str(city_order + 1).zfill(6)
            id_num = id_first + id_end
            id_list.append([idx_city, id_num])
    
    # sort in the order of city number
    id_list.sort(key = itemgetter(0))
    
    for id_num in id_list:
        print(id_num[1])
    
if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
from operator import itemgetter

def main():
    num_prefecture, num_city = map(int, input().rstrip().split())
    
    prefecture_list = [[] for i in range(num_prefecture)]
    
    '''prefecture_list[prefecture_number-1] = [[city index, born year], ...]'''
    for idx_city in range(num_city):
        p_belong, y_born = map(int, input().rstrip().split())
        p_belong -= 1 # convert so that index starts from 0
        prefecture_list[p_belong].append([idx_city, y_born])
    
    # sort in the order of city birth year in an each prefecture
    prefecture_list = [sorted(each_prefecture_list, key = itemgetter(1)) for each_prefecture_list in prefecture_list]
    
    id_list = []
    for idx_p, each_prefecture_list in enumerate(prefecture_list):
        for city_order, [idx_city, y_born] in enumerate(each_prefecture_list):
            id_first = '{0:06d}'.format(idx_p + 1)
            id_end = '{0:06d}'.format(city_order + 1)
            id_num = str(id_first) + str(id_end)
            id_list.append([idx_city, id_num])
    
    # sort in the order of city number
    id_list.sort(key = itemgetter(0))
    
    for id_num in id_list:
        print(id_num[1])
    
if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
n,m=map(int,input().split())
l=[[] for i in range(n)]
for i in range(m):
    p,y=input().split()
    l[int(p)-1].append(y.zfill(10)+str(i).zfill(6))
for i in range(n):
    l[i].sort()
s=[0]*m
for i in range(n):
    for j in range(len(l[i])):
        s[int(l[i][j][10:16])]=str(i+1).zfill(6)+str(j+1).zfill(6)
for i in s:
    print(i)

Submission status: Accepted

Solution code:
N, M = map(int, input().split())
D = {}
for i in range(M):
    p, y = map(int, input().split())
    if p not in D:
        D[p] = [(i, y)]
    else:
        D[p].append((i, y))

for p in D.keys():
    D[p].sort(key=lambda p: p[1])

ans = [None for i in range(M)]
for p, pairs in D.items():
    for x, pair in enumerate(pairs):
        x += 1
        i = pair[0]
        y = pair[1]
        out = "{0:06d}{1:06d}".format(p, x)
        ans[i] = out
        # ans.append((i, out))
# ans.sort(key=lambda p: p[0])
for an in ans:
    print(an)

Submission status: Accepted

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

towns = []  # List of (p, y, i)

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

towns = sorted(towns, key=lambda tup: (tup[0], tup[1]))

p_cur = 0
x = 1
for i in range(m):
    if (towns[i][0] == p_cur):
        x += 1
    else:
        x = 1
        p_cur = towns[i][0]

    towns[i][1] = x

towns = sorted(towns, key=lambda tup: tup[2])

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

Submission status: Accepted

Solution code:
tmp = list(map(int, input().split(" ")))
N = tmp[0]
M = tmp[1]

data = [[i] for i in range(M)]

for i in range(M):
    tmp = list(map(int, input().split(" ")))
    data[i].extend(tmp)

data = sorted(data, key=lambda x:(x[1],x[2]), reverse=False)

before = -1
counter = 1
for i in range(M):
    if data[i][1] != before:
        counter = 1
        before = data[i][1]
    data[i].append(counter)
    counter += 1

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

for d in data:
    print('{0:06}'.format(d[1]), end="")
    print('{0:06}'.format(d[3]))

Submission status: Accepted

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

out = [[0, 0] for i in range(m)]
hash = [[] for i in range(10**5+1)]
for i in range(m):
    p[i], y[i] = [int(i) for i in input().split()]
    hash[p[i]].append([y[i], i])

for i in range(len(hash)):
    hash[i] = sorted(hash[i])
    for j in range(len(hash[i])):
        out[hash[i][j][1]] = i, j+1
for i in range(len(out)):
    print("{}{}".format(str(out[i][0]).zfill(6), str(out[i][1]).zfill(6)))

Submission status: Accepted

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

out = [[0, 0] for i in range(m)]
hash = [[] for i in range(10**5+10)]
for i in range(m):
    p[i], y[i] = [int(i) for i in input().split()]
    hash[p[i]].append([y[i], i])

for i in range(len(hash)):
    hash[i] = sorted(hash[i])
    for j in range(len(hash[i])):
        out[hash[i][j][1]] = i, j+1
for i in range(len(out)):
    print("{}{}".format(str(out[i][0]).zfill(6), str(out[i][1]).zfill(6)))

Submission status: Accepted

Solution code:
N,M=map(int,input().split())
List=[[int(i) for i in input().split()] for i in range(M)]
for i in range(M):
  List[i].append(i)
List.sort(key=lambda x:[x[0],x[1]])
x=0
pre_p=1
ID=[""]*M
for i in List:
  if pre_p==i[0]:
    x+=1
  else:
    x=1
  ID[i[2]]+="0"*(6-len(str(i[0])))
  ID[i[2]]+=str(i[0])
  ID[i[2]]+="0"*(6-len(str(x)))
  ID[i[2]]+=str(x)
  pre_p=i[0]
for i in ID:
  print(i)

Submission status: Accepted

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

num = {}
for i in range(M):
    P_i, Y_i = map(int, input().split())
    if P_i in num:
        num[P_i].append((Y_i, i))
    else:
        num[P_i] = [(Y_i, i)]

display = [0] * M
for i in num:
    k = str(0) * (6 - len(str(i))) + str(i)
    for index, j in enumerate(sorted(num[i], key=lambda x: x[0])):
        l = str(0) * (6 - len(str(index + 1))) + str(index + 1)
        display[j[1]] = k + l

for item in display:
    print(item)

Submission status: Accepted

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

ans = []

for i in range(M):
   tmp = list(map(int, input().split()))
   tmp.append(i)
   tmp.append(-1)
   
   ans.append(tmp)
   
ans.sort(key=lambda x: x[1])

Check = [1]*N

for i in range(M):
    ans[i][3]=Check[ans[i][0]-1]
    Check[ans[i][0]-1] = Check[ans[i][0]-1]+1
                
ans.sort(key=lambda x: x[2])          

for i in range(M):
    ansA = str(ans[i][0]).zfill(6)
    ansB = str(ans[i][3]).zfill(6)
    tmp = [ansA, ansB]
    print(''.join(tmp))

Submission status: Accepted

Solution code:
N,M = (int(x) for x in input().split())

p_y_list = [0]*M
y_count = [1]*(N+1)

for i in range(M):
    p,y = (int(x) for x in input().split())
    p_y_list[i] = [p,y,i]
p_y_list.sort(key = lambda x:x[1])

for i in p_y_list:
    i[1] = y_count[i[0]]
    y_count[i[0]] += 1

p_y_list.sort(key = lambda x:x[2])
for i in p_y_list:
    print(str(i[0]).rjust(6,"0") + str(i[1]).rjust(6,"0"))

Submission status: Accepted

Solution code:
def main():
  n, m = map(int, input().split())
  a = [list(map(int, input().split())) for _ in range(m)]
  r = [0] * m
  pr = [[] for _ in range(n)]
  for i, x in enumerate(a):
    pr[x[0]-1].append([i, x[1]])
  pr = list(map(lambda x: sorted(x, key=lambda y: y[1]), pr))
  for i, x in enumerate(pr):
    for j, a in enumerate(x):
      r[a[0]] = str(i+1).zfill(6)+str(j+1).zfill(6)
  for x in r:
    print(x)
  
if __name__ == '__main__':
  main()

Submission status: Accepted

Solution code:
N,M = map(int,input().split())
t = [[] for i in range(N)]
ans = []
for i in range(M): 
    p,y = map(int,input().split())
    t[p-1].append([y,i])
    ans.append('')
for i in range(N):
    t[i].sort(key=lambda x:x[0])
    for j in range(len(t[i])):
        ans[t[i][j][1]] = str(i+1).zfill(6)+str(j+1).zfill(6)
for i in range(M):
    print(ans[i])

Submission status: Accepted

Solution code:
N,M = map(int,input().split())
t = [[] for i in range(N)]
ans = []
for i in range(M): 
    p,y = map(int,input().split())
    t[p-1].append([y,i])
    ans.append('')
for i in range(N):
    t[i].sort(key=lambda x:x[0])
    for j in range(len(t[i])):
        ans[t[i][j][1]] = '0'*(6-(len(str(i+1))))+str(i+1)+'0'*(6-(len(str(j+1))))+str(j+1)
for i in range(M):
    print(ans[i])

Submission status: Accepted

Solution code:

n,m = map(int,input().split())
arr = []
for i in range(m):
	ls = list(map(int,input().split()))+[i]
	arr.append(ls)

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

def st(a):
	b = list(str(a))
	while len(b) <= 5:
		b.insert(0,'0')
	c= ''.join(b)
	return c

dic = {}
for j in range(m):
	if arr[j][0] in dic:
		dic[arr[j][0]] += 1
		arr[j] += [dic[arr[j][0]]]
	else:
		dic[arr[j][0]] = 1
		arr[j] += [dic[arr[j][0]]]

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

for y in range(m):
	print('{}{}'.format(st(arr[y][0]), st(arr[y][3])))

Submission status: Accepted

Solution code:
N, M = list(map(int, input().split()))
kens = [[] for _ in range(N)]
for i in range(M):
    x, y = map(int, input().split())
    kens[x - 1].append((y, i))

ans = [[]for i in range(M)]
for i,ken in enumerate(kens):
    ken = sorted(ken)
    ken_number = i + 1
    for j, city in enumerate(ken):
        output_order = city[1]
        rank = j + 1
        ans[output_order] = "%06d%06d" % (ken_number,rank)
for i in ans:
    print(i)

Submission status: Accepted

Solution code:
from itertools import groupby

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

classes = []

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

classes_rank = {}
for key, cls in groupby(sorted(classes, key=lambda x:x[0]), lambda x:x[0]):
  for index, c in enumerate(sorted(list(cls), key=lambda x:x[1])):
    classes_rank[c] = index + 1

for cls in classes:
  P, Y = cls
  rank = classes_rank[ cls ]
  print('{P:06d}{rank:06d}'.format(P=P, rank=rank))

Submission status: Accepted

Solution code:
I=lambda:list(map(int,input().split()))
n,m=I()
a=[[i]+I() for i in range(m)]
a=sorted(a,key=lambda x:(x[1],x[2]))
b=[]
j0=0
p=1
for i,j,k in a:
  p=1 if j!=j0 else p+1
  b.append([i,j,p])
  j0=j
  
for i,j,k in sorted(b):
  print("{:06d}{:06d}".format(j,k))

Submission status: Accepted

Solution code:
I=lambda:list(map(int,input().split()))
n,m=I()
a=[[i]+I() for i in range(m)]
a=sorted(a,key=lambda x:(x[1],x[2]))
b=[]
j0=0
p=1
for i,j,k in a:
  if j!=j0:
    p=1
  else:
    p+=1
  b.append([i,j,p])
  j0=j
b=sorted(b,key=lambda x:x[0])
for i,j,k in b:
  print("{:06d}{:06d}".format(j,k))

Submission status: Accepted

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

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

cityN = [ [] for i in range(n)]
for i in city:
    cityN[i[0]-1].append(i)

for i in range(n):
    if len(cityN[i])>1:
        cityN[i] = sorted(cityN[i], key=lambda x: x[1])
    for j,li in enumerate(cityN[i]):
        li.append(j)

city = []
for i in range(n):
    city.extend(cityN[i])

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

for i in city:
    print(str(i[0]).rjust(6, "0") + str(i[3]+1).rjust(6, "0"))

Submission status: Accepted

Solution code:
import sys
from itertools import chain

s = [
    '100 100\n',
    '12 12\n',
    '13 13\n',
    '14 14\n',
    '12 112\n',
    '13 113\n',
    '14 114\n',
    '12 1212\n',
    '13 1213\n',
    '14 1214\n',
    '12 12312\n',
    '13 12313\n',
    '14 12314\n',
    '2 15\n',
    '3 16\n',
    '4 17\n',
    '2 155\n',
    '2 177\n',
    '2 2\n',
    '3 3\n',
    '4 4\n',
    '2 5\n',
    '3 6\n',
    '4 7\n',
    '2 55\n',
    '2 77\n',
    '2 99',
]

def main():
    s = sys.stdin.readlines()
    # print(s)

    n, m = map(int, s[0].split())
    table = [list(chain([i], list(map(int, py.split())))) for i, py in zip(range(m), s[1:])]

    # print('table1')
    # print(table)

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

    # print('table2')
    # print(table)

    _i = table[0][0]
    _p = table[0][1]
    count = 1
    result = [[_i, _p, count]]

    for i, p, _ in table[1:]:
        if p == _p:
            count += 1
        else:
            count = 1
            _p = p
        result.append([i, p, count])

    # print('result')
    # print(result)

    result.sort(key=lambda x: x[0])
    print('\n'.join([str(p).rjust(6, '0') + str(count).rjust(6, '0') for _, p, count in result]))


if __name__ == '__main__':
    main()