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:
a, b = map(int, input().split())
l = [[int(i) for i in input().split()] for i in range(b)] 

for i in range(b):
    l[i].append(i)

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

l[0].append(1)
for i in range(1,b):
    if l[i][0] != l[i-1][0]:
        l[i].append(1)
    else:
        l[i].append(l[i-1][3] + 1)

for i in range(b):
    l[i].append(str(l[i][0]).zfill(6) + str(l[i][3]).zfill(6))

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

for i in range(b):
    print(l[i][4])

Submission status: Accepted

Solution code:
N, M = map(int,input().split())
PY = [list(map(int,input().split())) + [0] for _ in range(M)]
sort_PY = sorted(PY, key = lambda x: x[1])
d = {}
for py in sort_PY:
  if(py[0] not in d):
    d[py[0]] = 1
  else:
    d[py[0]] += 1
  py[2] = d[py[0]]
for py in PY:
  print(str(py[0]).zfill(6) + str(py[2]).zfill(6))

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,p,y])

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

id=1
old_city=0
for city_id in city:
    if city_id[1]!=old_city:
        id=1
    city_id[2]=id
    id+=1
    old_city=city_id[1]

city.sort(key = lambda t:t[0])

for x in city:
    ans=x[1]*1000000+x[2]
    print("{0:012d}".format(ans))

Submission status: Accepted

Solution code:
import numpy as np
N, M = map(int, input().split())
data = np.zeros((4, M))
 
for i in range(M):
    data[0, i] = i+1
    data[1:3, i] = list(map(int, input().split()))
 
city = [0 for i in range(N)]
data = data[:, np.argsort(data[2, :])]
for i in range(M):
    city[int(data[1, i]-1)] += 1
    data[3, i] = city[int(data[1, i]-1)]
 
data = data[:, np.argsort(data[0, :])]
for i in range(M):
    tmp = str(int(data[1, i])).zfill(6) + str(int(data[3, i])).zfill(6)
    print(tmp)

Submission status: Accepted

Solution code:
# coding:utf-8

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

def gen_id(n):
    id = ""
    hokan = 6 - len(str(n))
    for _ in range(hokan):
        id += "0"
    id += str(n)
    return id

DIC = dict()
CITY = []

for pi in range(1, N+1):
    DIC[pi] = []

for i in range(M):
    pi, yi = map(int, input().split())
    DIC[pi].append({ "i":i, "p":pi, "y":yi})

# まずは県ごとにソートする
for pi in range(1, N+1):
    DIC[pi] = sorted(DIC[pi], key=lambda x: x["y"])

# 認識番号を生成
for pi in range(1, N+1):
    for index, city in enumerate(DIC[pi]):
        id = gen_id(city["p"]) + gen_id(index+1)
        city["id"] = id
        CITY.append(city)

# 市番号でソート
x =sorted(CITY, key=lambda x: x["i"])

for i in x:
    print(i["id"])

Submission status: Accepted

Solution code:
N,M = map(int,raw_input().split())
data = []

#for i in range(M):
#    A,B = map(int,raw_input().split())
#    data.append([A,B,i])

for i in range(M):
    A,B = map(int,raw_input().split())
    data.append([A,B,i])

data.sort()
P = data[0][0]
counter = 0

for i in range(len(data)):
    if P != data[i][0]:
        P = data[i][0]
        counter = 0
    data[i] = [data[i][2],P,counter+1]
    counter += 1

data.sort()
for i in data:
    print format(i[1],'06')+format(i[2],'06')

Submission status: Accepted

Solution code:
class struct:
  def __init__(self,i,a,b,c):
    self.i=i
    self.a=a
    self.b=b
    self.c=c
n,m=map(int,input().split())
l=[]
l2=[]#市番
for i in range(n):
  l2.append(1)
for i in range(m):
  a,b=map(int,input().split())
  l.append(struct(i,a,b,0))
l=sorted(l,key=lambda x:(x.a,x.b))
for i in range(m):
  a=l[i].a
  l[i].c=l2[a-1]
  l2[a-1]+=1
l=sorted(l,key=lambda x:x.i)
for i in l:
  print(str(i.a).zfill(6)+str(i.c).zfill(6))

