Problem:


Score: 300 points

Problem Statement

In Republic of Atcoder, there are N prefectures, and a total of M cities that belong to those prefectures.

City i is established in year Y_i and belongs to Prefecture P_i.

You can assume that there are no multiple cities that are established in the same year.

It is decided to allocate a 12-digit ID number to each city.

If City i is the x-th established city among the cities that belong to Prefecture i, the first six digits of the ID number of City i is P_i, and the last six digits of the ID number is x.

Here, if P_i or x (or both) has less than six digits, zeros are added to the left until it has six digits.

Find the ID numbers for all the cities.

Note that there can be a prefecture with no cities.

Constraints

1 \leq N \leq 10^5

1 \leq M \leq 10^5

1 \leq P_i \leq N

1 \leq Y_i \leq 10^9

Y_i are all different.

All values in input are integers.

Input

Input is given from Standard Input in the following format:

N M
P_1 Y_1
:
P_M Y_M

Output

Print the ID numbers for all the cities, in ascending order of indices (City 1, City 2, ...).

Sample Input 1

2 3
1 32
2 63
1 12

Sample Output 1

000001000002
000002000001
000001000001

As City 1 is the second established city among the cities that belong to Prefecture 1, its ID number is 000001000002.

As City 2 is the first established city among the cities that belong to Prefecture 2, its ID number is 000002000001.

As City 3 is the first established city among the cities that belong to Prefecture 1, its ID number is 000001000001.

Sample Input 2

2 3
2 55
2 77
2 99

Sample Output 2

000002000001
000002000002
000002000003



Sample input:
2 3
1 32
2 63
1 12


Sample output:
000001000002
000002000001
000001000001

Submission status: Accepted

Solution code:
N,M = map(int,input().split())
d=[0]*M
res = []
for i in range(M):
    P,Y = map(int,input().split())
    res.append((P,Y,i))
c=0
res.sort()
t = str(res[0][0])
for i in res:
    x = str(i[0])
    tmp = (6-len(x))*'0'+x+(6-len(str(c)))*'0'+str(c)
    if x == t:
        c+=1
    else:
        c=1
        t = x
    d[i[2]] = (6-len(x))*'0'+x+(6-len(str(c)))*'0'+str(c)

for i in d:
    print(i)

Submission status: Accepted

Solution code:
def main():
    import sys
    input = sys.stdin.readline
    sys.setrecursionlimit(10**7)
    from collections import Counter, deque
    #from collections import defaultdict
    from itertools import combinations, permutations, accumulate, groupby
    #from itertools import product
    from bisect import bisect_left,bisect_right
    from heapq import heapify, heappop, heappush
    from math import floor, ceil
    #from operator import itemgetter

    #inf = 10**17
    #mod = 10**9 + 7

    n,m = map(int, input().split())
    py = [list(map(int, input().split())) for _ in range(m)]
    #l[i]:県iの市
    l = [[] for _ in range(n+1)]
    for p, y in py:
        l[p].append(y)
    for i in range(n+1):
        l[i].sort()
    for p, y in py:
        a = bisect_left(l[p], y) + 1
        print('{:06d}{:06d}'.format(p, a))



if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import bisect
n,m = map(int,input().split())
l = [list(map(int,input().split())) for i in range(m)]
ls = sorted(l,key=lambda x:x[1])
dict = {}
for i in ls:
    p,y = i
    if not p in dict.keys():
        dict[p] = []
        dict[p].append(y)
    else:
        dict[p].append(y)
for j in l:
    p,y = j
    print('{:0=6}'.format(p)+'{:0=6}'.format(bisect.bisect_left(dict[p],y) + 1))

Submission status: Accepted

Solution code:
from collections import deque
from collections import Counter, defaultdict
from itertools import product, permutations,combinations
from operator import itemgetter
from heapq import heappop, heappush
from bisect import bisect_left, bisect_right, bisect
#pypyではscipy, numpyは使えない
#from scipy.sparse.csgraph import shortest_path, floyd_warshall, dijkstra, bellman_ford, johnson, minimum_spanning_tree
#from scipy.sparse import csr_matrix, coo_matrix, lil_matrix
import numpy as np
from fractions import gcd
from math import ceil,floor, sqrt, cos, sin, pi, factorial
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10**8)
INF = float('inf')
MOD = 10**9+7

