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:
import sys
from io import StringIO
import unittest
import os

# 再帰処理上限(dfs作成時に設定するのが面倒なので限度近い値を組み込む)
sys.setrecursionlimit(999999999)


# 実装を行う関数
def resolve(test_def_name=""):
    # 数値取得サンプル
    #   1行1項目 n = int(input())
    #   1行2項目 x, y = map(int, input().split())
    #   1行N項目 x = list(map(int, input().split()))
    #   N行1項目 x = [int(input()) for i in range(n)]
    #   N行N項目 x = [list(map(int, input().split())) for i in range(n)]

    # 文字取得サンプル
    #   1行1項目 x = input()
    #   1行1項目(1文字ずつリストに入れる場合) x = list(input())
    n, m = map(int, input().split())
    py_s = [list(map(int, input().split())) for i in range(m)]


    num = 0
    city = 0
    city_str = ""
    numdict = {}

    for i in sorted(py_s, key=lambda x: [x[0], int(x[1])]):
        if city != i[0]:
            city = i[0]
            city_str = format(city, '06')
            num = 0
        num += 1
        numdict[i[1]] = "".join([city_str, format(num, '06')])

    for i in py_s:
        print(numdict[i[1]])


# テストクラス
class TestClass(unittest.TestCase):
    def assertIO(self, assert_input, output):
        stdout, sat_in = sys.stdout, sys.stdin
        sys.stdout, sys.stdin = StringIO(), StringIO(assert_input)
        resolve(sys._getframe().f_back.f_code.co_name)
        sys.stdout.seek(0)
        out = sys.stdout.read()[:-1]
        sys.stdout, sys.stdin = stdout, sat_in
        self.assertEqual(out, output)

    def test_input_1(self):
        test_input = """2 3
1 32
2 63
1 12"""
        output = """000001000002
000002000001
000001000001"""
        self.assertIO(test_input, output)

    def test_input_2(self):
        test_input = """2 3
2 55
2 77
2 99"""
        output = """000002000001
000002000002
000002000003"""
        self.assertIO(test_input, output)

    # 自作テストパターンのひな形(利用時は「tes_t」のアンダーバーを削除すること
    def test_original1(self):
        test_input = """100000 4
100000 1000000000
2 1
2 10
2 2
"""
        output = """100000000001
000002000001
000002000003
000002000002"""
        self.assertIO(test_input, output)

    # 自作テストパターンのひな形(利用時は「tes_t」のアンダーバーを削除すること
    def t_est_original2(self):
        test_input = """4 1
1 20
"""
        output = """000001000001"""
        self.assertIO(test_input, output)


# 実装orテストの呼び出し
if __name__ == "__main__":
    if os.environ.get("USERNAME") is None:
        # AtCoder提出時の場合
        resolve()

    else:
        # 自PCの場合
        unittest.main()

Submission status: Accepted

Solution code:
n,m = map(int,input().split())
all_town = [[] for i in range(n)]
for i in range(m):
  p_y = list(map(int,input().split()))
  p_y.append(i)
  all_town[p_y[0]-1].append(p_y)

i_id = []
for town in all_town:
  town.sort(key=lambda x: x[1])
  for i in range(len(town)):
    left = "{:0=6}".format(town[i][0])
    right = "{:0=6}".format(i+1)
    i_id.append([town[i][2],left+right])
    
i_id.sort(key=lambda x: x[0])
for id in i_id:
  print(id[1])

Submission status: Accepted

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

p.sort(key=lambda x:x[2]) 
c = [1]*(n+1)
for i in range(m):
  p[i][2] = c[p[i][1]]
  c[p[i][1]] += 1
p.sort()
for i in range(m):
  print( str(p[i][1]).zfill(6) + str(p[i][2]).zfill(6))

Submission status: Accepted

Solution code:
from collections import defaultdict

