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 numpy as np
import bisect
n, m = map(int, input().split())

#data = [[0] * 4] * m
data = [0] * m
for i in range(m):
    #data[i][2] = i
    p, y = map(int, input().split())
    temp = [p, y, i, 0]
    data[i] = temp

# 県でSort（普通にソート
# setから、Prefの数をカウント
# prefごとに範囲を絞って、４データ目に書き込み
# ３データでソートして、入力データ並びに戻す
# print(data)
data1 = sorted(data)
dArray = np.array(data1)
pref = dArray[:, 0]

setPref = set(pref)
numPref = len(setPref)
#lis = list(setPref)

for i in setPref:
    left = bisect.bisect_left(pref, i)
    right = bisect.bisect_right(pref, i) - 1
    tar = left - right + 1
    id = 1
    for j in range(left, right + 1):
        #t = '%06d' % (i)
        pre = '%06d' % (i)
        post = '%06d' % (id)
        dArray[j, 3] = pre + post
        id += 1

ansList = dArray[dArray[:, 2, ].argsort(), :]
for i in range(m):
    ans = ansList[i, 3]
    ansS = '{:0>12}'.format(ans)
    print(ansS)

Submission status: Accepted

Solution code:
import itertools
import math
import fractions
import functools
import copy
n, m = map(int, input().split())
pyi = []
for i in range(m):
    p,y= map(int, input().split())
    pyi.append([p,y,i])

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

ken = 0
for i in range(m):
    if pyi[i][0] != ken:
        ken = pyi[i][0]
        x = 1
    else:
        x += 1
    pyi[i].append(x)


pyi.sort(key=lambda x: x[2])
for i in range(m):
    print(str(pyi[i][0]).zfill(6)+str(pyi[i][3]).zfill(6))

Submission status: Accepted

Solution code:
import sys
import heapq
import re
from itertools import permutations
from bisect import bisect_left, bisect_right
from collections import Counter, deque
from fractions import gcd
from math import factorial, sqrt, ceil
from functools import lru_cache, reduce
INF = 1 << 60
MOD = 1000000007
sys.setrecursionlimit(10 ** 7)

# UnionFind
class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.find(x)]

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        return len(self.roots())

    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}

    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())

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


# ワーシャルフロイド (任意の2頂点の対に対して最短経路を求める)
# 計算量n^3 (nは頂点の数)
def warshall_floyd(d, n):
    #d[i][j]: iからjへの最短距離
    for k in range(n):
        for i in range(n):
            for j in range(n):
                d[i][j] = min(d[i][j],d[i][k] + d[k][j])
    return d


# ダイクストラ
def dijkstra_heap(s, edge, n):
    #始点sから各頂点への最短距離
    d = [10**20] * n
    used = [True] * n #True:未確定
    d[s] = 0
    used[s] = False
    edgelist = []
    for a,b in edge[s]:
        heapq.heappush(edgelist,a*(10**6)+b)
    while len(edgelist):
        minedge = heapq.heappop(edgelist)
        #まだ使われてない頂点の中から最小の距離のものを探す
        if not used[minedge%(10**6)]:
            continue
        v = minedge%(10**6)
        d[v] = minedge//(10**6)
        used[v] = False
        for e in edge[v]:
            if used[e[1]]:
                heapq.heappush(edgelist,(e[0]+d[v])*(10**6)+e[1])
    return d

# 素因数分解
def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append([i, cnt])

    if temp!=1:
        arr.append([temp, 1])

    if arr==[]:
        arr.append([n, 1])

    return arr

# 2数の最小公倍数
def lcm(x, y):
    return (x * y) // gcd(x, y)

# リストの要素の最小公倍数
def lcm_list(numbers):
    return reduce(lcm, numbers, 1)

# リストの要素の最大公約数
def gcd_list(numbers):
    return reduce(gcd, numbers)

# 素数判定



# limit以下の素数を列挙
def eratosthenes(limit):
    A = [i for i in range(2, limit+1)]
    P = []

    while True:
        prime = min(A)
        
        if prime > sqrt(limit):
            break
            
        P.append(prime)
            
        i = 0
        while i < len(A):
            if A[i] % prime == 0:
                A.pop(i)
                continue
            i += 1
            
    for a in A:
        P.append(a)
            
    return P