Submission status: Accepted

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

s = sorted(a,key=lambda x:(x[0],x[1]))
f=s[0][0]
d=1
for i in range(m):
    if s[i][0] == f:
        s[i][1]=d
        d+=1
    else:
        f=s[i][0]
        d=1
        s[i][1]=d
        d+=1
for i in range(m):
    print("{:06}".format(a[i][0]) +"{:06}".format(a[i][1]))

Submission status: Accepted

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

x=[]
for i in range(m):
    p,y = input().split()
    x.append({"i":i, "p":p, "y":int(y)})
cnt = {}
x=sorted(x, key=lambda z: z["y"])
for city in x:
    c = cnt.get(city["p"], 0)
    cnt[city["p"]] = c+1
    city["n"] = city["p"].zfill(6) + str(c+1).zfill(6)

x = sorted(x, key=lambda z: z["i"])
for city in x:
    print(city["n"])

Submission status: Accepted

Solution code:
import bisect
n,m=(int(i) for i in input().split())
a=[[] for _ in range(n)]
s=[]

for _ in range(m):
    x,c=(int(i) for i in input().split())
    a[x-1].append(c)
    s.append((x,c))

[a[i].sort() for i in range(n)]

for x,c in s:
    print("{:06}{:06}".format(x, bisect.bisect_left(a[x-1],c)+1))

Submission status: Accepted

Solution code:
from operator import itemgetter
N,M = [int(x) for x in input().split()]
P = [0]*M
Y = [0]*M
pref = [[] for _ in range(N)]
city = [0]*M
for i in range(M):
    P[i],Y[i] = [int(x) for x in input().split()]
    pref[P[i]-1].append([i,Y[i]])
for index,i in enumerate(pref):
    pref[index].sort(key=itemgetter(1))
for index,i in enumerate(pref):
    for index2,j in enumerate(i):
        city[j[0]]='{:0=6}'.format(index+1)+'{:0=6}'.format(index2+1)
for i in city:
    print(i)

Submission status: Accepted

Solution code:
import numpy as np
N, M = map(int, input().split())
data = np.zeros((4, M))

for i in range(M):
    data[0, i] = i+1
    data[1:3, i] = list(map(int, input().split()))

city = [0 for i in range(N)]
data = data[:, np.argsort(data[2, :])]
for i in range(M):
    city[int(data[1, i]-1)] += 1
    data[3, i] = city[int(data[1, i]-1)]

data = data[:, np.argsort(data[0, :])]
for i in range(M):
    tmp = str(int(data[1, i])).zfill(6) + str(int(data[3, i])).zfill(6)
    print(tmp)

Submission status: Accepted

Solution code:
N,M = map(int,input().split())
info = [list(map(int,input().split())) for i in range(M)]
info_new = sorted(info,key=lambda x:(x[0],x[1]))
note = info_new[0][0]
cnt = 1
for i in range(M):
    if info_new[i][0] == note:
        info_new[i][1] = cnt
        cnt += 1
    else:
        note = info_new[i][0]
        cnt = 1
        info_new[i][1] = cnt
        cnt += 1
        
for i in range(M):
    pri = str(info[i][0])
    bir = str(info[i][1])
    number = "0"*(6-len(pri)) + pri + "0"*(6-len(bir)) + bir
    print(number)

Submission status: Accepted

Solution code:
nm_lst = list(map(int, input().split()))
city_lst = [list(map(int, (str(i)+' '+input()).split())) for i in range(nm_lst[1])]

city_lst = sorted(city_lst, key = lambda x: x[1]*(10**12) + x[2])

ans_lst = []
num_num = 0
for n, city in enumerate(city_lst):
    prefec_num = city[1]
    prefec_str = '0' * (6-len(str(prefec_num))) + str(prefec_num)
    if n == 0 or (prefec_num != city_lst[n-1][1]):
        num_num = 1
    else:
        num_num += 1
    num_str = '0' * (6-len(str(num_num))) + str(num_num)
    ans_lst.append([city[0], prefec_str, num_str])
    