def main():
    d = defaultdict(int)
    n, m = [int(i) for i in input().split()]
    py = {}

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

    res = [''] * m
    for v in sorted(py.items(), key=lambda x:x[1]):
        d[v[1][0]] += 1
        res[v[0]] = str(v[1][0]).zfill(6) + str(d[v[1][0]]).zfill(6)
    for r in res:
        print(r)

if __name__ == '__main__':
    main()

Submission status: Accepted

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

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

now=0
p1=items[0][0]
ans=[]
for p,y,ind in items:
    if p==p1:
        now+=1
        tmp=str(p*10**6+now)
        tmp=(12-len(tmp))*"0"+tmp
        ans.append((ind,tmp))
    else:
        now=1
        p1=p
        tmp=str(p*10**6+now)
        tmp=(12-len(tmp))*"0"+tmp
        ans.append((ind,tmp))

ans.sort()
for _ , j in ans:
    print(j)

Submission status: Accepted

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

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

now=0
p1=items[0][0]
ans=[]
for p,y,ind in items:
    if p==p1:
        now+=1
        tmp=str(p*10**6+now)
        tmp=(12-len(tmp))*"0"+tmp
        ans.append((ind,tmp))
    else:
        now=1
        p1=p
        tmp=str(p*10**6+now)
        tmp=(12-len(tmp))*"0"+tmp
        ans.append((ind,tmp))

ans.sort()
for _,j in ans:
    print(j)

Submission status: Accepted

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

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

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

now=0
p1=items[0][0]
ans=[]
for p,y,ind in items:
    
    if p==p1:
        now+=1
        tmp=str(p*10**6+now)
        tmp=(12-len(tmp))*"0"+tmp
        
        ans.append((ind,tmp))
    else:
        now=1
        p1=p
        tmp=str(p*10**6+now)
        tmp=(12-len(tmp))*"0"+tmp
        ans.append((ind,tmp))
ans.sort()
for _ , j in ans:
    print(j)

Submission status: Accepted

Solution code:
N, M, *_PY = map(int, open(0).read().split())
PY = []

for i in range(M):
    PY.append([_PY[i*2],_PY[i*2+1], i+1])
    
now_p = 0

for py in sorted(PY):
    if py[0] != now_p:
        now_p = py[0]
        cnt = 1
    else:
        cnt += 1

    py.append(str(py[0]).zfill(6) + str(cnt).zfill(6))
    
for py in PY:
    print(py[3])

Submission status: Accepted

Solution code:
n,m=map(int,input().split())
PY=sorted([list(map(int,input().split()))+[_] for _ in range(m)],key=lambda x:x[1])

A,B={},[]
for p,y,num in PY:
    if p not in A:
        A[p]=1
        B.append([p,A[p],num])
    else:
        A[p] +=1
        B.append([p,A[p],num])

for a,b,c in sorted(B,key=lambda x:x[2]):
    print(str(a).zfill(6)+str(b).zfill(6))

Submission status: Accepted

Solution code:
import sys, re
from math import ceil, floor, sqrt, pi, factorial, gcd
from copy import deepcopy
from collections import Counter, deque
from heapq import heapify, heappop, heappush
from itertools import accumulate, product, combinations, combinations_with_replacement
from bisect import bisect, bisect_left
from functools import reduce
from decimal import Decimal, getcontext
# input = sys.stdin.readline 
def i_input(): return int(input())
def i_map(): return map(int, input().split())
def i_list(): return list(i_map())
def i_row(N): return [i_input() for _ in range(N)]
def i_row_list(N): return [i_list() for _ in range(N)]
def s_input(): return input()
def s_map(): return input().split()
def s_list(): return list(s_map())
def s_row(N): return [s_input for _ in range(N)]
def s_row_list(N): return [s_list() for _ in range(N)]
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
def lcm(a, b): return a * b // gcd(a, b)
sys.setrecursionlimit(10 ** 6)
INF = float('inf')
MOD = 10 ** 9 + 7
num_list = []
str_list = []

