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())
py = []
for i in range(m):
  py.append(list(map(int, input().split())) + [i])
  
py.sort(key=lambda x: x[1])
py.sort(key=lambda x: x[0])

bef = 0
state = 0

triple = [ ]
for i in py:
    if (i[0] != bef):
        bef = i[0]
        state = 1
        triple.append ( [ i[ 0 ], i[ 1 ], i[ 2 ], str ( i[ 0 ] ).rjust ( 6, '0' ) + str ( state ).rjust ( 6, '0' ) ] )
    else:
        state += 1
        triple.append ( [ i[ 0 ], i[ 1 ], i[ 2 ], str ( i[ 0 ] ).rjust ( 6, '0' ) + str ( state ).rjust ( 6, '0' ) ] )

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

Submission status: Accepted

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

for i in range(m):
    l = list_PY[i]
    l.append(i)
list_PY.sort(key=lambda x:(x[0], x[1]))

cnt = 0
k = 0
for i in range(m):
    l = list_PY[i]
    if l[0] == k:
        cnt += 1
        a = len(list(str(l[0])))
        b = "0"*(6 - a) + str(l[0])
        c = len(list(str(cnt)))
        d = "0"*(6 - c) + str(cnt)
    else:
        k = l[0]
        cnt = 1
        a = len(list(str(l[0])))
        b = "0" * (6 - a) + str(l[0])
        c = len(list(str(cnt)))
        d = "0" * (6 - c) + str(cnt)
    l.append(b+d)


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

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

Submission status: Accepted

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

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

result = {}
for i in range(N):
    tmp = 1
    for j in d[i]:
        result[j] = tmp
        tmp += 1

def sixlize(n):
    k = len(str(n))
    return "0"*(6-k) + str(n)

for i in range(M):
    print( sixlize(P[i]) + sixlize(result[Y[i]]) )

Submission status: Accepted

Solution code:
N,M = map(int, input().split())
P = [list(map(int, input().split())) for _ in range(M)]
cnt = (N+1)*[0]
ids = {}

for p,y in sorted(P,key=lambda x: x[1]):
	cnt[p] += 1
	ids[y] = "%06d%06d" % (p,cnt[p])

for _,y in P:
	print(ids[y])

Submission status: Accepted

Solution code:
N, M = map(int,input().split())
p = []
pad = p.append
for i in range(M):
    s = list(map(int,input().split()))
    pad(s + [i])
p.sort()
cur = p[0][0]
cnt = 1
for i in range(M):
    if p[i][0] > cur:
        cur = p[i][0]
        cnt = 1
    p[i][1] = cnt
    cnt += 1
p.sort(key=lambda x: x[2])
for i in range(M):
    print("0" * (6 - len(str(p[i][0]))) + str(p[i][0]) + "0" * (6 - len(str(p[i][1]))) + str(p[i][1]))

Submission status: Accepted

Solution code:
N, M = map(int,input().split())
p = []
for i in range(M):
    s = list(map(int,input().split()))
    p.append(s + [i])
p.sort()
cur = p[0][0]
cnt = 1
for i in range(M):
    if p[i][0] > cur:
        cur = p[i][0]
        cnt = 1
    p[i][1] = cnt
    cnt += 1
p.sort(key=lambda x: x[2])
for i in range(M):
    print("0" * (6 - len(str(p[i][0]))) + str(p[i][0]) + "0" * (6 - len(str(p[i][1]))) + str(p[i][1]))

Submission status: Accepted

Solution code:
# Author: cr4zjh0bp
# Created: Sun Mar 22 17:06:57 UTC 2020
import sys
 
stdin = sys.stdin
inf = 1 << 60
mod = 1000000007
 
ni      = lambda: int(ns())
nin     = lambda y: [ni() for _ in range(y)]
na      = lambda: list(map(int, stdin.readline().split()))
nan     = lambda y: [na() for _ in range(y)]
nf      = lambda: float(ns())
nfn     = lambda y: [nf() for _ in range(y)]
nfa     = lambda: list(map(float, stdin.readline().split()))
nfan    = lambda y: [nfa() for _ in range(y)]
ns      = lambda: stdin.readline().rstrip()
nsn     = lambda y: [ns() for _ in range(y)]
ncl     = lambda y: [list(ns()) for _ in range(y)]
nas     = lambda: stdin.readline().split()