ans_lst = sorted(ans_lst, key = lambda x:x[0])

for city in ans_lst:
    print(city[1]+city[2])

Submission status: Accepted

Solution code:
import bisect
n, m = (int(i) for i in input().split())
yl = [[] for _ in range(n)]
dl = []

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

[yl[i].sort() for i in range(n)]

for p, y in dl:
    print("{:0>6}{:0>6}".format(p, bisect.bisect_left(yl[p-1], y)+1))

Submission status: Accepted

Solution code:
import bisect
n, m = (int(i) for i in input().split())
yl = []
[yl.append([]) for _ in range(n)]
dl = []

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

[yl[i].sort() for i in range(n)]

for p, y in dl:
    print("{:0>6}{:0>6}".format(p, bisect.bisect_left(yl[p-1], y)+1))

Submission status: Accepted

Solution code:
import numpy as np
n, m = map(int,input().split())
l = [list(map(int,input().split()))+ [0] for i in range(m)]
l2 = sorted(l)
p = 0
for i in l2:
    x = 1 if i[0] != p else x + 1
    p = i[0]
    i[2] = x
for i in l:
    print(str(i[0]).zfill(6)+str(i[2]).zfill(6))

Submission status: Accepted

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

def main():
    [N, M] = list(map(int, input().split()))
    c_list = []
    for i in range(M):
        [p, y] = list(map(int, input().split()))
        c_list.append((i, p, y))

    c_list.sort(key = lambda t: t[2])

    ct = [0] * (N + 1)
    id_list = []
    for i in range(M):
        j, p, y = c_list[i]
        ct[p] += 1
        w = str(1000000 + p)[1:] + str(1000000 + ct[p])[1:]
        id_list.append((j, w))

    id_list.sort(key = lambda t: t[0])

    for i in range(M):
        print(id_list[i][1])



if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
n,m = map(int, input().split())
a = [[] for _ in range(n)]
count = 1
for i in range(m):
    p,y = map(int, input().split())
    a[p-1].append([y, count])
    count += 1
b = []
for i,j in enumerate(a):
    j_sort = sorted(j)
    for k,l in enumerate(j_sort):
        b.append([l[1],str(i+1).zfill(6)+str(k+1).zfill(6)])
for i in sorted(b):
    print(i[1])

Submission status: Accepted

Solution code:
from collections import defaultdict
n, m = map(int, input().split())

a = [list(map(int, input().split())) +[i, None] for i in range(m)]
a.sort(key=lambda x: x[1])
d = defaultdict(int)
for i in range(m):
    p,y = a[i][0], a[i][1]
    d[p] += 1
    code = "{0:06d}{1:06d}".format(p, d[p])
    a[i][3] = code
a.sort(key=lambda x: x[2])
for i in a:
    print(i[3])

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
 
N, M = (int(i) for i in input().split())
py_list = [[int(i) for i in input().split()] + [0] for i in range(M)] 
m_list = [[] for j in range(N+1)]
 
sorted_py_list = sorted(py_list, key=lambda x:x[1])

city_list = {}
for py in sorted_py_list:
    city_list[py[0]] = city_list[py[0]]+1 if py[0] in city_list else 1
    py[2] = city_list[py[0]]
 
for py in py_list:
    print(str(py[0]).zfill(6) + str(py[2]).zfill(6))

Submission status: Accepted

Solution code:
N, M = map(int,input().split())
PY = [list(map(int,input().split())) + [0] for i in range(M)]
sort_PY = sorted(PY, key = lambda x: x[1])
city = {}
for py in sort_PY:
  if(py[0] not in city):
    city[py[0]] = 1
  else:
    city[py[0]] += 1
  py[2] = city[py[0]]
for py in PY:
  print(str(py[0]).zfill(6) + str(py[2]).zfill(6))

Submission status: Accepted

Solution code:
N, M = map(int, input().split())
P, Y = [], []
ydics = [{} for _ in range(N)]
for i in range(M):
    p, y = map(int, input().split())
    ydics[p-1][i] = (p, y)

odic = {}
for ydic in ydics:
    for o, (i, (p, y)) in enumerate(sorted(ydic.items(), key=lambda x: x[1][1])):
        odic[i] = (p, o+1)