def main():
    n, m = i_map()
    for i in range(m):
        p, y = i_map()
        num_list.append([p, y, i])

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

    ans_list = []
    count_index = 0
    for num in sorted_data:
        if count_index != num[0]:
            count_index = num[0]
            count_num = 1
        else:
            count_num += 1
        ans_num = str(num[0]).zfill(6) + str(count_num).zfill(6)
        ans_list.append([num[2], ans_num])

    ans_list.sort()

    for ans in ans_list:
        print(ans[1])
 
if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
n,m=map(int,input().split())
pre=[[] for _ in range(n)]
for _ in range(m):
    p,y=map(int,input().split())
    pre[p-1].append([y,_,p])
for p in range(n):
    pre[p].sort(key=lambda x:x[0])
    for i in range(len(pre[p])):
        pre[p][i].append(i)
lis=[]
for i in pre:
    for j in i:
        lis.append(j)
lis.sort(key=lambda x:x[1])
for i in lis: print("{:06}{:06}".format(i[2],i[3]+1))

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

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

res = [''] * m
cnt = 1
for i in range(m):
    res[city[i][2]] = str(city[i][0]).zfill(6) + str(cnt).zfill(6)
    if i + 1 < m and city[i][0] == city[i+1][0]:
        cnt += 1
    else:
        cnt = 1


for num in res:
    print(num)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
import numpy as np
from collections import deque
from collections import defaultdict
import heapq
import collections
import itertools
import bisect


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


def z():
    return int(input())


def S():
    return input()


def C(line):
    return [input() for _ in range(line)]


N, M = zz()
P, Y = [], []
years = defaultdict(list)
ids = defaultdict(list)
# years: [city_id, year]
for i in range(M):
    p, y = zz()
    years[p].append(y)
    ids[p].append(i)
# print(years)
ans = ['']*M
for p in years:
    c = zip(years[p], ids[p])
    c = sorted(c)
    year, id = zip(*c)
    for i, id_ in enumerate(id):
        i = i + 1
        ans[id_] = str(p).zfill(6) + str(i).zfill(6)
for a in ans:
    print(a)
# print(*ans)

# .zfill(6)

Submission status: Accepted

Solution code:
from collections import defaultdict

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

code = [0] * m
ctr = defaultdict(int)
for i in range(m):
    ctr[yp[i][1]] += 1
    x = ctr[yp[i][1]]
    code[yp[i][2]] = '{:06}{:06}'.format(yp[i][1], x)
for c in code:
    print(c)

Submission status: Accepted

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

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

py = []
city = {i+1: [] for i in range(n)}
for i in range(m):
    p, y = list(map(int, input().split()))
    city[p].append(y)
    py.append([p, y])


for i in city.values():
    i.sort()
# print(city)

ans = {i+1: {} for i in range(n)}
for key, value in city.items():
    for i in range(len(value)):
        ans[key][value[i]] = i+1

for p, y in py:
    # print(p, ans[p][y])
    print("{:06}{:06}".format(p, ans[p][y]))

Submission status: Accepted

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

Nl = [[] for i in range(N)]
# Pl = []

for i in range(M):
    P, Y = map(int, input().split())
    # Pl.append(P-1)
    Nl[P-1].append({"year": Y, "index": i, "pref": P-1})
newl = []
for i in Nl:
    i.sort(key=lambda x: x["year"])
    num = 1
    for j in i:
        j["order"] = num
        num += 1
    newl += i


newl.sort(key=lambda x: x["index"])

for i in newl:

    print("{:06}".format(i["pref"]+1), end="")
    print("{:06}".format(i["order"]))

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
"""
Created on Sat Jun 20 09:11:30 2020

@author: NEC-PCuser
"""

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

Submission status: Accepted

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

for i in range(len(l)):
  L[l[i][0]-1].append([l[i][1],i+1])
  
for ind,lis in enumerate(L):
  lis.sort()
  for j in range(len(lis)):
    ans[lis[j][1] - 1] = str(ind+1).zfill(6) + str(j+1).zfill(6)
    