from collections import defaultdict

n, m = na()
py = nan(m)
d = defaultdict(list)

for i in range(m):
    p, y = py[i]
    d[p].append((y, i))

q = defaultdict(lambda: 1)
ans = []
for k, v in d.items():
    v.sort()
    for i in range(len(v)):
        y, j = v[i]
        ans.append((j, q[k], k))
        q[k] += 1

ans.sort()
for i in range(m):
    print("{:0>6}{:0>6}".format(ans[i][2], ans[i][1]))

Submission status: Accepted

Solution code:
n, m = map(int, input().split())
py_dict = dict()
ip_dict = dict()
io_dict = dict()

for i in range(m):
    py_list = list(map(int, input().split()))
    py_list.append(i)
    if py_list[0] in py_dict:
        py_dict[py_list[0]].append(py_list)
    else:
        py_dict[py_list[0]] = [py_list]
    ip_dict[i] = py_list[0]

for item in py_dict:
    tmp_list = py_dict[item]
    tmp_list.sort(key=lambda x: x[1])
    for i in range(len(tmp_list)):
        io_dict[tmp_list[i][2]] = str(
            ip_dict[tmp_list[i][2]]).zfill(6) + str(i+1).zfill(6)

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

Submission status: Accepted

Solution code:
def K(n):
  a=0
  while n>0:
    n=n//10
    a=a+1
  return a

n,m=map(int,input().split())
A=[[0]*3 for i in range(m)]
ans=[0]*m
for i in range(m):
  A[i][0],A[i][1]=map(int,input().split())
  A[i][2]=i
A.sort()
a=0
b=1
for i in range(m):
  if a==A[i][0]:
    b=b+1
  else:
    a=A[i][0]
    b=1
  S=""
  T=""
  B=list(str(A[i][0]))
  C=list(str(b))
  for j in range(6-K(A[i][0])):
    S=S+"0"
  for j in range(K(A[i][0])):
    S=S+B[j]
  for j in range(6-K(b)):
    T=T+"0"
  for j in range(K(b)):
    T=T+C[j]
  ans[A[i][2]]=S+T
for i in range(m):
  print(ans[i])

Submission status: Accepted

Solution code:
# import bisect
# from collections import Counter, deque
# import copy
# from fractions import gcd
# from functools import reduce
# from itertools import accumulate, permutations, combinations, combinations_with_replacement, groupby, product
# import math
# import numpy as np
import sys

sys.setrecursionlimit(10 ** 5 + 10)


# input = sys.stdin.readline

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

    data1 = sorted(data, key=lambda x: x[1])
    cnt=[0]*N
    dic={}

    for [p,y] in data1:
        cnt[p-1]+=1
        dic[y]="%06d%06d"%(p,cnt[p-1])

    for [p,y] in data:
        print(dic[y])






resolve()

Submission status: Accepted

Solution code:
# import bisect
# from collections import Counter, deque
# import copy
# from fractions import gcd
# from functools import reduce
# from itertools import accumulate, permutations, combinations, combinations_with_replacement, groupby, product
# import math
# import numpy as np
import sys
sys.setrecursionlimit(10 ** 5 + 10)
# input = sys.stdin.readline

def resolve():
    N,M=map(int,input().split())
    P=[]
    city_count=[0]*N
    city_end=[1]*N
    for i in range(M):
        p,y=map(int,input().split())
        city_count[p-1]+=1
        P.append([p,y])

    P1 = sorted(P, key=lambda x: x[1])
    P1=sorted(P1)
    for i in P1:
        i.append(city_end[i[0]-1])
        city_end[i[0] - 1]+=1


    for i in P:
        print(str(i[0]).zfill(6)+str(i[2]).zfill(6))


    #P = dict(sorted(P.items()))

resolve()

Submission status: Accepted

Solution code:
#「県ごとの市の「市番号(id)、誕生年(year)」リスト」と「市番号順の市の認識番号(tag)リスト」を用意する

class City:
    #市番号と誕生年を管理する
    def __init__(self,id,y):
        self.id = id
        self.year = y