def main():
  n, m = map(int, readline().split())
  py = [[int(x) for x in readline().split()] for _ in range(m)]
  p_to_y = defaultdict(set)
  for p, y in py:
    p_to_y[p].add(y)
  
  def set_to_rank_dict(se):
    return {x:i for i, x in enumerate(sorted(se), 1)}
  
  p_to_y = {p:set_to_rank_dict(se) for p, se in p_to_y.items()}
  for p, y in py:
    print('{:06g}{:06}'.format(p,p_to_y[p][y]))
  
  
  
  
if __name__ == '__main__':
  main()

Submission status: Accepted

Solution code:
import bisect
n, m = [int(x) for x in input().split()]
city = [[int(x) for x in input().split()] for i in range(m)]
city_sd = sorted(city, key=lambda y:y[1])
dict = {}
for c in city_sd:
  p, y = c
  if not p in dict.keys():
    dict[p] = []
    dict[p].append(y)
  else:
    dict[p].append(y)
for c in city:
  p, y = c
  print('{:0=6}'.format(p)+'{:0=6}'.format(bisect.bisect_left(dict[p], y) + 1))

Submission status: Accepted

Solution code:
n, m = map(int, input().split())
ans = [0] * m
G = [[] for _ in range(n + 1)]
for i in range(m):
    p, y = map(int, input().split())
    G[p].append([y, i])
for i in range(1, n + 1):
    g = G[i]
    g.sort()
    for j in range(len(g)):
        f = g[j]
        s = ["0"] * (6 - len(str(i))) + [str(i)]
        t = ["0"] * (6 - len(str(j + 1))) + [str(j + 1)]
        ans[f[1]] = "".join(s + t)
for i in ans:
    print(i)

Submission status: Accepted

Solution code:
mod = 10 ** 9 + 7
mod2 = 2**61+1
from collections import deque
import heapq
from bisect import bisect_left, insort_left, bisect_right

def iip(listed=True):
    ret = [int(i) for i in input().split()]
    if len(ret) == 1 and not listed:
        return ret[0]
    return ret

def iip_ord():
    return [ord(i) - ord("a") for i in input()]


def main():
    ans = solve()
    if ans is not None:
        print(ans)

def solve():
    N, M = iip(False)


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

    nn = {}
    data.sort(key=lambda x:x[1])
    for i in data:
        nn[i[0]] = 0

    result = []
    for i in data:
        nn[i[0]] += 1
        a = i[0] * 10**6 + nn[i[0]]
        a = str(a).zfill(12)
        result.append((a, i[2]))

    result.sort(key=lambda x:x[1])
    result = [i[0] for i in result]
    split_print_enter(result)



#####################################################ライブラリ集ここから

def fprint(s):
    for i in s:
        print(i)

def split_print_space(s):
    print(" ".join([str(i) for i in s]))


def split_print_enter(s):
    print("\n".join([str(i) for i in s]))


def koenai_saidai_x_index(sorted_list, n):
    l = 0
    r = len(sorted_list)
    if len(sorted_list) == 0:
        return False
    if sorted_list[0] > n:
        return False

    while r - l > 1:
        x = (l + r) // 2
        if sorted_list[x] == n:
            return x
        elif sorted_list[x] > n:
            r = x
        else:
            l = x
    return l


def searchsorted(sorted_list, n, side):
    if side not in ["right", "left"]:
        raise Exception("sideはrightかleftで指定してください")

    l = 0
    r = len(sorted_list)

    if n > sorted_list[-1]:
        # print(sorted_list)
        return len(sorted_list)
    if n < sorted_list[0]:
        return 0

    while r - l > 1:
        x = (l + r) // 2
        if sorted_list[x] > n:
            r = x
        elif sorted_list[x] < n:
            l = x
        else:
            if side == "left":
                r = x
            elif side == "right":
                l = x

    if side == "left":
        if sorted_list[l] == n:
            return r - 1
        else:
            return r

    if side == "right":
        if sorted_list[l] == n:
            return l + 1
        else:
            return l