print(*ans,sep = '\n')

Submission status: Accepted

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

for i in range(len(l)):
  L[l[i][0]-1].append([l[i][1],i+1])
  
for ind,lis in enumerate(L):
  lis.sort()
  for j in range(len(lis)):
    ans[lis[j][1] - 1] = str(ind+1).zfill(6) + str(j+1).zfill(6)
    
print(*ans,sep = '\n')

Submission status: Accepted

Solution code:
import bisect
n,m=map(int,input().split())
a=dict()
b=[]
for i in range(m):
    p,y=map(int,input().split())
    b.append((p,y))
    if p not in a:
        a[p]=[y]
    else:
        a[p]+=[y]
for i,l in a.items():
    a[i]=sorted(l)
for p,y in b:
    index=bisect.bisect_left(a[p],y)+1
    a1=str(p).zfill(6)
    a2=str(index).zfill(6)
    print(a1+a2)

Submission status: Accepted

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

p = []
for i in range(m):
  x = str(i)+' '+input()
  p.append(list(map(int,x.split())))

p.sort(key=lambda x:x[2]) 
c = [1]*(n+1)
for i in range(m):
  p[i][2] = c[p[i][1]]
  c[p[i][1]] += 1
p.sort()
for i in range(m):
  print( str(p[i][1]).zfill(6) + str(p[i][2]).zfill(6))

Submission status: Accepted

Solution code:
def main():
    import sys
    input = sys.stdin.readline

    N, M = map(int, input().split())
    PY = {}
    for i in range(1, M+1):
        p, y = map(int,input().split())
        if p not in PY.keys():
            PY[p] = []
        PY[p].append((y, i))
    numbers = [0] * (1+M)
    for p in PY.keys():
        PY[p].sort(reverse=True)
        rank = 1
        while PY[p]:
            year, i = PY[p].pop()
            num = str(p).zfill(6) + str(rank).zfill(6)
            rank += 1
            numbers[i] = num
            
    for i in range(1, M+1):
        print(numbers[i])


main()

Submission status: Accepted

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

# p:県　y:誕生年
py=[]

# [p y number]
for i in range(m):
    py.append(list(map(int,input().split())))
    py[i].append(i)
py=sorted(py,key= lambda x:(x[0],x[1]))

for i in range(m):
    if i==0:
        py[i][1]=1
    else:
        if py[i][0]==py[i-1][0]:
            py[i][1]=py[i-1][1]+1
        else:
            py[i][1]=1
py=sorted(py,key=lambda x:(x[2]))

for i in range(m):
    temp1="0"*(6-len(str(py[i][0])))+str(py[i][0])
    temp2="0"*(6-len(str(py[i][1])))+str(py[i][1])
    print(temp1+temp2)

Submission status: Accepted

Solution code:
N,M = map(int,input().split())
digit = 'zero padding: {:0=6}'
dic = [[] for _ in range(N+1)]

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

for p in dic:
    p.sort()

ans = [None for _ in range(M)]
for k in range(1,N+1):
    p = dic[k]
    for j in range(len(p)):
        i = p[j][1]
        ID = str(k).zfill(6)+str(j+1).zfill(6)
        ans[i] = ID

for a in ans:
    print(a)

Submission status: Accepted

Solution code:
N,M=map(int,input().split())
P=[list(map(int,input().split())) for _ in range(M)]
for i in range(M):
  P[i].append(i)
P.sort()
j=1
k=0
for i in range(M):
  k+=1
  if P[i][0]!=j:
    j=P[i][0]
    k=1
  s=str(j)
  while len(s)!=6:
    s='0'+s
  t=str(k)
  while len(t)!=6:
    t='0'+t
  P[i].append(s+t)
P.sort(key=lambda x:x[2])
for i in range(M):
  print(P[i][3])

Submission status: Accepted

Solution code:
N, M = map(int, input().split())
ls = []
for i in range(M):
    p, y = map(int, input().split())
    ls.append([i, p, y])