def main():
    n,m = map(int,input().split())
    pre_lst = [[] for _ in range(n)]  #各県に含まれる市のリスト
    city_tags = [0 for _ in range(m)] #上記のリストから作った市の認識番号を格納するためのリスト

    for i in range(m):
        p,y = map(int,input().split())
        pre_lst[p-1].append(City(i,y)) #入力を受け取り、県ごとのリストを作る

    for pre_num,pre in enumerate(pre_lst):
        if len(pre) <= 0:
            continue
        pre.sort(key = lambda x:x.year) #各県ごとに誕生年順にソート

        counter = 0 #認識番号の右側、何番目に誕生した都市かを作るためのカウンター
        for city in pre:
            city_tags[city.id] = str(pre_num+1).zfill(6) + str(counter+1).zfill(6)
            counter += 1
    for tag in city_tags:
        print(tag)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
class City:
    def __init__(self,id,y):
        self.id = id
        self.year = y


def main():
    n,m = map(int,input().split())
    pre_lst = [[] for _ in range(n)]
    city_tags = [0 for _ in range(m)]

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

    for pre_num,pre in enumerate(pre_lst):
        if len(pre) <= 0:
            continue
        pre.sort(key = lambda x:x.year)
        counter = 0
        for city in pre:
            city_tags[city.id] = str(pre_num+1).zfill(6) + str(counter+1).zfill(6)
            counter += 1
    for tag in city_tags:
        print(tag)


if __name__ == '__main__':
    main()

Submission status: Accepted

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

data = []

for i in range(m):
    temp_p, temp_y = input().split()
    temp_p, temp_y = int(temp_p), int(temp_y)
    data.append([temp_p, temp_y, i])

data.sort()

result = [[] for _ in range(m)]

i = data[0][0]

k = 1

for j in range(m):
    if i != data[j][0]:
        k = 1
        i = data[j][0]
    result[data[j][2]] = [data[j][0], k]
    k += 1

for temp_data in result:
    print("{:0>6}".format(temp_data[0]) + "{:0>6}".format(temp_data[1]))

Submission status: Accepted

Solution code:
import sys

N,M = (int(x) for x in input().split())
li = []
for i in range(M):
  a,b = (int(x) for x in input().split())
  li.append([i,a,b,""])

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

cnt = [1]*N
for i in range(M):
  li[i][3] = str(li[i][1]).zfill(6) + str(cnt[li[i][1]-1]).zfill(6)
  cnt[li[i][1]-1] += 1
  
li.sort(key=lambda x: x[0])
for i in range(M):
  print(li[i][3])

Submission status: Accepted

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


def binary_search(list, item):
    low = 0
    high = len(list) - 1

    while low <= high:
        mid = (low + high) // 2
        guess = list[mid]
        if guess == item:
            return mid
        if guess > item:
            high = mid - 1
        else:
            low = mid + 1


n, m = map(int, input().split())
py = [list(map(int, input().split())) for i in range(m)]
check = sorted(py)
memo = py[0][0]
cnt = [0] * m
cnt_memo = 0

for i in range(m):
    if memo != check[i][0]:
        memo = check[i][0]
        cnt_memo = 0
    cnt_memo += 1
    cnt[i] = cnt_memo

for i in range(m):
    number = str(cnt[binary_search(check, py[i])])
    p = str(py[i][0])
    print((6 - len(p)) * '0' + p + (6 - len(number)) * '0' + number)

Submission status: Accepted

Solution code:
import collections
import bisect
n, m = map(int, input().split())#入力
s = [[int(_) for _ in input().split() ] for _ in range(m)]
a = collections.defaultdict(list)#「県」と「市の誕生順」を分けて管理
for x,y in sorted(s):#ソート⇒県の順番に並ぶ
    a[x]+=[y]
for x,y in s:
    z = bisect.bisect(a[x],y)
    #二分検索⇒「県」内の「市の誕生順」のインデックスを返す
    print("%06d%06d"%(x,z))#形式を整えて出力、出力は入力時の順番

Submission status: Accepted

Solution code:
import collections
import bisect

n, m = map(int, input().split())#入力
s = [[int(_) for _ in input().split() ] for _ in range(m)]
a = collections.defaultdict(list)#「県」と「市の誕生順」を分けて管理