for i, (p, o) in sorted(odic.items()):
    print(str(p).zfill(6) + str(o).zfill(6))

Submission status: Accepted

Solution code:
import numpy as np
from operator import itemgetter

N, M = input().split()
N, M = int(N), int(M)
C = [input().split() for i in range(M)]

for i, c in enumerate(C):
  C[i] = [int(c[0]), int(c[1])]
  C[i].append(i)

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

counter = 1
current = 1

for c in C_sorted:
  if current < c[0]:
    counter = 1
  pref = str(c[0])
  num = str(counter)
  number = ''
  for i in range(6 - len(pref)):
    number += '0'
  number += pref
  for i in range(6 - len(num)):
    number += '0'
  number += num

  c.append(number)
  counter += 1
  current = c[0]

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

for c in C_reversed:
  print(c[3])

Submission status: Accepted

Solution code:
n, m = map(int, input().split())
d = [list() for i in range(n+1)] 
out = []
for i in range(m):
    pi, yi = map(int, input().split())
    d[pi].append([yi, i])
    out.append(-1)

for i in range(len(d)):
    d[i].sort()

for i in range(1, n+1):
    for j in range(len(d[i])):
        out[d[i][j][1]] = str(i).zfill(6) + str(j+1).zfill(6)

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

Submission status: Accepted

Solution code:
from collections import defaultdict

N, M = map(int, input().split())
yp = []
d = defaultdict(lambda: [])
ans = ['' for _ in range(M)]
for i in range(M):
    p, y = input().split()
    d[int(p)].append([i, int(y)])


for key in d.keys():
    d[key].sort(key = lambda x : x[1])
    num = 1
    for i in range(len(d[key])):
        ans[d[key][i][0]] += '{:0=6}'.format(key) \
                + '{:0=6}'.format(num) 
        #print('city: ' + str(d[key][i][0]) + ', prefecture: ' + str(key) + ', n-th:', str(i + 1))
        num += 1

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

Submission status: Accepted

Solution code:
n, m = map(int, input().split())
index = 0
listForL = []
listForL2 = []
while index < m:
    p, y = map(int, input().split())
    listForL.append([p, y])
    listForL2.append([p, y, index])
    index+=1

listForL2.sort()
listForAns=[0]*m
index2 =0
count = 0
before=0
while index2 < len(listForL2):
    if before!=listForL2[index2][0]:
        count=1
        before = listForL2[index2][0]
    else:
        count+=1
    mojiR=str(listForL2[index2][0])
    mojiL=str(count)
    index3=0
    if len(mojiR)==1:
        mojiR="00000"+mojiR
    elif len(mojiR)==2:
        mojiR = "0000"+mojiR
    elif len(mojiR)==3:
        mojiR = "000"+mojiR
    elif len(mojiR)==4:
        mojiR = "00"+mojiR
    elif len(mojiR)==5:
        mojiR = "0"+mojiR
    if len(mojiL) == 1:
        mojiL = "00000"+mojiL
    elif len(mojiL) == 2:
        mojiL = "0000"+mojiL
    elif len(mojiL) == 3:
        mojiL = "000"+mojiL
    elif len(mojiL) == 4:
        mojiL = "00"+mojiL
    elif len(mojiL) == 5:
        mojiL = "0"+mojiL
    listForAns[listForL2[index2][2]]=mojiR+mojiL
    index2+=1

for ans in listForAns:
    print(ans)

Submission status: Accepted

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

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

counter = {}
order = {}

for i, p, y in sorted(ipy, key = lambda x: x[2]):
    counter[p] = counter.get(p, 0) + 1
    order[i, p] = counter[p]
    
for i, p, y in ipy:
    print('{:06}{:06}'.format(p, order[i, p]))

Submission status: Accepted

Solution code:
n, m = [int(x) for x in input().split()]
pi_yi_list = [[] for i in range(n)]
input_list = []
iddict = {}
for i in range(m):
    pi, yi = [int(x) for x in input().split()]
    pi_yi_list[pi - 1].append(yi)
    input_list.append(str(pi) + str(yi))
    iddict[str(pi) + str(yi)] = -1