ls.append([float('inf'), float('inf'), 1])
ls.sort(key=lambda x: x[1])
rem = []
ans = []
cur_p = -1
for i in range(M+1):
    if ls[i][1] == float('inf'):
        rem.sort(key=lambda x: x[2])
        for j in range(len(rem)):
            rem_j = rem[j][:]
            rem_j.append('0'*(6-len(str(rem_j[1]))) + str(rem_j[1]) + '0'*(6-len(str(j+1))) + str(j+1))
            ans.append(rem_j)
        break
    if cur_p != ls[i][1]:
        if len(rem) != 0:
            rem.sort(key=lambda x: x[2])
            for j in range(len(rem)):
                rem_j = rem[j][:]
                rem_j.append('0'*(6-len(str(rem_j[1]))) + str(rem_j[1]) + '0'*(6-len(str(j+1))) + str(j+1))
                ans.append(rem_j)
            cur_p = ls[i][1]
            rem = []
            rem.append(ls[i])
        else:
            rem.append(ls[i])
            cur_p = ls[i][1]
    else:
        rem.append(ls[i])
ans.sort(key=lambda x: x[0])
for x in ans:
    print(x[-1])

Submission status: Accepted

Solution code:
N, M = map(int, input().split())
G = [[] for _ in range(N)]
res = [10 ** 12] * M
for i in range(M):
    p, y = map(int, input().split())
    G[p - 1].append((y, i))

G = list(map(sorted, G))
for p in range(N):
    for m, (y, i) in enumerate(G[p], 1):
        res[i] += (p + 1) * 10 ** 6 + m

for r in res:
    print(str(r)[1:])

Submission status: Accepted

Solution code:
N, M = map(int, input().split())
G = [[] for _ in range(N)]
res = [""] * M
for i in range(M):
    p, y = map(int, input().split())
    G[p - 1].append((y, i))

G = list(map(sorted, G))
for p in range(N):
    for m, (y, i) in enumerate(G[p], 1):
        res[i] = 10 ** 12 + (p + 1) * 10 ** 6 + m

for r in res:
    print(str(r)[1:])

Submission status: Accepted

Solution code:
n, m = map(int, input().split())
d = [[] for _ in range(n)]
for i in range(m):
    p, y = map(int, input().split())
    d[p-1].append((y, i))
d = list(map(sorted, d))
ans = [0] * m
for p in range(n):
    for x, (y, i) in enumerate(d[p], 1):
        ans[i] = (p + 1) * 10 ** 6 + x
for a in ans:
    print(str(a + 10 ** 12)[1:])

Submission status: Accepted

Solution code:
from collections import defaultdict,deque
from sys import stdin,setrecursionlimit
import heapq,bisect,math,itertools,string,queue,datetime,copy
setrecursionlimit(10**8)
INF = float('inf')
mod = 10**9+7
eps = 10**-7
def inpl(): return list(map(int, stdin.readline().split()))

N,M = inpl()
prefe = defaultdict(list)
for i in range(M):
    p,m = inpl()
    prefe[p].append((m,i+1))

anls = [[] for _ in range(M)]
for a,item in prefe.items():
    item.sort()
    jyun = []
    for b in item:
        ind = bisect.bisect_left(item,b) + 1
        jyun.append([ind,b[1]])
    for item2 in jyun:
        anls[item2[1]-1].append((a,item2[0]))

for item3 in anls:
    print(str(item3[0][0]).zfill(6) + str(item3[0][1]).zfill(6))

Submission status: Accepted

Solution code:
from bisect import bisect_right

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

Ps, Ys, vals = [], [], {}
for i in range(M):
  P, Y = map(int, input().split())
  Ps.append(P)
  Ys.append(Y)

  if P not in vals:
    vals[P] = []
  vals[P].append(Y)

for P in vals:
  vals[P].sort()

for i in range(M):
  pref = str(Ps[i]).zfill(6)
  city = str(bisect_right(vals[Ps[i]], Ys[i])).zfill(6)
  print(pref + city)