for x,y in sorted(s):#ソート⇒県の順番に並ぶ
    a[x]+=[y]
for x,y in s:
    z = bisect.bisect(a[x],y)#二分検索⇒市の誕生順のインデックスが返る
    print("%06d%06d"%(x,z))#形式を整えて出力

Submission status: Accepted

Solution code:
import collections
import bisect

n, m = map(int, input().split())#入力
s = [[int(_) for _ in input().split() ] for _ in range(m)]
a = collections.defaultdict(list)#「県」と「市の誕生順」を分けて管理

for x,y in sorted(s):#ソート⇒県の順番に並ぶ
    a[x]+=[y]
for x,y in s:
    z = bisect.bisect(a[x],y)#二分検索⇒市の誕生順に並ぶ
    print("%06d%06d"%(x,z))#形式を整えて出力

Submission status: Accepted

Solution code:
import collections
import bisect

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

s = [[int(_) for _ in input().split() ] for _ in range(m)]
a = collections.defaultdict(list)

for x,y in sorted(s):
    a[x]+=[y]
for x,y in s:
    z = bisect.bisect(a[x],y)
    print("%06d%06d"%(x,z))

Submission status: Accepted

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

    p = [[] for _ in range(m + 1)]
    y = [[] for _ in range(m + 1)]

    pref = [[] for _ in range(n + 1)]
    
    for i in range(m):
        _p, _y = list(map(int, input().split()))
        p[i] = _p
        y[i] = _y

        pref[_p].append(_y)

    for i in range(len(pref)):
        pref[i] = list((sorted(pref[i])))

    _pref = [[] for _ in range(len(pref))]
    for i in range(len(_pref)):
        _pref[i] = dict(zip(pref[i], range(1, len(pref[i]) + 1)))


    for i in range(m):
        print("{:06}{:06}".format(p[i], _pref[p[i]][y[i]]))

if __name__ == "__main__":
    solve()

Submission status: Accepted

Solution code:
from sys import stdin
def f(n,m):
    n,m=str(n),str(m)
    s1=["0"]*(6-len(n))
    s1.append(n)
    s2=["0"]*(6-len(m))
    s2.append(m)
    return "".join(s1)+"".join(s2)

def main():
    #入力
    readline=stdin.readline
    N,M=map(int,readline().split())
    li=[0]*M
    for i in range(M):
        a=list(map(int,readline().split()))
        a.append(i)
        li[i]=a
    
    li.sort(key=lambda x:x[1])
    count=[1]*(N+1)
    for i in range(M):
        city_number=li[i][0]
        x=count[city_number]
        count[city_number]+=1
        li[i].append(f(city_number,x))

    li.sort(key=lambda x:x[2])
    for i in range(M):
        print(li[i][3])
        
if __name__=="__main__":
    main()

Submission status: Accepted

Solution code:
from collections import defaultdict
N,M=map(int,input().split())
dic=defaultdict(list)
DIC=defaultdict(str)
l=[]
for i in range(M):
  i,x=map(int,input().split())
  l.append([i,x])
  dic[i].append(x)
for i in range(1,N+1):
  half_l='0'*(6-len(str(i)))+str(i)
  if len(dic[i])==0:
    pass
  else:
    sorted_l=sorted(dic[i])
    index_dic={}
    index=1
    for num in sorted_l:
      index_dic[num]=index
      index+=1
    for j in range(len(dic[i])):
      INDEX=index_dic[dic[i][j]]
      half_r='0'*(6-len(str(INDEX)))+str(INDEX)
      DIC[(i,dic[i][j])]=half_l+half_r
for i in range(M):
  i,x=l[i][0],l[i][1]
  print(DIC[(i,x)])

Submission status: Accepted

Solution code:

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

ans = [None] * m
for i in  range(n):
    data[i].sort()
    for j in range(len(data[i])):
        y, k = data[i][j]
        ans[k] = '0' * (6 - len(str(i + 1))) + str(i + 1) + '0' * (6 - len(str(j + 1))) + str(j + 1)

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

Submission status: Accepted

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

CITYID = 2
PREF = 0
YEAR = 1
city = [[int(x) for x in input().split()] + [i] for i in range(M)]