pi_yi_list_sorted = [sorted(x) for x in pi_yi_list]
for pi, pilist in enumerate(pi_yi_list_sorted):
    for j, yi in enumerate(pilist):
        iddict[str(pi + 1) + str(yi)] = '{:0=6}'.format(pi+1) + '{:0=6}'.format(j+1)

for input in input_list:
    print(iddict[input])

Submission status: Accepted

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

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

rankdic = {} # 通し番号：県における順位

for i, p in enumerate(PY):
    # print(p)
    ken_d[p[0]].append([i, p[1]])

for k in range(N+1):
    ken_d[k].sort(key=lambda x:x[1])
    for i, v in enumerate(ken_d[k]):
        rankdic[v[0]] = i # 通し番号辞書に入れる

for i, p in enumerate(PY):
    x = rankdic[i] + 1
    print(str(p[0]).zfill(6) + str(x).zfill(6))

# 気づき：indexはクソ遅い

Submission status: Accepted

Solution code:
N, M = map(int, input().split())
import sys
PY = [list(map(int,sys.stdin.readline().rstrip().split())) for _ in range(M)]

# ken = {p[0] for p in PY}
# ken_d = {k:[] for k in ken}
ken_d = [[] for _ in range(N+1)]

rankdic = {} # 通し番号：県における順位

for i, p in enumerate(PY):
    # print(p)
    ken_d[p[0]].append([i, p[1]])

for k in range(N+1):
    ken_d[k].sort(key=lambda x:x[1])
    for i, v in enumerate(ken_d[k]):
        rankdic[v[0]] = i # 通し番号辞書に入れる

for i, p in enumerate(PY):
    x = rankdic[i] + 1
    print(str(p[0]).zfill(6) + str(x).zfill(6))

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

import array
from bisect import *
from collections import *
import fractions
import heapq 
from itertools import *
import math
import random
import re
import string
import sys

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

ans = [None] * M
ctr = Counter()
for y, p, idx in YPIs:
    ans[idx] = "{:06d}{:06d}".format(p, ctr[p] + 1)
    ctr[p] += 1
for a in ans:
    print(a)

Submission status: Accepted

Solution code:
import numpy as np

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

P=[[] for i in range(n)]
for i in range(m):
    P[inp[i][0]-1].append(inp[i])

out=[]
for i in range(n):
    P[i].sort(key=lambda x:x[1])
    l=len(P[i])
    for j in range(l):
        P[i][j].append(j+1)
        out.append(P[i][j])
out.sort(key=lambda x:x[2])

for i in range(m):
    x=str(out[i][0])
    y=str(out[i][3])
    ID=x.zfill(6)+y.zfill(6)
    print(ID)

Submission status: Accepted

Solution code:
n, m = map(int, input().strip().split())
py = []
pyd = {}

for _ in range(m):
  p, y = map(int, input().strip().split())
  py.append((p, y))
  if p in pyd:
    pyd[p].append(y)
  else:
    pyd[p] = [y]

num = {}
for p, yl in pyd.items():
  for i, y in enumerate(sorted(yl)):
    num[(p,y)] = "%06d%06d" % (p, i+1)

for _py in py:
  print(num[_py])

Submission status: Accepted

Solution code:
import copy
def a():return input()#s
def ai():return int(input())#a,n or k
def ma():return map(int, input().split())#a,b,c,d or n,k
def ms():return map(str, input().split())#,a,b,c,d
def lma():return list(map(int, input().split()))#x or y
def lms():return list(map(str, input().split()))#x or y

N, M = ma()
PY = [lma() + [i] for i in range(M)]
KY = PY.sort()
ans = []
cnt = [0]*N
for p, y, i in PY: #for p, y, i in enumerate(PY): はできない
    ans.append(["%06d%06d" % (p, cnt[p - 1] + 1), i])
    cnt[p - 1] += 1
ans = sorted(ans, key=lambda x: x[1])
for a,i in ans:
    print(a)

Submission status: Accepted

Solution code:
from operator import itemgetter
n,m = map(int,input().split())

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

b=[[i] for i in range(m)]