Submission status: Accepted

Solution code:
from bisect import bisect_right
n,m=map(int,input().split())
p,y=[],[]
l={}
for i in range(m):
 p_,y_=map(int,input().split())
 p.append(p_)
 y.append(y_)
 if not p_ in l:l[p_] = []
 l[p_].append(y_)
for i in l:
 l[i].sort()
for i in range(m):
 print(str(p[i]).zfill(6)+str(bisect_right(l[p[i]],y[i])).zfill(6))

Submission status: Accepted

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

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

ans=[0]*m

for i, d in enumerate(D):
    d.sort()
    for k, (y, j) in enumerate(d):
        ans[j]=str(i+1).zfill(6) + str(k+1).zfill(6)

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

Submission status: Accepted

Solution code:
import heapq

N, M = map(int, input().split())
P_list = []
ans = []

for i in range(N+1):
    P_list.append([])

for i in range(M):
    P, Y = map(int, input().split())
    Y = Y * 10 ** 6 + i
    P_list[P].append(Y)

for i in range(N+1):
    P_list[i].sort()
    for j, k in enumerate(P_list[i]):
        tmp = (k % 10**6 + 1) * 10**12 + i * 10**6 + j + 1
        ans.append(tmp)

heapq.heapify(ans)

for i in range(M):
    pr = heapq.heappop(ans)
    ans_pr = str(pr % 10**12)
    print(ans_pr.zfill(12))

Submission status: Accepted

Solution code:
from bisect import bisect_right

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

Ps, Ys, vals = [], [], {}
for i in range(M):
  P, Y = map(int, input().split())
  Ps.append(P)
  Ys.append(Y)

  if P not in vals:
    vals[P] = []
  vals[P].append(Y)

for P in vals:
  vals[P].sort()

for i in range(M):
  pref = str(Ps[i]).zfill(6)
  city = str(bisect_right(vals[Ps[i]], Ys[i])).zfill(6)
  print(pref + city)

Submission status: Accepted

Solution code:
import sys
import math
import itertools
import bisect
from copy import copy
from collections import deque,Counter
from decimal import Decimal
def s(): return input()
def i(): return int(input())
def S(): return input().split()
def I(): return map(int,input().split())
def L(): return list(input().split())
def l(): return list(map(int,input().split()))
def lcm(a,b): return a*b//math.gcd(a,b)
sys.setrecursionlimit(10 ** 9)
mod = 10**9+7

N,M = I()
C = [[] for _ in range(N+1)]
for i in range(M):
    p,y = I()
    C[p].append([y,i])
ans = ['a']*M
for i in range(1,len(C)):
    c = C[i]
    if c:
        c.sort()
        for j in range(len(c)):
            y,b = c[j]
            ans[b] = str(i).zfill(6)+str(j+1).zfill(6)
for a in ans:
    print(a)

Submission status: Accepted

Solution code:
(N, M, _), *PY = [list(map(int, s.split())) + [i] for i, s in enumerate(open(0))]
prev_p = 0
city_cnt = 1
PY.sort()
for i in range(M):
    p, y, _ = PY[i]
    if p != prev_p:
        city_cnt = 1
        prev_p = p
    PY[i].append(str(p).zfill(6) + str(city_cnt).zfill(6))
    city_cnt += 1
PY.sort(key=lambda x: x[2])
[print(x[-1]) for x in PY]

Submission status: Accepted

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

N, M = map(int, input().split())
PY = [map(int, input().split()) for i in range(M)]
PYI = sorted((p, y, i+1) for i, (p, y) in enumerate(PY))
def gen():
  pre = -1
  count = -1
  for p, y, i in PYI:
    if p == pre:
      count += 1
      yield (i, str(1*10**12+p*10**6+count)[1:])
    else:
      count = 1
      yield (i, str(1*10**12+p*10**6+count)[1:])
      pre = p