city.sort()
id = [""] * M
ord = 1 # 同じ県の中の順番

for i in range(M):
    if i > 0 and city[i][PREF] == city[i - 1][PREF]:
        ord += 1
    else:
        ord = 1
    id[city[i][CITYID]] = '{:0>6}{:0>6}'.format(str(city[i][PREF]),  str(ord))

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

Submission status: Accepted

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

Ans = [None] * m
pre_p = City[0][0]
cnt = 1
for p, y, i in City:
    if pre_p != p:
        cnt = 1
        pre_p = p
    Ans[i] = '0'*(6 - len(str(p))) + str(p) + '0'*(6 - len(str(cnt))) + str(cnt)
    cnt += 1
print(*Ans, sep='\n')

Submission status: Accepted

Solution code:
n, m = map(int, input().split())
ary = []
for i in range(m):
    #[0] = 県, [1] = 誕生年
    ary.append([int(x) for x in input().split()])
    ary[i].append(i) #[2] = 復元用の通し番号

#県でソートして、同じなら誕生年順にソート
ary.sort(key=lambda x:(x[0], x[1]))

p = 1
num = 1
for v in ary:
    if v[0] != p:
        p = v[0]
        num = 1
    _id = str(v[0]).zfill(6) + str(num).zfill(6)
    num += 1
    v.append(_id)

ary.sort(key=lambda x:x[2]) #最初の順序に復元

for v in ary:
    print(v[3])

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import collections
from bisect import bisect


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

    a = collections.defaultdict(list)
    for x, y in sorted(PY):
        a[x] += [y]

    for x, y in PY:
        z = bisect(a[x], y)
        print("%06d%06d" % (x, z))


if __name__ == "__main__":
    main()

Submission status: Accepted

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

a = []
for i in range(m):
  #[0] = 県
  #[1] = 誕生年
  #[2] = 市番号
  a.append(list(map(int, input().split())))
  a[i].append(i)

#県、誕生年ごとにソート
a.sort(key=lambda x:(x[0], x[1]))
p = 0
num = 1
for v in a:
  if not v[0] == p:
    p = v[0]
    num = 1
  _id = str(v[0]).zfill(6) + str(num).zfill(6)
  num += 1
  v.append(_id)

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

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

Submission status: Accepted

Solution code:
from collections import defaultdict
import bisect

N,M = map(int, input().split())
PY = [tuple(map(int, input().split())) for _ in range(M)]

prefs = defaultdict(list)


for p, y in PY:
    # ここで実際の誕生年をつめてから、あとで県ごとにソートして単なる順番に座標圧縮
    prefs[p].append(y)

for k in prefs.keys():
    # 順に並び替えたので、後にbisectで位置を探せば誕生年から順番で取り出せる
    prefs[k].sort()

for p, y in PY:
    idx = bisect.bisect_left(prefs[p], y)
    print(str(p).zfill(6) + str(idx+1).zfill(6))

Submission status: Accepted

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

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

indices = list(range(M))
sorted_indices = sorted(indices, key=lambda i: PY[i])
PY.sort()

def calc(x):
    n = len(str(x))
    res = ""
    if n < 6:
        for i in range(6-n):
            res += "0"
    res += str(x)
    return res

before = 0
num = 1
ans = [0]*M
for i in range(M):
    if before != PY[i][0]:
        num = 1
        ans[sorted_indices[i]] = calc(PY[i][0])+calc(num)
        num += 1
        before = PY[i][0]
    else:
        ans[sorted_indices[i]] = calc(PY[i][0])+calc(num)
        num += 1
        before = PY[i][0]

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

Submission status: Accepted

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


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

result = [None]*m

for p,i in enumerate(input_list) :
  for n, (a,b) in enumerate(i):
    result[b] = str(p+1).zfill(6)+str(n+1).zfill(6)
    
print(*result, sep = '\n')

Submission status: Accepted

Solution code:
from operator import itemgetter
n,m=map(int,input().split())
l=[]
for i in range(m):
  g=list(map(int,input().split()))
  l.append(g)
  l[i].append(i)
l.sort()
l[0][1]=1
for i in range(1,m):
  if l[i][0]==l[i-1][0]:
    l[i][1]=int(l[i-1][1])+1
  else:
    l[i][1]=1