def soinsuu_bunkai(n):
    ret = []
    for i in range(2, int(n ** 0.5) + 1):
        while n % i == 0:
            n //= i
            ret.append(i)
        if i > n:
            break
    if n != 1:
        ret.append(n)
    return ret


def conbination(n, r, mod, test=False):
    if n <= 0:
        return 0
    if r == 0:
        return 1
    if r < 0:
        return 0
    if r == 1:
        return n
    ret = 1
    for i in range(n - r + 1, n + 1):
        ret *= i
        ret = ret % mod

    bunbo = 1
    for i in range(1, r + 1):
        bunbo *= i
        bunbo = bunbo % mod

    ret = (ret * inv(bunbo, mod)) % mod
    if test:
        # print(f"{n}C{r} = {ret}")
        pass
    return ret


def inv(n, mod):
    return power(n, mod - 2)


def power(n, p, mod_= mod):
    if p == 0:
        return 1
    if p % 2 == 0:
        return (power(n, p // 2, mod_) ** 2) % mod_
    if p % 2 == 1:
        return (n * power(n, p - 1, mod_)) % mod_


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
n,m=(int(i) for i in input().split())
p=[[int(i) for i in input().split()] for i in range(m)]
c=[0]*(n)
i={}
for pe,pk in sorted(p, key=lambda x: x[1]):
  c[pe-1]+= 1
  i[pk]='%06d%06d' % (pe, c[pe-1])
for _,pk in p:
  print(i[pk])

Submission status: Accepted

Solution code:
n,m=map(int,input().split())
py=[[0,0,0]]*m
for i in range(m):
  py[i]=list(map(int,input().split()))+[i]
ans=['']*m
a=sorted(py)
j=0
for i in range(len(a)):
  if i>0 and a[i-1][0]<a[i][0]:
    j=1
  else:
    j+=1
  ans[a[i][2]]='{:06}'.format(a[i][0])+'{:06}'.format(j)
for i in range(m):
  print(ans[i])

Submission status: Accepted

Solution code:
N,M=map(int,input().split())
ids=[]
x=[]
numofpref=1
for i in range(M):
    p,y=map(int,input().split())
    ids.append([p,y,i,0])
#print(ids)
x=sorted(ids,key=lambda x:x[1])	#まず、下軸要素(同着の中では~)をsortedでソートする
x.sort(key=lambda x:x[0])
#print(x)
for i in range(M):
    if i==0:
        x[i][3]="".join((str(x[i][0]).zfill(6),str(numofpref).zfill(6)))
        numofpref=numofpref+1
    else:
        if x[i][0]!=x[i-1][0]:
            numofpref=1
        x[i][3]="".join((str(x[i][0]).zfill(6),str(numofpref).zfill(6)))
        numofpref=numofpref+1
x.sort(key=lambda x:x[2])
for i in range(M):
    print(x[i][3])

Submission status: Accepted

Solution code:
def main():
    import bisect
    n, m, *py = map(int, open(0).read().split())
    d = [[] for _ in range(n+1)]
    for i,j in zip(*[iter(py)]*2):
        d[i].append(j)

    for i in d:
        i.sort()

    ans = ''
    for i, j in zip(*[iter(py)] * 2):
        k = bisect.bisect_right(d[i], j)
        ans += str(i).zfill(6) + str(k).zfill(6) + '\n'

    print(ans)


if __name__ == '__main__':
    main()

Submission status: Accepted

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

import sys
import math
from bisect import bisect_right as br
from bisect import bisect_left as bl
sys.setrecursionlimit(2147483647)
from heapq import heappush, heappop,heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
inf = float('inf')
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))

n,m = LI()
py = [LI()+[i] for i in range(m)]

py.sort(key = lambda x:(x[0],x[1]))
ans = []
flag = True
cnt = 0
for p,y,i in py:
    s = '0'*6
    t = '0'*6
    if flag:
        cnt += 1
        tmp = p
        flag = False
    elif tmp == p:
        cnt += 1
    else:
        cnt = 1
        tmp = p
    s += str(p)
    s = s[-6:]
    t += str(cnt)
    t = t[-6:]
    ans.append([s+t,i])
ans.sort(key = lambda x:x[1])
for i,j in ans:
    print(i)

Submission status: Accepted

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

import numpy as np

# line1 = "2 3"
# line2 = ['1 32', '2  63', '1 12']

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