# 同じものを含む順列
def permutation_with_duplicates(L):

    if L == []:
        return [[]]

    else:
        ret = []

        # set（集合）型で重複を削除、ソート
        S = sorted(set(L))

        for i in S:

            data = L[:]
            data.remove(i)

            for j in permutation_with_duplicates(data):
                ret.append([i] + j)

        return ret


# ここから書き始める
n, m = map(int, input().split())
p = [0 for i in range(m)]
y = [0 for i in range(m)]
for i in range(m):
    p[i], y[i] = map(int, input().split())
x = [[] for i in range(n)]
for i in range(m):
    x[p[i] - 1].append(y[i])
for i in range(n):
    x[i].sort()
# print("x =", x)
for i in range(m):
    index = bisect_left(x[p[i] - 1], y[i])
    ans = str(p[i]).zfill(6) + str(index + 1).zfill(6)
    print(ans)

Submission status: Accepted

Solution code:
N, M = map(int, input().split())
ss = [[] for _ in range(N)]
for i in range(M):
    p, y = map(int, input().split())
    ss[p-1].append((i, y))
ls = [''] * M
for p in range(N):
    s = ss[p]
    s.sort(key=lambda g: g[1])
    for d, (i, y) in enumerate(s):
        ps = str(p+1).zfill(6)
        ds = str(d+1).zfill(6)
        ls[i] = ps+ds
for l in ls:
    print(l)

Submission status: Accepted

Solution code:
def getN():
    return int(input())
def getNM():
    return map(int, input().split())
def getList():
    return list(map(int, input().split()))
def getArray(intn):
    return [int(input()) for i in range(intn)]
def input():
    return sys.stdin.readline().rstrip()

from collections import defaultdict, deque, Counter
from sys import exit
import heapq
import math
import copy
from operator import mul
from functools import reduce
from bisect import bisect_left, bisect_right

import sys
sys.setrecursionlimit(1000000000)
mod = 10 ** 9 + 7

# N個の県、M個の市
N, M = getNM()
city = []
# i県の中でn番目に→誕生が早い順に全ての都市を並べる
# →i県の市が来た時だけpref[i] += 1する　
# i県の中での順位が効率よく求められる
pref = [1] * (N + 1)
for i in range(M):
    # 市iについて
    # p県に属し、y年生まれ
    p, y = getNM()
    # 入力した順番についてのインデックス(i)を通っておく
    city.append([i + 1, p, y])
# 誕生が早い順に全ての都市を並べる
city = sorted(city, key=lambda i: i[2])

ans = []
for i, p, y in city:
    np = len(str(p))
    uppercode = '0' * (6 - np) + str(p)

    # p県のうちで何番目か
    order = pref[p]
    yp = len(str(order))
    undercode = '0' * (6 - yp) + str(order)
    # 次に来るp県の都市はpref[i] + 1番目に早く生まれた
    pref[p] += 1
    ans.append([i, uppercode + undercode])

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

Submission status: Accepted