newl=sorted(l,key=itemgetter(2))
for i in range(m):  
  print((6-len(str(newl[i][0])))*'0'+str(newl[i][0])+(6-len(str(newl[i][1])))*'0'+str(newl[i][1]))

Submission status: Accepted

Solution code:
n, m = [int(i) for i in input().split()]
data = []  # P, Y and Order
for i in range(m):
    arr = [int(k) for k in input().split()]
    data.append(arr + [i])

data.sort()
id = []  # P, x and Order
now_p = rank = 0
for p, _, o in data:
    if now_p != p:
        now_p = p
        rank = 1
    id.append([p, rank, o])
    rank += 1

id.sort(key=lambda x: x[2])
for p, x, _ in id:
    print('{:06}{:06}'.format(p, x))

Submission status: Accepted

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

YPI.sort()
ans = [''] * M
num_city = {}
for y, p, i in YPI:
  if p in num_city:
    num_city[p] += 1
  else:
    num_city[p] = 1
  
  ans[i] = str(p).zfill(6) + str(num_city[p]).zfill(6)

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

Submission status: Accepted

Solution code:
from collections import defaultdict

def main():
    n, m = [int(e) for e in input().split()]
    PY = [[int(e) for e in input().split()] for i in range(m)]

    Ds = defaultdict(set)
    for p, y in PY:
        Ds[p].add(y)

    Dd = defaultdict(dict)
    for p, s in Ds.items():
        for i, y in enumerate(sorted(s)):
            Dd[p][y] = i + 1

    for p, y in PY:
        print('{:06}{:06}'.format(p, Dd[p][y]))

if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
n,m=map(int,input().split())
pp=[0]*6
xx=[0]*6
PY=[list(map(int,input().split())) for _ in range(m)]
g=[[] for _ in range(n+1)]
for i ,(p,y) in enumerate(PY):
    g[p].append((y,i))

ans=[0]*m
for i in range(n+1):
    for o,(j,k) in enumerate(sorted(g[i])):
        ans[k]=str(i).zfill(6)+str(o+1).zfill(6)
for i in ans:
    print(i)

Submission status: Accepted

Solution code:


def read_input():
    n, m = map(int, input().split())
    pylist = [tuple(map(int, input().split())) for _ in range(m)]
    return n, m, pylist


def submit():
    n, m, pylist = read_input()
    pylist_count = {}

    pylist_sort = sorted(pylist, key=lambda x: x[1])
    cities = {i: 0 for i in range(1, n + 1)}

    for p, y in pylist_sort:
        cities[p] += 1
        pylist_count[(p, y)] = cities[p]
    
    for p, y in pylist:
        print(str(p).zfill(6) + str(pylist_count[(p, y)]).zfill(6))


if __name__ == "__main__":
    submit()

Submission status: Accepted

Solution code:
n,m=map(int,input().split())
num=[[] for i in range(n)]
p=[0]*m
y=[0]*m
for i in range(m):
  p[i],y[i]=map(int,input().split())
  num[p[i]-1].append((i,y[i]))
score=['']*m
for i in range(n):
  num[i].sort(key=lambda x:x[1])
  idx=1
  for s,t in num[i]:
    score[s]=str(i+1).zfill(6)+str(idx).zfill(6)
    idx+=1
print(*score,sep='\n')

Submission status: Accepted

Solution code:
n, m = map(int, input().split())
L = [tuple(map(int, input().split())) for _ in range(m)]
cnt = [0]*(n+1)
IDs = {}
for p, y in sorted(L, key = lambda x: x[1]):
    cnt[p] += 1
    
    # Yをkey, IDがvalueとなるように辞書型で格納.
    IDs[y] = '%06d%06d' % (p, cnt[p])
for _, y in L:
    print(IDs[y])

Submission status: Accepted

Solution code:
from collections import defaultdict
import bisect
N, M = map(int, input().split())
PY = []
PYd = defaultdict(list)
for i in range(M):
    x, y = map(int, input().split())
    PYd[x].append(y)
    PY.append((x,y))

for i in PYd.keys():
    PYd[i].sort()