PY = np.array(PY)
cn = np.array([np.arange(np.shape(PY)[0])])
cc = np.array([np.zeros(np.shape(PY)[0], dtype=int)])

city_list = np.hstack([cn.T, PY, cc.T])
cl_ysort = city_list[np.argsort(city_list[:, 2])]
city_count = np.zeros(N+1, dtype=int)
for i, cinfo in enumerate(cl_ysort):
    pref = cinfo[1]
    city_count[pref] += 1
    cl_ysort[i, 3] = city_count[pref]

cl_idsort = cl_ysort[np.argsort(cl_ysort[:, 0])]

[print('{:06d}{:06d}'.format(cl[1], cl[3])) for cl in cl_idsort]

Submission status: Accepted

Solution code:
N,M = map(int,input().split())
PYlist = []
for i in range(M):
    PYlist_ele = list(map(int,input().split()))
    PYlist_ele.append(i+1)
    PYlist.append(PYlist_ele)
PYlist.sort()
check = 0
count = 0
P_id = []
for i in range(M):
    if check == PYlist[i][0]:
        count +=1
    else:
        count = 1
        check = PYlist[i][0]
    idup = '{:06}'.format(PYlist[i][0])
    iddown = '{:06}'.format(count)
    P_id.append([str(idup)+str(iddown),PYlist[i][2]])
P_id.sort(key=lambda x: x[1])
for ans in P_id:
    print(ans[0])

Submission status: Accepted

Solution code:
import copy
n,m = map(int,input().split())
a = []
ans = dict()
for i in range(m):
    p,y = map(int,input().split())
    a.append((p,y))
adc = copy.deepcopy(a)
a.sort()
cnt = 1
for i in range(m-1):
    num = str(a[i][0]).zfill(6) + str(cnt).zfill(6)
    ans[a[i]] = num
    if a[i+1][0] != a[i][0]:
        cnt = 1
    else:
        cnt += 1
num = str(a[-1][0]).zfill(6) + str(cnt).zfill(6)
ans[a[-1]] = num
for i in range(m):
    print(ans[(adc[i][0], adc[i][1])])

Submission status: Accepted

Solution code:
n, m = map(int, input().split())
p_y_num_list = sorted([list(map(int, input().split())) + [i] for i in range(m)])
now = p_y_num_list[0][0]
num = 1
for pyn in p_y_num_list:
    if pyn[0] != now:
        num = 1
        now = pyn[0]
        pyn.append(num)
    else:
        pyn.append(num)
    num += 1
p_y_num_list.sort(key=lambda x: x[2])
for p, y, i, n in p_y_num_list:
    print("{:06}{:06}".format(p, n))

Submission status: Accepted

Solution code:
import bisect as bis
n, m = map(int, input().split())
p, y = [], []
idx = lambda x: x-1
for _ in range(m):
    p_, y_ = map(int, input().split())
    p.append(p_)
    y.append(y_)
val = [[] for _ in range(n)]
for i in range(m):
    val[idx(p[i])].append(y[i])
for i in range(n):
    val[i].sort()
for i in range(m):
    v = p[i]
    id = bis.bisect_right(val[idx(v)], y[i])
    print(str(v).zfill(6) + str(id).zfill(6))

Submission status: Accepted

Solution code:
import bisect as bis
n, m = map(int, input().split())
idx = lambda x: x-1
p, y = [], []
for _ in range(m):
    p_, y_ = map(int, input().split())
    p.append(p_)
    y.append(y_)
val = [[] for _ in range(n)]
for i, j in zip(p, y):
    val[idx(i)].append(j)
for i in range(n):
    val[i].sort()
for i in range(m):
    v = p[i]
    id = bis.bisect_right(val[idx(v)], y[i])
    print(str(v).zfill(6) + str(id).zfill(6))

Submission status: Accepted

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

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

liss = sorted(lis)
dic = {}
cnt = [0] * n

for i in range(m):
    x, y = liss[i]
    cnt[x - 1] += 1
    xx, yy, cc = str(x), str(y), str(cnt[x - 1])
    id = "0" * (6-len(xx)) + xx + "0" * (6-len(cc)) + cc
    dic[xx + "_" + yy] = id