print('\n'.join(i[1] for i in sorted(gen())))

Submission status: Accepted

Solution code:
n,m = map(int,input().split())
p = [0]*m
V = [[] for i in range(n+1)]
for i in range(m):
    p[i] = list(map(int,input().split())) + [i]
    V[p[i][0]].append(p[i][1:])
W = []
for i in range(n+1):
    if V[i] == []:
        pass
    else:
        V[i].sort(key= lambda val : val[0])
        for j in range(len(V[i])):
            K = ["0"]*(6 - len(str(i))) + list(str(i)) + ["0"]*(6 - len(str(j+1))) + list(str(j+1))
            W.append(["".join(K),V[i][j][1]])
W.sort(key= lambda val : val[1])
for ans in W:
    print(ans[0])

Submission status: Accepted

Solution code:
n,m = map(int,input().split())
p = [0]*m
V = [[] for i in range(n+1)]
for i in range(m):
    p[i] = list(map(int,input().split())) + [i]
    V[p[i][0]].append(p[i][1:])
W = []
for i in range(n+1):
    if V[i] == []:
        pass
    else:
        V[i].sort(key= lambda val : val[0])
        for j in range(len(V[i])):
            K = ["0"]*(6 - len(str(i))) + list(str(i)) + ["0"]*(6 - len(str(j+1))) + list(str(j+1))
            W.append(["".join(K),V[i][j][1]])
W.sort(key= lambda val : val[1])
for ans in W:
    print(ans[0])

Submission status: Accepted

Solution code:
import itertools
def main():
    n, m = list(map(int, input().split()))
    A = [[] for _ in range(n)]
    for i in range(m):
        p, y = list(map(int, input().split()))
        A[p - 1].append([i, y])
    for i, a in enumerate(A):
        a.sort(key = lambda x: x[1])
        for j in range(len(a)):
            a[j] = [a[j][0], '{:06}{:06}'.format(i + 1, j + 1)]
    A = list(itertools.chain.from_iterable(A))
    A.sort(key = lambda x: x[0])
    for a in A:
        print(a[1])

if __name__ == '__main__':
    main()

Submission status: Accepted

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

def main():
    n, m = map(int, input().split())
    
    def readlines():
        for i in range(m):
            p, y = map(int, input().split())
            yield p, y, i

    cityies = sorted(readlines())

    def convert():
        prev = 0
        now = 1
        for p, y, i in cityies:
            if p == prev:
                now += 1
            else:
                now = 1
            yield i, "{:06}{:06}".format(p, now)

            prev = p

    print("\n".join(number for i, number in sorted(convert())))


main()

Submission status: Accepted

Solution code:
n,m = map(int,input().split())
pyl = [list(map(int,input().split())) for nesya in range(m)]
predic = dict()
ydic = dict()
spyl = sorted(pyl,key = lambda x:x[1])
for py in spyl:
  p = py[0]
  y = py[1]
  if p in predic:
    predic[p] += 1
  else:
    predic[p] = 1
  ydic[y] = (str(p).zfill(6))+(str(predic[p]).zfill(6))
for hoge in pyl:
  print(ydic[hoge[1]])

Submission status: Accepted

Solution code:
para_line = list(map(int,input().split(' ')))
city = []
for i in range(para_line[1]):
    line = list(map(int,input().split(' ')))
    city.append(line+[i])
city.sort(key = lambda a: a[1])
city_cnt = [0 for k in range(para_line[0])]
for n in range(para_line[1]):
    city_cnt[city[n][0]-1] += 1
    city[n].append(str(city[n][0]).zfill(6)+str(city_cnt[city[n][0]-1]).zfill(6))
city.sort(key = lambda b: b[2])
for j in city:
    print(j[3])

Submission status: Accepted

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

INF = float("inf")

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

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

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

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

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

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

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

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

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

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

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

def S():
    return input()

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

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

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

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

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

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

py_new = mysort(py_new,2,False)

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

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

py_now = mysort(py_now,0,False)

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