for p,y in PY:
    str_p = str(p).zfill(6)
    index = str(bisect.bisect(PYd[p],y)).zfill(6)
    print(str_p + index)

Submission status: Accepted

Solution code:
from collections import defaultdict
import bisect
N, M = map(int, input().split())
PY = []
PYd = defaultdict(list)
for i in range(M):
    x, y = map(int, input().split())
    PYd[x].append(y)
    PY.append((x,y))

for i in PYd.keys():
    PYd[i].sort()

for p,y in PY:
    str_p = str(p).zfill(6)
    index = str(bisect.bisect(PYd[p],y)).zfill(6)
    print(str_p + index)

Submission status: Accepted

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

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

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

tlist={}

for indlist in mlist:
    ken=indlist[0]
    if ken in tlist:
        indlist[1]=tlist[ken]+1
        tlist[ken] = tlist[ken]+1
    else:
        indlist[1]=1
        tlist[ken]=1

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

for result in mlist:
    pref=str(result[0])
    ord=str(result[1])
    output=""
    leng=len(pref)
    for i in range(6-leng):
        output +="0"
    output += pref

    leng=len(ord)
    for i in range(6-leng):
        output +="0"
    output += ord

    print(output)

Submission status: Accepted

Solution code:
import collections
import bisect

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

s = [[int(_) for _ in input().split() ] for _ in range(m)]
a = collections.defaultdict(list)

for x,y in sorted(s):
    a[x]+=[y]
for x,y in s:
    z = bisect.bisect(a[x],y)
    print("%06d%06d"%(x,z))

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
N, M = map(int,input().split())
P = []
for i in range(M) :
    p, y = map(int,input().split())
    P.append([p, y, i])

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

ans = [0 for i in range(M)]
count = 1

for i in range(M) :
    num = P[i][2]
    if i > 0 :
        if P[i][0] == P[i-1][0] :
            count += 1
        else :
            count = 1
    ans[num] = str(P[i][0]).zfill(6) + str(count).zfill(6)

for t in ans :
    print(t)

Submission status: Accepted

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

ans = []
for i in range(m):
    p = py[i][0]
    y = py[i][1]
    key = py[i][2]
    if i == 0:
        ans.append([p, 1, key])
    elif i >= 1:
        if ans[i - 1][0] == p:
            ans.append([p, ans[i - 1][1] + 1, key])
        else:
            ans.append([p, 1, key])

ans = sorted(ans, key=lambda x: x[2])
for i in range(m):
    print(format(ans[i][0], '06'), end='')
    print(format(ans[i][1], '06'))

Submission status: Accepted

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

for _ in range(M):
    p, y = map(int, input().split())
    PY.append((p - 1, y))
    P[p - 1].append(y)
# print(P)

PD = [{} for _ in range(N)]

for i in range(N):
    for j, c in enumerate(sorted(P[i]), 1):
        PD[i][c] = j
    # print(PD)

for p, y in PY:
    print('%06d%06d' % (p + 1, PD[p][y]))

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-

N,M = list(map(int, input().rstrip().split()))
PY_list = [list(map(int, input().rstrip().split())) for i in range(M)]
#-----

## key= int, Number of Prefecture
## value= list, BirthYear of city
pref_dic={}

for p,y in PY_list:
    pref_dic.setdefault(p,[])
    pref_dic[p] += [y]

for k in pref_dic:
    pref_dic[k].sort()

## key= int, BirthYear of city
## value= int, Index of BirthYear-list in each Prefecture
city_dic={}

for k in pref_dic:
    for i,year in enumerate( pref_dic[k] ):
        city_dic.setdefault(year,-1)
        city_dic[year] = i

for m in range(M):
    inum_pref = PY_list[m][0]
    #inum_city = pref_dic[ inum_pref ].index( PY_list[m][1] ) + 1
    inum_city = city_dic[ PY_list[m][1] ] + 1
    print('{0:06}{1:06}'.format(inum_pref, inum_city))

Submission status: Accepted

Solution code:
from bisect import bisect_left as bl


def f(v):
    v = str(v)
    return '0' * (6 - len(v)) + v