for x, y in lis:
    xx, yy = str(x), str(y)
    print(dic[xx + "_" + yy])

Submission status: Accepted

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

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

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

#print(city_list)

tmp_list = [0]*m
tmp_num = 1
for num,j in enumerate(city_list):
    if num == 0:
        tmp_list[j[2]] = str(j[0]).zfill(6)+str(tmp_num).zfill(6)
        j_tmp = j[0]
        tmp_num += 1
    else:
        if j[0] != j_tmp:
            j_tmp = j[0]
            tmp_num = 1
            tmp_list[j[2]] = str(j[0]).zfill(6)+str(tmp_num).zfill(6)
            tmp_num += 1
        else:
            tmp_list[j[2]] = str(j[0]).zfill(6)+str(tmp_num).zfill(6)
            tmp_num += 1

for k in tmp_list:
    print(k)

Submission status: Accepted

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

for i in range(M):
  P,Y=map(int,input().split())
  li.append([P,Y,i])
li.sort(key=lambda x:x[1])
li.sort(key=lambda x:x[0])
pre=li[0][0]
cnt=1
ans=[]

for p,y,i in li:
  if p==pre:
    ans.append([str(p).zfill(6)+str(cnt).zfill(6),i])
    cnt+=1
  else:
    pre=p
    ans.append([str(p).zfill(6)+str(1).zfill(6),i])
    cnt=2
ans.sort(key=lambda x:x[1])

for a,i in ans:
  print(a)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
import sys
import math
import os
import itertools
import string
import heapq
import _collections
from collections import Counter
from collections import defaultdict
from functools import lru_cache
import bisect
import re
import queue
from decimal import *


class Scanner():
    @staticmethod
    def int():
        return int(sys.stdin.readline().rstrip())

    @staticmethod
    def string():
        return sys.stdin.readline().rstrip()

    @staticmethod
    def map_int():
        return [int(x) for x in Scanner.string().split()]

    @staticmethod
    def string_list(n):
        return [input() for i in range(n)]

    @staticmethod
    def int_list_list(n):
        return [Scanner.map_int() for i in range(n)]

    @staticmethod
    def int_cols_list(n):
        return [int(input()) for i in range(n)]