Solution code:
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
from itertools import permutations, accumulate, combinations, combinations_with_replacement
from math import sqrt, ceil, floor, factorial
from bisect import bisect_left, bisect_right, insort_left, insort_right
from copy import deepcopy
from operator import itemgetter
from functools import reduce
from fractions import gcd
import sys
def input(): return sys.stdin.readline().rstrip()
def I(): return int(input())
def Is(): return map(int, input().split())
def LI(): return list(map(int, input().split()))
def TI(): return tuple(map(int, input().split()))
def IR(n): return [I() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def TIR(n): return [TI() for _ in range(n)]
def S(): return input()
def Ss(): return input().split()
def LS(): return list(input())
def SR(n): return [S() for _ in range(n)]
def SsR(n): return [Ss() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
sys.setrecursionlimit(10**6)
MOD = 10**9+7
INF = 10**18
# ----------------------------------------------------------- #

n, m = Is()
PY = []
for i in range(m):
    p, y = Is()
    PY.append((i, p, y))
PY.sort(key=itemgetter(1, 2))
ANS = [[0]*2 for _ in range(m)]
tmp = -1
count = -1
for i, p, y in PY:
    if tmp != p:
        count = 1
        tmp = p
    else:
        count += 1
    ANS[i][0] = p
    ANS[i][1] = count
for a, b, in ANS:
    print("{}{}".format(str(a).zfill(6), str(b).zfill(6)))

Submission status: Accepted

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

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

result = [1] * M
citys = [[] for _ in range(N)]

for i, n in enumerate(P):
    citys[n-1].append([Y[i], i])

for c in citys:
    
    c.sort()
    for i, k in enumerate(c):
        result[k[1]] += i



for x, y in zip(P, result):
    x, y = str(x), str(y)
    print('0'*(6-len(x))+x+'0'*(6-len(y))+y)

Submission status: Accepted

Solution code:
n, m = map(int, input().split())
py = []
for _ in range(m):
    p, y = map(int, input().split())
    py.append((p, y))
prefs = [[] for _ in range(n)]
for ind, (p, y) in enumerate(py):
    prefs[p-1].append((y, ind))
ans = [None]*m
for p, i in enumerate(prefs):
    i.sort()
    for j, (_, ind) in enumerate(i):
        ans[ind] = str(p+1).zfill(6)+str(j+1).zfill(6)
for i in ans:
    print(i)

Submission status: Accepted

Solution code:
import copy
n, m = map(int, input().split())
p = [list(map(int, input().split())) for i in range(m)]
dic = {}
q = copy.copy(p)
q.sort(key=lambda x: x[1])
cnt = [0 for i in range(n+1)]
for i in range(m):
    cnt[q[i][0]] += 1
    dic[q[i][1]] = cnt[q[i][0]]
for i in range(m):
    print(str(p[i][0]).zfill(6)+str(dic[p[i][1]]).zfill(6))

Submission status: Accepted

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

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

ls = [''] * M
for p in range(N):
    s = ss[p]
    s.sort(key=lambda g: g[1])
    for d, (i, y) in enumerate(s):
        ps = str(p+1).zfill(6)
        ds = str(d+1).zfill(6)
        ls[i] = ps+ds

for l in ls:
    print(l)

Submission status: Accepted

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

spy = sorted(py, key=lambda x: x[1])
ids = {}
maxy = [1] * (n + 1)
for p, y in spy:
    ids[(p, y)] = maxy[p]
    maxy[p] += 1
for p, y in py:
    print('{:0=6}{:0=6}'.format(p, ids[p,y]))

Submission status: Accepted

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

spy = sorted(py, key=lambda x: x[1])
ids = {}
maxy = [1] * (n + 1)
for p, y in spy:
    ids[(p, y)] = maxy[p]
    maxy[p] += 1
for p, y in py:
    print('{:0=6}'.format(p) + '{:0=6}'.format(ids[p,y]))

Submission status: Accepted

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

ol = []


def zeros(x):
    xt = str(x)
    k = 6 - len(xt)
    return "0" * k + xt

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

l = sorted(ol)


res = {}

t=0
for i in range(M):
    if l[i][0] == l[i-1][0]:
        t+=1
    else:
        t=1
    res[l[i]] = zeros(l[i][0])+ zeros(t)

for i in ol:
    print(res[i])

Submission status: Accepted

Solution code:
from bisect import bisect_left
from collections import defaultdict
n, m = map(int, input().split())
py = []
dict_p = defaultdict(list)
for i in range(m):
    p, y = map(int, input().split())
    py.append((p, y))
    dict_p[p].append(y)
#print(dict_p)
for values in dict_p.values():
    values.sort()

for p, y in py:
    x = bisect_left(dict_p[p], y)
    ans = "{:006}".format(p) + "{:006}".format(x+1)
    print(ans)

Submission status: Accepted

Solution code:
n,m = map(int,input().split())
p = {str(i):[] for i in range(1,n+1)}
l = []
for i in range(m):
    t = input().split()
    l.append((t[0],int(t[1])))
    p[t[0]].append(int(t[1]))
for i in range(1,n+1):
    i = str(i)
    p[i].sort()
    d = {}
    for j in range(len(p[i])):
        d[p[i][j]] = str(i).zfill(6)+str(j+1).zfill(6)
    p[i]=d
for t in l:
    print(p[t[0]][t[1]])

Submission status: Accepted

Solution code:
from collections import defaultdict
from bisect import bisect_left

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

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

for v in city_list_by_pref.values():
    v.sort()

for p, y in city_list:
    x = bisect_left(city_list_by_pref[p], y)
    print('{:06}{:06}'.format(p, x+1))

Submission status: Accepted

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

Pref = [[]for _ in range(N)]

City = []

for _ in range(M):
    prefecture, year = map(int, input().split())
    prefecture -= 1
    Pref[prefecture].append([_, year])

for i in range(N):
    Pref[i].sort(key=lambda x: x[1])
    for j in range(len(Pref[i])):
        s1 = str(i+1).zfill(6)
        s2 = str(j+1).zfill(6)
        Pref[i][j].append(s1+s2)
        City.append(Pref[i][j])
City.sort()
for a, b, c in City:
    print(c)

Submission status: Accepted

Solution code:
from collections import defaultdict


def main():
    N, M = list(map(int, input().split(' ')))
    pref = defaultdict(list)
    for c in range(M):
        p, y = list(map(int, input().split(' ')))
        p -= 1
        pref[p].append((c, y))
    nums = ['' for _ in range(M)]
    for p in range(N):
        pref[p].sort(key=lambda a: a[1])
        for x, city in enumerate(pref[p]):
            nums[city[0]] = '{:06}{:06}'.format(p + 1, x + 1)
    for n in nums:
        print(n)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
n,m = map(int,input().split())
py = [list(map(int,input().split()))for i in range(m)]
pypy = py[::]
from operator import itemgetter
import bisect
py.sort(key = itemgetter(1))
dic = {}
for i in range(m):
    if py[i][0] not in dic:
        dic[py[i][0]] = []
    dic[py[i][0]].append(py[i][1])


anslist = [0]*m

for i in range(m):
    anslist[i] = str(pypy[i][0]).zfill(6) + str(bisect.bisect_left(dic[pypy[i][0]],pypy[i][1]) + 1).zfill(6)

for ans in anslist:
    print(ans)

Submission status: Accepted

Solution code:
from collections import Counter
n, m = map(int, input().split())
py = []
for i in range(m):
    t = list(map(int, input().split()))
    py.append(t+[i])

c = Counter([])
py.sort(key=lambda x: x[1])

ans = []
for p, y, i in py:
    c[p]+=1
    ans.append((i, str(p).zfill(6)+str(c[p]).zfill(6)))
ans.sort()
for i, a in ans:
    print(a)

Submission status: Accepted

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


def solve(n, m, p, y):
    kens = [[] for i in range(n + 1)]
    for i in range(m):
        kens[p[i]].append(y[i])
    for ken in kens:
        ken.sort()
    
    #id 生成
    ids = [{} for i in range(n + 1)]
    for indken, ken in enumerate(kens):
        for indsi, yi in enumerate(ken, 1):
            ids[indken][yi] = str(indken).zfill(6) + str(indsi).zfill(6)
    
    #出力
    for i in range(m):
        print(ids[p[i]][y[i]])

    return

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
from __future__ import print_function

from functools import reduce
from operator import mul
from collections import Counter
from collections import deque
from itertools import accumulate
from queue import Queue
from queue import PriorityQueue as pq
from heapq import heapreplace
from heapq import heapify
from heapq import heappushpop
from heapq import heappop
from heapq import heappush
import heapq
import time
import random
import bisect
import itertools
import collections
from fractions import Fraction
import fractions
import string
import math
import operator
import functools
import copy
import array
import re
import sys
sys.setrecursionlimit(500000)


input = sys.stdin.readline


def eprint(*args, **kwargs):
    print(*args, file=sys.stderr, **kwargs)
    return


def combinations_count(n, r):
    r = min(r, n - r)
    numer = reduce(mul, range(n, n - r, -1), 1)
    denom = reduce(mul, range(1, r + 1), 1)
    return numer // denom


def cmp_vec(u, v):
    if u[1] < v[1]:
        return -1
    elif u[1] == v[1]:
        if u[2] < v[2]:
            return -1
        elif u[2] == v[2]:
            return 0
        else:
            return 1
    else:
        return 1


def main():
    #
    n, m = map(int, input().strip().split())
    l = []
    for i in range(m):
        p, y = map(int, input().strip().split())
        p = str(p).zfill(6)
        l.append(list((i, p, y)))
    l.sort(key=functools.cmp_to_key(cmp_vec))

    #
    cntr = 1
    for i in range(m):
        if i > 0 and l[i][1] != l[i-1][1]:
            cntr = 1
        l[i][2] = str(cntr).zfill(6)
        cntr += 1

    #
    l.sort(key=lambda x: x[0])
    for xx in l:
        print(xx[1],end="")
        print(xx[2])


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
from __future__ import print_function

import sys
sys.setrecursionlimit(500000)

import re
import array
import copy
import functools
import operator

import math
import string
import fractions
from fractions import Fraction

import collections
import itertools
import bisect

import random
import time

import heapq
from heapq import heappush
from heapq import heappop
from heapq import heappushpop
from heapq import heapify
from heapq import heapreplace
from queue import PriorityQueue as pq
from queue import Queue

from itertools import accumulate

from collections import deque
from collections import Counter

from operator import mul
from functools import reduce

input = sys.stdin.readline


def eprint(*args, **kwargs):
    print(*args, file=sys.stderr, **kwargs)
    return

# from fractions import gcd
# from math import gcd

# def lcm(n, m):
#     return int(n * m / gcd(n, m))


# def coprimize(p, q):
#     common = gcd(p, q)
#     return (p // common, q // common)


# def find_gcd(list_l):
#     x = reduce(gcd, list_l)
#     return x


def combinations_count(n, r):
    r = min(r, n - r)
    numer = reduce(mul, range(n, n - r, -1), 1)
    denom = reduce(mul, range(1, r + 1), 1)
    return numer // denom

def cmp_vec(u,v):   # u < v なる必要条件を記す
    if u[1] < v[1]:
        return  1
    elif u[1] == v[1]:
        if u[2] < v[2]:
            return 1
        elif u[2]==v[2]:
            return 0
        else:
            return -1
    else:
        return -1

def main():
    #
    n,m = map(int,input().strip().split())  # 市 in 県  # n個の県，m個の市
    l=[]
    for i in range(m):
        p,y = map(int,input().strip().split()) # 市iは県piに属しyi年に誕生した
        p = str(p).zfill(6) # p-=1 # i (y,p) 
        l.append(list((i,p,y)))
    l.sort(key=functools.cmp_to_key(cmp_vec),reverse = True)

    #
    eprint('l (i,p,y)',end=':\n')
    eprint(l)

    #
    cntr=1
    for i in range(m):
        if i>0 and l[i][1] != l[i-1][1]:
            cntr=1
        l[i][2] = str(cntr).zfill(6)
        cntr+=1

    #
    l.sort(key=lambda x:x[0])
    for xx in l:
        print(xx[1]+xx[2])
    #
    # eprint('l (i,p,y)',end=':\n')
    # eprint(l)
    # aaa=["asdfa",32, 15.3, True]
    # eprint('aaa ',end=':\n')
    # eprint(aaa)

if __name__ == '__main__':
    main()

Submission status: Accepted

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

Ps = [[] for i in range(N)]
Cs = []
for i in range(M):
    p, y = map(int, input().split())
    p -= 1
    Cs.append([p, 0])
    Ps[p].append([i, y])

for p in Ps:
    p = sorted(p, key=lambda city: city[1])
    for i in range(len(p)):
        Cs[p[i][0]][1] = i+1

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

Submission status: Accepted

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

pref = {}
for p,y in info:
    if not p in pref: pref[p] = [y]
    else: pref[p].append(y)

id = {}
for p,years in pref.items():
    years.sort()
    id[p] = {}
    for i,y in enumerate(years):
        id[p][y] = str(p).zfill(6) + str(i+1).zfill(6)

for p,y in info:
    print(id[p][y])

Submission status: Accepted

Solution code:
import numpy as np
N, M = map(int, input().split())
cities = np.array(tuple(tuple(map(int, input().split())) for _ in range(M)), dtype=np.int64)
arg = np.argsort(cities[:, 0] * 10 ** 10 + cities[:, 1])
pref = 0
ans = []
for p, y in cities[arg]:
    if p != pref:
        pref = p
        count = 1
    ans.append("{:06d}{:06d}".format(p, count))
    count += 1
for i in np.argsort(arg):
    print(ans[i])

Submission status: Accepted

Solution code:
def bisect(seq, target):
  left = -1    # ind. always lt target
  right = len(seq)    # ind. always gt or eq to target
  while right - left > 1:
    mid = (left + right) // 2
    if seq[mid] < target:
      left = mid
    else:
      right = mid
  return right



n, m = map(int, input().split())
L = [[] for _ in range(n + 1)]
pairs = [list(map(int, input().split())) for _ in range(m)]
for p, y in pairs:
  L[p].append(y)

for i in range(1, n + 1):
  L[i].sort()


for p, y in pairs:
  left_id = "{:0>6}".format(p)
  right_id = "{:0>6}".format(bisect(L[p], y) + 1)
  print(left_id + right_id)

Submission status: Accepted

Solution code:
import sys
readline = sys.stdin.readline
from heapq import heapify, heappush, heappop

def main():
    N, M = map(int, readline().rstrip().split())
    inp = [list(map(int, readline().rstrip().split())) for _ in range(M)]
    pref = {}
    for p, y in inp:
        pref.setdefault(p, [])
        pref[p].append(y)

    pref_year_id = {}
    for p, years in pref.items():
        heapify(years)
        p_id = str(p).zfill(6)
        pref_year_id[p] = {}
        for i in range(1, len(years)+1):
            year = heappop((years))
            pref_year_id[p][year] = p_id + str(i).zfill(6)
    
    for p, y in inp:
        print(pref_year_id[p][y])

if __name__ == '__main__':
    main()

Submission status: Accepted

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

dic = {}
PY.sort(key = lambda x:x[1])
ken = [0 for i in range(N)]
for k,value,s in PY:
    ken[k-1] += 1
    s1 = str(k).zfill(6)
    s2 = str(ken[k-1])
    s2 = s2.zfill(6)
    dic[s] = s1+s2

ans = sorted(dic.items(),key=lambda x:x[0])

for i,j in ans:
    print(j)

Submission status: Accepted

Solution code:
import itertools
import math
import fractions
import functools
n, m = map(int, input().split())
py = []
for i in range(m):
    l = list(map(int, input().split()))
    l.append(i)
    py.append(l)
 
# py = [p,y,index]
 
# yでsort
py.sort(key=lambda x: x[1])

ans = [0] * (m)
ans1 = [0] * (m)
memo = {}
for item in py:
    ken = item[0]
    year = item[1]
    idx = item[2]
    ith = memo.get(ken, 1)
    ans[idx] = ith
    ans1[idx] = ken
    memo[ken] = ith + 1

for i in range(m):
    print(str(ans1[i]).zfill(6) + str(ans[i]).zfill(6))

Submission status: Accepted

Solution code:
import itertools
import math
import fractions
import functools
n, m = map(int, input().split())
py = []
for i in range(m):
    l = list(map(int, input().split()))
    l.append(i)
    py.append(l)

# py = [p,y,index]

# yでsort
py.sort(key=lambda x: x[1])

prev = 0
py.sort(key=lambda x: x[0])
# py = [p, y, index, pの中でのindex]
for i in range(m):
    if prev != py[i][0]:
        prev = py[i][0]
        x = 1

    py[i].append(x)
    x += 1
py.sort(key=lambda x: x[2])

p_i = ""
x_i = ""
for i in range(m):
    if(len(str(py[i][0])) == 6):
        p_i = str(py[i][0])
    if(len(str(py[i][0])) == 5):
        p_i = '0' + str(py[i][0])
    if(len(str(py[i][0])) == 4):
        p_i = '00'+str(py[i][0])
    if(len(str(py[i][0])) == 3):
        p_i = '000' + str(py[i][0])
    if(len(str(py[i][0])) == 2):
        p_i = '0000'+str(py[i][0])
    if(len(str(py[i][0])) == 1):
        p_i = '00000' + str(py[i][0])
    if(len(str(py[i][3])) == 6):
        x_i = str(py[i][3])
    if(len(str(py[i][3])) == 5):
        x_i = '0' + str(py[i][3])
    if(len(str(py[i][3])) == 4):
        x_i = '00'+str(py[i][3])
    if(len(str(py[i][3])) == 3):
        x_i = '000' + str(py[i][3])
    if(len(str(py[i][3])) == 2):
        x_i = '0000'+str(py[i][3])
    if(len(str(py[i][3])) == 1):
        x_i = '00000' + str(py[i][3])

    print(p_i + x_i)

Submission status: Accepted

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

cities = {}
output = []
for i in range(M):
    x, y = map(int, input().split())
    cities[i+1] = [x,y]
    output.append(y)

ID = {}
county_old = 0
sorted_counties_years = sorted(cities.values())
for county,year in sorted_counties_years:
    if county_old == 0:
        county_old = county
        count = 1
        ID[year] = '{:06}{:06}'.format(county, count)
        count += 1
        continue
    elif county_old == county:
        ID[year] = '{:06}{:06}'.format(county, count)
        count += 1
    else:
        county_old = county
        count = 1
        ID[year] = '{:06}{:06}'.format(county, count)
        count += 1
for i in output:
    print(ID[i])

Submission status: Accepted

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

ypi=[[y,p,i] for i,(p,y) in enumerate(PY)]			#順番iはp,yより前に来る
ypi.sort()

from collections import defaultdict

d=defaultdict(int)
ans=[0]*m

for y,p,i in ypi:
	d[p]+=1
	ans[i]=str(p).zfill(6)+str(d[p]).zfill(6)
	
print(*ans,sep="\n")

Submission status: Accepted

Solution code:
from bisect import bisect_right

n,m=map(int,input().split())
P=[]
Y=[]
A=[list() for _ in range(n)]										#二次元配列作る

for _ in range(m):
	p,y=map(int,input().split())
	P.append(p)
	Y.append(y)
	A[p-1].append(y)

A=[sorted(a) for a in A]												#二次元配列同一配列内でのソート

for i in range(m):
	j=bisect_right(A[P[i]-1],Y[i])
	print(str(P[i]).zfill(6)+str(j).zfill(6))

Submission status: Accepted

Solution code:
def main():
    n, m = map(int, input().split(" "))
    p = []
    ids = [0 for _ in range(m)]
    y = []
    rev_y = dict()
    p_order = [1 for _ in range(n + 1)]
    for i in range(m):
        pi, yi = map(int, input().split(" "))
        p.append(pi)
        y.append(yi)
        rev_y[yi] = i
    y.sort()
    for year in y:
        city_index = rev_y[year]
        prefecture_id = p[city_index]
        born_time = p_order[prefecture_id]
        ids[city_index] = born_time
        p_order[prefecture_id] += 1
    for i in range(m):
        print("%s%s" % (padding_str(p[i]), padding_str(ids[i])))


def padding_str(n):
    return str(n).zfill(6)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
n,m=map(int,input().split())
from collections import defaultdict
d=defaultdict(list)
py=[]
for i in range(m):
    p,y=map(int,input().split())
    d[p].append(y)
    py.append((p,y))

for k in d.keys():
    d[k]=sorted(d[k])

from bisect import bisect_right
for i in range(m):
    p=py[i][0]
    y=py[i][1]
    x=bisect_right(d[p], y)
    print('0'*(6-len(str(p)))+str(p)+'0'*(6-len(str(x)))+str(x))

Submission status: Accepted

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

d = [[] for _ in range(n)]
P = [0] * m
Y = [0] * m

for i in range(m):
    p,y = map(int,input().split())
    P[i] = p
    Y[i] = y
    d[p-1].append(y)
for i in range(n):
    d[i].sort()

for i in range(m):
    p,y = P[i],Y[i]
    D = d[p - 1]
    idx = bisect.bisect_left(D, y) + 1
    print(str(p).zfill(6) + str(idx).zfill(6))

Submission status: Accepted

Solution code:
n,m=map(int,input().split())
lis=[]
for i in range(0,m):
  p,q=map(int,input().split())
  lis.append([q,p,i])#iで出力の順番を管理
lis.sort()
ken=[1]*n
res=[]
for i in range(0,m):
  attack=lis[i]
  kenken=attack[1]
  ken_count=ken[kenken-1]
  moji=""
  moji+="0"*(6-len(str(kenken)))+str(kenken)+"0"*(6-len(str(ken_count)))+str(ken_count)
  ken[kenken-1]+=1
  res.append([attack[2],moji])
  
res.sort()
for i in range(0,m):
  print(res[i][1])

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
import sys
from itertools import *
from operator import itemgetter


def solve(N: int, M: int, P: "List[int]", Y: "List[int]"):
    items = [(P[i], Y[i]) for i in range(M)]

    key_to_value_to_rank = {}
    for key, sorted_items in groupby(sorted(items), key = itemgetter(0)):
        value_to_rank = dict((item, index + 1) for index, item in enumerate(map(lambda x: x[1], sorted_items)))
        key_to_value_to_rank[key] = value_to_rank

    for key, value in items:
        rank = key_to_value_to_rank[key][value]
        print('{0:06d}'.format(key, rank) + '{0:06d}'.format(rank))

    return


# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    M = int(next(tokens))  # type: int
    P = [int()] * (M)  # type: "List[int]"
    Y = [int()] * (M)  # type: "List[int]"
    for i in range(M):
        P[i] = int(next(tokens))
        Y[i] = int(next(tokens))
    solve(N, M, P, Y)

if __name__ == '__main__':
    main()