for i in range(m):
  p[i].extend(b[i])
  
p = sorted(sorted(p, key=itemgetter(1)))

old_p=0
for i in range(m):
  if p[i][0] != old_p :
    old_p = p[i][0]
    count = 1
  else:
    count +=1
  p[i][0] = "0"*(6-len(str(p[i][0])))+str(p[i][0])+"0"*(6-len(str(count)))+str(count)

p = sorted(p, key=itemgetter(2))

for i in range(m):
  print(p[i][0])

Submission status: Accepted

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

for i in range(0,len(inp)):
    P[inp[i][0]-1]+=[inp[i][1]]
for i in range(N):
    P[i].sort()

for i in range(0,len(inp)):
    a=P[inp[i][0]-1]
    b=inp[i][1]
    max=len(a)
    min=-1

    while(max>=min):
        mid=int((max+min)/2)
        if(a[mid]==b):
            print(str(inp[i][0]).zfill(6)+str(mid+1).zfill(6))
            break
        elif(a[mid]<b):
            min=mid+1
        else:
            max=mid-1

Submission status: Accepted

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

Submission status: Accepted

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

class City:
    def __init__(self, i1, p, y, o=None):
        self.i1 = i1
        self.p = p
        self.y = y
        self.o = o

    # def __repr__(self):
    #     return f"City({self.i1}, {self.p}, {self.y}, {self.o})"

    def get_id(self):
        return "%06d%06d" % (self.p, self.o)

def put_ids(n, cities):
    years = {i: [] for i in range(1, n + 1)}
    for c in cities:
        years[c.p].append(c.y)

    year_to_order = {i: {} for i in range(1, n + 1)}
    for i in range(1, n + 1):
        ys = sorted(years[i])
        for j0, y in enumerate(ys):
            year_to_order[i][y] = j0 + 1

    for c in cities:
        c.o = year_to_order[c.p][c.y]

def main():
    n, m = map(int, input().split())
    cities = []
    for i0 in range(m):
        p, y = map(int, input().split())
        city = City(i0, p, y)
        cities.append(city)
    put_ids(n, cities)
    for c in cities:
        print(c.get_id())

main()

Submission status: Accepted

Solution code:
N, M = [int(a) for a in input().strip().split()]
P = []
Y = []
prefs = {}
YtoIdx = {}
results = ['' for i in range(0, M)]
for i in range(0, M):
    pk, yk = [int(a) for a in input().strip().split()]
    if not pk in prefs:
        prefs[pk] = []
    prefs[pk].append(yk)
    P.append(pk)
    Y.append(yk)
    YtoIdx[yk] = i

for p in prefs.keys():
    prefs[p].sort()
    for i, y in enumerate(prefs[p]):
        pre = str(p).zfill(6)
        suf = str(i+1).zfill(6)
        results[YtoIdx[y]] = pre + suf

for res in results:
    print(res)

Submission status: Accepted

Solution code:
# coding:utf-8

import sys
from collections import Counter, defaultdict

INF = float('inf')
MOD = 10 ** 9 + 7

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def II(): return int(sys.stdin.readline())
def SI(): return input()


n, m = LI()
YP = [[y, p] for p, y in (LI() for _ in range(m))]

YP2 = sorted(YP)

P = defaultdict(int)
ans = {}
for y, p in YP2:
    P[p] += 1
    l1, l2 = len(str(p)), len(str(P[p]))
    id = '{:06d}{:06d}'.format(p, P[p])
    ans[y] = id

for y, p in YP:
    print(ans[y])

Submission status: Accepted

Solution code:
from operator import itemgetter
N,M=(int(i) for i in input().split())
data = [[int(i) for i in input().split()] for i in range(M)]

j=0
for i in data:
    i.append(j)
    j=j+1

data.sort(key=itemgetter(1))
data.sort(key=itemgetter(0))

def addzero(n):
    addnum = 6-len(str(n))
    return '0'*addnum+str(n)

pref=0
yearLank=0
for i in data:
    if pref!=i[0]:
        pref=i[0]
        yearLank=1
    i.append(addzero(pref)+addzero(yearLank))
    yearLank = yearLank+1