N, M = map(int, input().split())
dic = dict()
PY = []
for i in range(M):
    p, y = map(int, input().split())
    if dic.get(p, False):
        dic[p].append(y)
    else:
        dic[p] = [y]
    PY.append((p, y))

for i in range(1, N + 1):
    if dic.get(i, False):
        dic[i] = sorted(dic[i])

# print('dic', dic, PY)
for i in range(M):
    p, y = PY[i]
    # print('p y', p, y)
    l = dic[p]
    ans = f(p) + f(bl(l, y) + 1)
    print(ans)

Submission status: Accepted

Solution code:
def main():
    N, M = map(int, input().split())
    P = [[] for _ in range(N)]
    PY = []
    for _ in range(M):
        p, y = map(int, input().split())
        PY.append((p - 1, y))
        P[p - 1].append(y)
    PD = [{} for _ in range(N)]
    for i in range(N):
        for j, c in enumerate(sorted(P[i]), 1):
            PD[i][c] = j
    for p, y in PY:
        print('%06d%06d' % (p + 1, PD[p][y]))

main()

Submission status: Accepted

Solution code:
n,m = map(int,input().split())
py = [list(map(int,input().split()))+[_] for _ in range(m)]
py.sort()
flag = py[0][0]
flag_2 = 1
for i in range(m):
  if flag != py[i][0]:
    flag = py[i][0]
    flag_2 = 1
  py[i][0] = (6-len(str(py[i][0])))*"0"+str(py[i][0])
  py[i][1] = (6-len(str(flag_2)))*"0"+str(flag_2)
  flag_2 += 1
py.sort(key = lambda py:py[2])
for j in range(m):
  print("".join(py[j][:2]))

Submission status: Accepted

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

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

ans = [None]*m

for i,d in enumerate(lst):
    d.sort()
    for j, (Y,I) in enumerate(d):
        ans[I] = str(i+1).zfill(6) + str(j+1).zfill(6)

for i in ans:
    print(i)

Submission status: Accepted

Solution code:
from operator import itemgetter
n,m = map(int,input().split())
lists = [list(map(int,input().split())) for i in range(m)]
for i in range(m):
    lists[i].append(i)
sort_lists = sorted(lists,key=itemgetter(0,1))
cnt = 1
ans = []
for i in range(m-1):
    tmp = sort_lists[i][0]
    left =  '{0:06d}'.format(tmp)
    right = '{0:06d}'.format(cnt)
    if tmp == sort_lists[i+1][0]:
        cnt += 1
    else:
        cnt = 1
    ans.append([str(left) + str(right),sort_lists[i][2]] )
tmp = sort_lists[-1][0]
left = '{0:06d}'.format(tmp)
right = '{0:06d}'.format(cnt)
ans.append([str(left) + str(right), sort_lists[-1][2] ])
ans.sort(key = itemgetter(1))
for i in range(m):
    print(ans[i][0])


#3 4
#1 45
#2 34
#3 56
#1 65

Submission status: Accepted

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

L = [[] for i in range(n)]
D = []

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

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

for i in range(m):
    s1 = str(D[i][0]).zfill(6)
    s2 = str(bisect.bisect_left(L[D[i][0]-1], D[i][1])+1).zfill(6)
    print(s1+s2)

Submission status: Accepted

Solution code:
N,M=map(int,input().split(' '))
PY=[tuple(map(int,input().split(' '))) for _ in range(M)]
P=[[] for i in range(N)]
num = []
for n,i in enumerate(PY):
    P[i[0]-1].append((i[1],n))
for n0,i in enumerate(P):
    for n,j in enumerate(sorted(i)):
        num.append((j[1],format(n0+1,'06')+format(n+1,'06')))
for i in sorted(num):
    print(i[1])

Submission status: Accepted

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

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

ans = [[0] * 2 for i in range(m)]
cnt = 0
val = py[0][0]
for i in range(m):
    #print(val)
    if py[i][0] != val:
        cnt = 0
        val = py[i][0]
    cnt += 1

    ans[py[i][2]][0] = py[i][0]
    ans[py[i][2]][1] = cnt
#print(ans)
for i in range(m):
    print('0' * (6 - len(str(ans[i][0]))) + str(ans[i][0]) + '0' * (6 - len(str(ans[i][1]))) + str(ans[i][1]))