class Math():
    @staticmethod
    def gcd(a, b):
        if b == 0:
            return a
        return Math.gcd(b, a % b)

    @staticmethod
    def lcm(a, b):
        return (a * b) // Math.gcd(a, b)

    @staticmethod
    def divisor(n):
        res = []
        i = 1
        for i in range(1, int(n ** 0.5) + 1):
            if n % i == 0:
                res.append(i)
                if i != n // i:
                    res.append(n // i)
        return res

    @staticmethod
    def round_up(a, b):
        return -(-a // b)

    @staticmethod
    def is_prime(n):
        if n < 2:
            return False
        if n == 2:
            return True
        if n % 2 == 0:
            return False
        d = int(n ** 0.5) + 1
        for i in range(3, d + 1, 2):
            if n % i == 0:
                return False
        return True


def pop_count(x):
    x = x - ((x >> 1) & 0x5555555555555555)
    x = (x & 0x3333333333333333) + ((x >> 2) & 0x3333333333333333)
    x = (x + (x >> 4)) & 0x0f0f0f0f0f0f0f0f
    x = x + (x >> 8)
    x = x + (x >> 16)
    x = x + (x >> 32)
    return x & 0x0000007f


MOD = int(1e09) + 7
INF = int(1e15)


class City:
    def __init__(self, id, p, y):
        self._id = id
        self._p = p
        self._y = y
        self._x = 0


def main():
    # sys.stdin = open("sample.txt")
    N, M = Scanner.map_int()
    cities = []
    for i in range(M):
        p, x = Scanner.map_int()
        cities.append(City(i, p, x))
    cities.sort(key=lambda c: c._y)
    M = defaultdict(int)
    for c in cities:
        M[c._p] += 1
        c._x = M[c._p]
    cities.sort(key=lambda c: c._id)
    for c in cities:
        print('{:0>6}{:0>6}'.format(c._p, c._x))


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
n,m=map(int,input().split())
l=[[] for _ in range(n)]
for i in range(m):
    a,b=map(int,input().split())
    l[a-1].append([b,i])
ans=[0]*m
for idx,i in enumerate(l,1):
    i.sort(key=lambda x:x[0])
    pref=''
    if len(str(idx))<6:
        diff=6-len(str(idx))
        pref=('0'*diff)+str(idx)
    else:
        pref=str(idx)
    #print(i)
    for j,k in enumerate(i,1):
        suff=''
        if len(str(j))<6:
            diff=6-len(str(j))
            suff=('0'*diff)+str(j)
        else:
            suff=str(j)
#        print(k[1])
        ans[k[1]]=pref+suff
for i in ans:
    print(i)

Submission status: Accepted

Solution code:
n,m = map(int,input().split())
li = []
for i in range(m):
    p,y = map(int,input().split())
    li.append([p,y,i])
li.sort(key= lambda x:x[1])
li.sort(key= lambda x:x[0])
pre = li[0][0]
cnt = 1
ans = []
for p,y,i in li:
    if p==pre:
        ans.append(   (str(p).zfill(6) + str(cnt).zfill(6) ,i))
        cnt+=1
    else:
        pre = p
        ans.append((str(p).zfill(6) + str(1).zfill(6),i))
        cnt=2
ans.sort(key=lambda x:x[1])
for a,i in ans:
    print(a)

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([p,y,i])
ls.sort(key= lambda x:x[1])
ls.sort(key= lambda x:x[0])
pre = ls[0][0]
cnt = 1
ans = []
for p,y,i in ls:
    if p==pre:
        ans.append(   (str(p).zfill(6) + str(cnt).zfill(6) ,i))
        cnt+=1
    else:
        pre = p
        ans.append((str(p).zfill(6) + str(1).zfill(6),i))
        cnt=2
ans.sort(key=lambda x:x[1])
for a,i in ans:
    print(a)

Submission status: Accepted

Solution code:
from sys import stdin

N, M = map(int, stdin.readline().split())
py = [list(map(int, stdin.readline().split())) for _ in range(M)]

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

py.sort()

px = []

ptmp = 0
xtmp = 1

for p, y, i in py:
    if p == ptmp:
        xtmp += 1
    else:
        ptmp = p
        xtmp = 1
    px.append([str(p).zfill(6) + str(xtmp).zfill(6), i])


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

for out, i in px:
    print(out)

Submission status: Accepted

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

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

dic = {}
for p in range(N+1):
    P[p] = sorted(P[p])
    for i, y in enumerate(P[p]):
        i += 1
        dic[y] = '{}{}'.format(str(p).zfill(6), str(i).zfill(6))

for i in range(M):
    p, y = ite[i]
    print(dic[y])

Submission status: Accepted

Solution code:
N,M = map(int,input().split())
PY = {n: [] for n in range(N + 1)}
ans = [0]*M
for i in range(M):
  p,y = map(int,input().split())
  PY[p].append((y, i))
for p,y in PY.items():
  y.sort()
  for j, (z, i) in enumerate(y):
    top_number = '0'*(6-len(str(p)))+str(p)
    under_number = '0'*(6-len((str(j+1))))+str(j+1)
    ans[i] = top_number + under_number
for i in range(M):
  print(ans[i])

Submission status: Accepted

Solution code:
n,m = map(int,input().split())
py = sorted([list(map(int,input().split()))+[i] for i in range(m)])
cnt = 1
ans_list = [['0'*(6 - len(str(py[0][0])))+str(py[0][0])+'000001',py[0][2]]]
for i in range(1,m):
  ans = '0'*(6 - len(str(py[i][0])))
  ans += str(py[i][0])
  if py[i-1][0] == py[i][0]:
    cnt += 1
  else:
    cnt = 1
  ans += '0'*(6 - len(str(cnt)))
  ans += str(cnt)
  ans_list.append([ans,py[i][2]])
ans_list = sorted(ans_list,key=lambda x:x[1])
for i in ans_list:
  print(i[0])

Submission status: Accepted

Solution code:
n, m = map(int, input().split())
y_inputs = []
dct = dict()
for _ in range(m):
  p, y = map(int, input().split())
  y_inputs.append(y)
  if dct.get(p) == None:
    dct[p] = [y]
  else:
    dct[p].append(y)

citycodes = dict()
for pref in sorted(dct.items()):
  pid = int(pref[0])
  years = sorted(pref[1])
  for i, y in enumerate(years):
    code = format(pid, '06') + format(i+1, '06')
    citycodes[y] = code

for y in y_inputs:
  print(citycodes[y])

Submission status: Accepted

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

P = [[] for _ in range(N+1)]

class City():
    def __init__(self, i, p, y):
        self.i = i
        self.p = p
        self.y = y
        self.x = None
        self.id = None
        
for i, (p, y) in enumerate(A):
    city = City(i, p, y)
    P[p].append(city)
    
for p, cities in enumerate(P):
    cities.sort(key=lambda x: x.y)
    for x, city in enumerate(cities):
        city.id = ('000000'+str(p))[-6:] + ('000000'+str(x+1))[-6:]
        city.x = x+1

P = [city for cities in P for city in cities]
P.sort(key=lambda x: x.i)

for city in P:
    print(city.id)

Submission status: Accepted

Solution code:
import sys

# import bisect
# from collections import Counter, deque, defaultdict

# import copy
# from heapq import heappush, heappop, heapify
# from fractions import gcd
# import itertools
from operator import attrgetter, itemgetter

# import math

# import numpy as np

readline = sys.stdin.readline
MOD = 10 ** 9 + 7
INF = float('INF')
sys.setrecursionlimit(10 ** 5)


def main():
    n, m = list(map(int, readline().split()))
    pyir = [[0] * 4 for _ in range(m)]

    for i in range(m):
        p, y = list(map(int, readline().split()))
        pyir[i][0] = p
        pyir[i][1] = y
        pyir[i][2] = i

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

    x = 0
    pprev = pyir[0][0]

    for i in range(m):
        if pprev != pyir[i][0]:
            x = 0
        x += 1
        pyir[i][3] = str(pyir[i][0]).zfill(6) + str(x).zfill(6)
        pprev = pyir[i][0]

    pyir.sort(key=itemgetter(2))

    for i in range(m):
        print(pyir[i][3])

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
def main():
    from builtins import int, map, list, print
    from collections import defaultdict, deque
    from bisect import bisect_left
    import sys
    sys.setrecursionlimit(10 ** 6)

    input = sys.stdin.readline
    input_list = (lambda: input().rstrip().split())
    input_number_list = (lambda: list(map(int, input_list())))

    N, M = input_number_list()
    pref = [[0] for i in range(N + 1)]
    q = deque()
    for i in range(M):
        p, y = map(int, input_number_list())
        pref[p].append(y)
        q.append((p, y))
    for p in pref:
        p.sort()
    for p, y in q:
        print('{:06}{:06}'.format(p, bisect_left(pref[p], y)))


if __name__ == '__main__':
    main()

Submission status: Accepted

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

lists = [[] for _ in range(N)]
items = [list(map(int, input().split())) for _ in range(M)]
for p, y in items:
  lists[p-1].append(y)

dic = {}

for n in range(N):
  lists[n].sort()  

for n in range(N):
  l = lists[n]
  count = 1
  for i in l:
    dic[i] = count
    count+=1

for p, y in items:
  print("{:06g}{:06g}".format(p,dic[y]))

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([i + 1, p, y])
city = sorted(city, key=lambda x: [x[1], x[2]])

res = []
p, pp = 0, 0
cnt = 0
for i in range(m):
    idx, p, _ = city[i]
    if i == 0:
        cnt = 1
        pp = p
    elif pp == p:
        cnt += 1
    else:
        pp = p
        cnt = 1

    ID = str(p).rjust(6, '0') + str(cnt).rjust(6, '0')
    res.append([idx, ID])

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

Submission status: Accepted

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

lists = [[] for _ in range(N)]
items = [list(map(int, input().split())) for _ in range(M)]
for p, y in items:
  lists[p-1].append(y)

dic = {}

for n in range(N):
  lists[n].sort()  

for n in range(N):
  l = lists[n]
  count = 1
  for i in l:
    dic[i] = count
    count+=1

for p, y in items:
  print("{:06g}{:06g}".format(p,dic[y]))

Submission status: Accepted

Solution code:
N, M = map(int, input().split())
l = []
for i in range(M):
  p, y = list(map(int, input().split()))
  l.append([i+1, p, y, ""])
l = sorted(l, key=lambda x: x[2])

cnt = [1]*(N+1)
for i in range(M):
  l[i][3] = str(l[i][1]).zfill(6) + str(cnt[l[i][1]]).zfill(6)
  cnt[l[i][1]] += 1

l = sorted(l, key=lambda x: x[0])
for i in range(M):
  print(l[i][3])

Submission status: Accepted

Solution code:
def main():
    N, M = map(int, input().split())
    citys = []
    for _ in range(M):
        p, y = map(int, input().split())
        citys.append((p, y))
    
    ### citysdict作成
    temp= [[] for _ in range(N)]
    for city in citys:
        p, y = city
        temp[p-1].append((p, y))
    sortedcitys = []
    for pre in temp:
        sortedcitys.append(sorted(pre, key=lambda x:x[1]))
    citysdict = {}
    for pre in sortedcitys:
        ban = 1
        for city in pre:
            citysdict[city] = ban
            ban += 1
    
    ## 出力
    for city in citys:
        up = city[0]
        down = citysdict[city]
        print('{:0>6}'.format(up) + '{:0>6}'.format(down))

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
n,m = list(map(int,input().split()))
PY=[list(map(int,input().split()))for _ in range(m)]
id = [[]for _ in range(n)]
for a,b in PY:
    id[a-1].append(b)
for v in id:
    v.sort()
d = {}
for i in range(n):
    k=1
    for j in range(len(id[i])):
        d[id[i][j]] = k
        k+=1
for i,j in PY:
    print("{:06g}{:06g}".format(i,d[j]))

Submission status: Accepted

Solution code:
import sys
from bisect import *
from heapq import *
from collections import *
from itertools import *
from functools import *
from math import *
from fractions import *

sys.setrecursionlimit(100000000)
input = lambda: sys.stdin.readline().rstrip()


def main():
    N, M = map(int, input().split())
    cities = []
    for i in range(M):
        P, Y = map(int, input().split())
        cities.append((i, P, Y))
    cities.sort(key=lambda t: t[2])
    count = defaultdict(int)
    ans = {}
    for i, P, _ in cities:
        count[P] += 1
        ans[i] = str(P).zfill(6) + str(count[P]).zfill(6)
    for i in range(M):
        print(ans[i])


main()

Submission status: Accepted

Solution code:
from collections import defaultdict
def main():
    N,M = map(int,input().split())
    P = defaultdict(list)
    for i in range(M):
        p,y = map(int,input().split())
        P[p].append([y,i])
    for t in P.keys():
        P[t].sort()
    ans = ['' for _ in range(M)]
    for v in P.items():
        pre = str(v[0])
        l = len(pre)
        while l < 6:
            pre = '0'+pre
            l += 1
        lis = v[1]
        for i,u in enumerate(lis):
            num = str(i+1)
            q = len(num)
            while q < 6:
                num = '0'+num
                q += 1
            ans[u[1]] = pre+num
    for a in ans:
        print(a)


if __name__ == "__main__":
    main()

Submission status: Accepted

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

ID.sort()
town = 0

for i in range(M):
    if ID[i][0] != town:
        town = ID[i][0]
        count = 1
        ID[i].append("0"*(6-len(str(town)))+str(town)+"0"*(6-len(str(count)))+str(count))
    else:
        count += 1
        ID[i].append("0"*(6-len(str(town)))+str(town)+"0"*(6-len(str(count)))+str(count))
        
ID.sort(key=lambda x:x[2])

for i in range(M):
    print(ID[i][3])

Submission status: Accepted

Solution code:
from operator import itemgetter
N, M = map(int, input().split())
P = [[0, 0, 0] for _ in range(M)]
for i in range(M):
    P[i][0], P[i][1] = map(int, input().split())
    P[i][0] = (6-len(str(P[i][0])))*"0"+str(P[i][0])
    
P_s = sorted(P, key=itemgetter(0, 1))

for i in range(1, M):
    if(P_s[i][0] == P_s[i-1][0]):
        P_s[i][2] = P_s[i-1][2]+1
    
for i in range(M):
    print(P[i][0]+(6-len(str(P[i][2]+1)))*"0"+str(P[i][2]+1))