data.sort(key=itemgetter(2))

for i in data:
    print(i[3])

Submission status: Accepted

Solution code:
N, M = [int(_) for _ in input().split()]
PY = [[int(_) for _ in input().split()] for _ in range(M)]
PYI = sorted([PY[i] + [i] for i in range(M)], key=lambda xs:xs[1])
count_p = {}
ans = [None] * M
for p, y, i in PYI:
    count_p[p] = count_p.get(p, 0) + 1
    ans[i] = [p, count_p[p]]
[print(str(p).zfill(6)+str(x).zfill(6)) for p, x in ans]

Submission status: Accepted

Solution code:
# coding:utf-8

import sys
from collections import Counter, defaultdict

INF = float('inf')
MOD = 10 ** 9 + 7

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def II(): return int(sys.stdin.readline())
def SI(): return input()


n, m = LI()
YP = [[y, p] for p, y in (LI() for _ in range(m))]

YP2 = sorted(YP)

P = defaultdict(int)
ans = {}
for y, p in YP2:
    P[p] += 1
    l1, l2 = len(str(p)), len(str(P[p]))
    id = (6 - l1) * '0' + str(p) + (6 - l2) * '0' + str(P[p])
    ans[y] = id

for y, p in YP:
    print(ans[y])

Submission status: Accepted

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

cs = [[] for i in range(N+1)]
for i,(p,y) in enumerate(src):
    cs[p].append((y,i))
for cc in cs:
    cc.sort()

ans = [None] * M
for p in range(len(cs)):
    for i,(_,j) in enumerate(cs[p]):
        s = str(p).zfill(6) + str(i+1).zfill(6)
        ans[j] = s
print(*ans, sep='\n')

Submission status: Accepted

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

cs = [[] for i in range(N+1)]
for i,(p,y) in enumerate(src):
    cs[p].append((y,i))
for cc in cs:
    cc.sort()

ans = [None] * M
for p in range(len(cs)):
    for i,(_,j) in enumerate(cs[p]):
        s = str(p).zfill(6) + str(i+1).zfill(6)
        ans[j] = s
print(*ans, sep='\n')

Submission status: Accepted

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

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

    pref_sorted = sorted(enumerate(pref), key=lambda x: x[1])

    idx = [1 for _ in range(N)]
    res = ['' for _ in range(M)]
    for j, (p, y) in pref_sorted:
        res[j] = str(p).zfill(6) + str(idx[p - 1]).zfill(6)
        idx[p - 1] += 1
    for r in res:
        print(r)


if __name__ == '__main__':
    main()

Submission status: Accepted

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

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

ans = [None for _ in range(M)]
for p in range(1, N + 1):
    for e, (y, i) in enumerate(sorted(a[p], key=lambda x: x[0]), 1):
        ans[i] = str(p).zfill(6) + str(e).zfill(6)

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

Submission status: Accepted

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

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

ipy.sort(key=lambda x:x[2])
count = {}
order = {}

for i in range(m):
    i, p, y = ipy[i]
    if not p in count:
        count[p] = 0
    count[p] += 1
    order[i, p] = count[p]
    
ipy.sort(key=lambda x: x[0])
    
for i, p, y in ipy:
    print('{:06}{:06}'.format(p, order[i, p]))

Submission status: Accepted

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

for x in range(0,M):
    X = list(map(int,input().split()))
    PY.append((X[0],X[1],x))

sortedPY = sorted(PY, key=lambda x:x[1])
ID = [0 for i in range(N)]

for y in range(0,M):
    n = sortedPY[y][0]
    n = n-1
    ID[n] = ID[n] + 1
    nstr = str(ID[n])
    Pstr = str(sortedPY[y][0])
    while len(nstr) < 6:
        nstr = '0' + nstr
    while len(Pstr) < 6:
        Pstr = '0' + Pstr
    PY[sortedPY[y][2]] = Pstr + nstr
    number = Pstr + nstr

for x in range(0,M):
    print(PY[x])

Submission status: Accepted

Solution code:
import bisect
N,M=map(int,input().split())
A=[[0] for j in range(N)]
px=[]
for i in range(M):
    p,x=map(int,input().split())
    A[p-1].append(x)
    px.append([p,x])
for m in range(N):
    A[m].sort()
for k in range(M):
    q=bisect.bisect_left(A[px[k][0]-1],px[k][1])
    print("0"*(6-len(str(px[k][0])))+str(px[k][0])+"0"*(6-len(str(q)))+str(q))

Submission status: Accepted

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

sortedPY = sorted(PY, key=lambda x:int(x[1]))

Pwas = [0 for i in range(N)]
for i,x in enumerate(sortedPY):
    P = x[0]
    idx = int(P) - 1
    Pwas[idx] = Pwas[idx] + 1
    PY[x[2]] = P.zfill(6) + str(Pwas[idx]).zfill(6)

for x in PY:
    print(x)

Submission status: Accepted

Solution code:
class CityData:
    def __init__(self, cityData):
        splitedData = cityData.split(" ")
        self.pref = int(splitedData[0])
        self.year = int(splitedData[1])

    def setRank(self, rank):
        self.rank = rank


firstLine = input().split(" ")
prefs = int(firstLine[0])
cities = int(firstLine[1])

cityDataArray = []
cityRankState = {}

for i in range(cities):
    inputData = input()
    cityDataArray.append(CityData(inputData))

sortedCityDataArray = sorted(cityDataArray, key=lambda x:x.year)

for i in sortedCityDataArray:
    try:
        rank = cityRankState[i.pref]
    except KeyError:
        rank = 0
    i.setRank(rank)
    rank += 1
    cityRankState[i.pref] = rank

for i in cityDataArray:
    print(str(i.pref).rjust(6, '0') + str(i.rank+1).rjust(6, '0'))

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
"""
Created on Fri Jan  4 20:10:14 2019

@author: Yamazaki Kenichi
"""
import bisect

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

a = [[] for i in range(N)]
for j in range(M):
    a[C[j][0]-1].append(C[j][1])

for i in range(N):
    a[i].sort()

ans = []
for j in range(M):
    l = '0'*(6-len(str(C[j][0])))+str(C[j][0])
    r1 = bisect.bisect_left(a[C[j][0]-1],(C[j][1]))+1
    r = '0'*(6-len(str(r1)))+str(str(r1))
    ans = l + r 
    print(ans)

Submission status: Accepted

Solution code:
N,M = [int(s) for s in input().split()]
data = [[0 for i in range(4)] for j in range(M)]

for i in range(M):
    l = [int(s) for s in input().split()]
    data[i][0],data[i][1] = l[0],l[1]
    data[i][2] = i+1
data.sort()

seq = 1
for i in range(M):
    if i == 0:
        data[0][3] =str(data[0][0]).zfill(6) + "000001"
        seq += 1
    elif data[i][0] == data[i-1][0]:
        data[i][3] = str(data[i][0]).zfill(6) + str(seq).zfill(6)
        seq += 1
    else:
        seq = 1
        data[i][3] = str(data[i][0]).zfill(6) + "000001"
        seq += 1

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

Submission status: Accepted

Solution code:
#C
def zeros(n): return [0 for i in range(n)]

N, M = [int(x) for x in input().split()]
city = []
for i in range(M):  
    pref, year = [int(x) for x in input().split()]
    city.append([pref, year, i, ''])

#print(N, M) #
#print(city) #
city.sort()
#print(city) #

nth = zeros(N+1)
for i in range(M):
    pref, year, seq, id = [x for x in city[i]]
    nth[pref] += 1
    city[i][3] = '%06d%06d' % (pref, nth[pref])
    city[i][0] = city[i][2] # seqを最初に
    #for j in range(4): print(city[i][j],end=',') #
    
city.sort()
for i in range(M): print(city[i][3])

Submission status: Accepted

Solution code:
def pad(n):
  s = str(n)
  while len(s) < 6:
    s = '0' + s
  return s

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

ans = [''] * (M+1)

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

pn = [0] * (N+1)

for y, p, i in ds:
  pn[p] += 1
  ans[i] = pad(p) + pad(pn[p])
print("\n".join(ans))