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())
citys = [list(map(int,input().split())) for _ in range(M)]
for i in range(M):
    citys[i].append(i)
citys.sort()
ppref = 0
city_code = 0
for city in citys:
    if ppref == city[0]:
        city_code += 1
    else:
        ppref = city[0]
        city_code = 1
    str_pref = str(city[0]).zfill(6)
    str_city = str(city_code).zfill(6)
    city.append(str_pref+str_city)

for city in sorted(citys, key=lambda x:x[2]):
    print(city[3])

Submission status: Accepted

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

N,M = map(int, input().split())
P = [0]*M
Y = [0]*M
for i in range(M):
	P[i],Y[i] = map(int, input().split())
 
p_dict = {} #dictionalyの初期化
for i in range(M):
	p_dict.setdefault(P[i],[]).append(Y[i])


under6 = {} #dictionalyの初期化
for p in p_dict.keys():
  sorted_year = sorted(p_dict[p])
  for i in range(len(sorted_year)):
    under6[sorted_year[i]] = i + 1

for i in range(M):
  print(str(P[i]).zfill(6) + str(under6[Y[i]]).zfill(6))

Submission status: Accepted

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

p_dict = {}
for i in range(M):
  p_dict.setdefault(P[i],[]).append(Y[i])
under6 = {}
for p in p_dict.keys():
  sorted_year = sorted(p_dict[p])
  for i in range(len(sorted_year)):
    under6[sorted_year[i]] = i + 1

for i in range(M):
  print(str(P[i]).zfill(6) + str(under6[Y[i]]).zfill(6))

Submission status: Accepted

Solution code:
n, m = map(int, input().split())
dp = [[] for i in range(n)]
for i in range(m):
    p, y = map(int, input().split())
    dp[p - 1].append([i, y])
for i, p in enumerate(dp):
    p = sorted(p, key=lambda x : x[1])
    dp[i] = p
ans = []
for i, p in enumerate(dp):
    for j, a in enumerate(p):
        s = '{:06}'.format(i + 1) + '{:06}'.format(j + 1)
        ans.append([a[0], s])
ans = sorted(ans)
for i, s in ans:
    print(s)

Submission status: Accepted

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

for i in range(M):
    tmp = []
    tmp = list(map(int,input().split()))
    tmp.append(i)
    L.append(tmp)

LL = sorted(L)
num = []

for i in range(len(LL)):
    if i == 0:
        cnt = 1
    else:
        if (LL[i][0] == LL[i-1][0]):
            cnt += 1
        else:
            cnt = 1
    id.append(LL[i][2])
    num.append(str(LL[i][0]).zfill(6) + str(cnt).zfill(6))

numnum = [x for _ , x in sorted(zip(id,num))]

for x in numnum:
    print(x)

Submission status: Accepted

Solution code:
n,m=map(int,input().split())
P=[]
for i in range(m):
    p,y=map(int, input().split())
    P.append([p,y,i])
nums=[0]*n
ans=[""]*m
P.sort(key=lambda x:x[1])

for p,y,i in P:
    nums[p-1]+=1
    ans[i]=(6-len(str(p)))*"0"+str(p)+(6-len(str(nums[p-1])))*"0"+str(nums[p-1])
for an in ans:
    print(an)

Submission status: Accepted

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

def main():
    ps = [[] for _ in range(N)]

    for m in range(M):
        p, y = [int(n) for n in input().split()]
        pref = ps[p - 1]
        pref.append([m, y])

    result = []

    for i, pref in enumerate(ps):
        pref.sort(key=lambda p: p[1])
        for j, p in enumerate(pref):
            result.append([p[0], '{:06}{:06}'.format(i + 1, j + 1)])

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

    ans = '\n'.join(map(lambda p: p[1], result))
    print(ans)

if __name__ == '__main__':
    main()

Submission status: Accepted

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

N,M = inpl()
li = [inpl()+[i] for i in range(M)]
li = sorted(li, key=lambda x: x[1])
ans = [0]*M
cnts = defaultdict(int)
for i in range(M):
    p,y,ind = li[i]
    s1 = str(p).zfill(6)
    s2 = str(cnts[p]+1).zfill(6)
    cnts[p] += 1
    ans[ind] = s1+s2

for a in ans:
    print(a)

Submission status: Accepted

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

for i in range(M) : 
    tmp = []
    tmp = list(map(int, input().split()))
    tmp.append(i)
    L.append(tmp)
    
LL = sorted(L)
num = []

for i in range(len(LL)) : 
    if i == 0 : 
        cnt = 1

    else : 
        if(LL[i][0] == LL[i-1][0]) : 
            cnt += 1
        else : 
            cnt = 1
        
    id.append(LL[i][2])
    num.append(str(LL[i][0]).zfill(6) + str(cnt).zfill(6))

numnum = [x for _,x in sorted(zip(id, num))] #このコード, なんでちゃんとidが消えて, numだけが残ってるんや? →　i, j for i, j in ～～～ となっていて, iの部分を捨てている感じ

for x in numnum : 
    print(x)

Submission status: Accepted

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

for i in range(M) : 
    tmp = []
    tmp = list(map(int, input().split()))
    tmp.append(i)
    L.append(tmp)
    
LL = sorted(L)
num = []

for i in range(len(LL)) : 
    if i == 0 : 
        cnt = 1

    else : 
        if(LL[i][0] == LL[i-1][0]) : 
            cnt += 1
        else : 
            cnt = 1
        
    id.append(LL[i][2])
    num.append(str(LL[i][0]).zfill(6) + str(cnt).zfill(6))

numnum = [x for _ , x in sorted(zip(id, num))]

for x in numnum : 
    print(x)

Submission status: Accepted

Solution code:
n,m = map(int,input().split())
P = [list(map(int,input().split()))+[0,i] for i in range(m)]
P.sort(key = lambda x:x[1])
city = {}
for p in P:
    if p[0] in city:
        city[p[0]] += 1
    else:
        city[p[0]] = 1
    p[2] = city[p[0]]
P.sort(key = lambda x:x[3])
for p in P:
    print(str(p[0]).zfill(6)+str(p[2]).zfill(6))

Submission status: Accepted

Solution code:
N,M=[int(a) for a in input().split(" ")]
PY = [[int(a) for a in input().split(" ")] for i in range(M)]
from collections import defaultdict
dic = defaultdict(list)
for i, (p, y) in enumerate(PY):
    dic[p].append((i, y))
ans = []
fill6 = lambda s:(6-len(s))*"0"+s
for p, arr in dic.items():
    s = fill6(str(p))
    arr = sorted(arr, key=lambda t: t[1])
    ans += [(j, s+fill6(str(i+1))) for i, (j, _) in enumerate(arr)]
for j, idx in sorted(ans, key=lambda t:t[0]):
    print(idx)

Submission status: Accepted

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

lst = []
for i in range(M):
    a = list(map(int, input().split()))
    a += [i] #i: 市の番号
    lst += [a]
#print (lst)
lst.sort()
#print (lst)

ken = -1
x = 0
ans = []
for j in range(M):
    if ken != lst[j][0]: #1つ前と市の名前が違う
        x = 1 #
        ken = lst[j][0]
#        P = '{:0>6}'.format(ken)
        #print ('A')
    else: #1つ前と市の名前が同じ
        x += 1
        #print ('B')
#    X = '{:0>6}'.format(x)
    ans += [[lst[j][2], ken, x]]

ans.sort()
#print (ans)
for k in range(M):
    P = '{:0>6}'.format(ans[k][1])
    X = '{:0>6}'.format(ans[k][2])
    print (P+X)

Submission status: Accepted

Solution code:
import sys
from collections import defaultdict
from copy import deepcopy

input = sys.stdin.readline
N, M = list(map(int, input().split()))

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

sorted_PY = deepcopy(PY)
sorted_PY.sort(key=lambda x: x[1])

p_count_dict = defaultdict(lambda: 0)
y_dict = {}

for py in sorted_PY:
    p_count_dict[py[0]] += 1
    y_dict[py[1]] = p_count_dict[py[0]]

for py in PY:
    # print(f'{py[0]:0>6}{y_dict[py[1]]:0>6}')
    print('{}{}'.format(str(py[0]).zfill(6), str(y_dict[py[1]]).zfill(6)))

Submission status: Accepted

Solution code:
import heapq

N, M = [int(i) for i in input().split()]
heaps = [[] for _ in range(N + 1)]
cities = [None] * (M+1)
for m in range(M):
    p, y = [int(i) for i in input().split()]
    heapq.heappush(heaps[p], (y, p, m))

for heap in heaps:
    id = 0
    while len(heap) > 0:
        id += 1
        y, p, m = heapq.heappop(heap)
        cities[m] = "{:06d}{:06d}".format(p, id)

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

Submission status: Accepted

Solution code:
N, M = map(int,input().split())
L = []
for i in range(M):
    p, y = map(int,input().split())
    L.append((p,y,i))
PY = sorted(L)
from collections import defaultdict
d = defaultdict(int)
ID = [None]*M
for p,y,i in PY:
    d[p] += 1
    ID[i] = d[p]
for i in range(M):
    p,y,j = L[i]
    print("{:06}{:06}".format(p, ID[i]))

Submission status: Accepted

Solution code:
N, M = list(map(int, input().split()))
temp = [list(map(int, input().split())) for i in range(M)]
temp = list(zip(*temp))
P, Y = temp
#print(P, Y)
data = dict()
for p, y in zip(P, Y):
  if p not in data:
    data[p] = [y]
  else:
    data[p].append(y)

data = {i:{value:j+1 for j, value in enumerate(sorted(data[i]))} for i in data.keys()}

for p, y in zip(P, Y):
  print("{:06}{:06}".format(p, data[p][y]))

Submission status: Accepted

Solution code:


#!/usr/bin/env python3

from collections import Counter

N, M = map(int, input().split())
PY = [ (i, P, Y) for i, (P, Y) in enumerate([map(int, input().split()) for _ in range(M)])]

answers = [0 for x in range(M)]
counter = Counter()

for index, P, Y in sorted(PY, key = lambda x : x[2]):
    counter[P] += 1
    answers[index] = "{:06}{:06}".format(P, counter[P])

print("\n".join(answers))

Submission status: Accepted

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

from itertools import chain
from collections import Counter

N,M = map(int, input().split())
PY = [ (i, P, Y) for i, (P, Y) in enumerate([map(int, input().split()) for _ in range(M)])]

answers = [0 for x in range(M)]
counter = Counter()

for index, P, Y in sorted(PY, key = lambda x : x[2]):
    counter[P] += 1
    answers[index] = "{:06}{:06}".format(P, counter[P])

print("\n".join(answers))

Submission status: Accepted

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

from itertools import chain
from collections import Counter

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

answers = [0 for x in range(M)]
counter = Counter()

for index, P, Y in sorted(PY, key = lambda x : x[2]):
    counter[P] += 1
    answers[index] = "{:06}{:06}".format(P, counter[P])

print("\n".join(answers))

Submission status: Accepted

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

d = {}
for i in range(M):
    p,y = map(int,input().split())
    if p in d.keys():
        d[p].append([p,y,i])
    else:
        d[p] = [[p,y,i]]

ans = []
for k in d.keys():
    d[k] = sorted(d[k],key=lambda x:x[1])
    for i,d_ in enumerate(d[k]):
        d_.append(i+1)
    ans += d[k]

ans = sorted(ans,key=lambda x:x[2])
for a in ans:
    print(str(a[0]).zfill(6)+str(a[3]).zfill(6))

Submission status: Accepted

Solution code:
import math
N,M = list(map(int,input().split(" ")))
towns = {}
ans = [0] * M
for i in range(M):
    temp = list(map(int,input().split(" ")))
    num = temp[0]
    year = temp[1]
    if num not in towns:
        towns[num] = [(year,i)]
    else:
        towns[num].append((year,i))

# print(towns)
for k,v in towns.items():
    # print("key:",k)
    i1 = str(k).zfill(6)
    v_sorted = sorted(v,key = lambda x:x[0])
    # print("v:",v_sorted)
    for i,town in enumerate(v_sorted):
        # print("town:",town)
        i2 = str(i+1).zfill(6)
        # print(i1 + i2)
        ind = town[1]
        ans[ind] = i1 + i2
# print("ans","---"*20)
for a in ans:
    print(a)

Submission status: Accepted

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

n, m = map(int, input().split())
l = [list(map(int, input().split())) for _ in range(m)]

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

for v in l:
    ll[v[0] - 1].append(v[1])
    
for i in range(len(ll)):
    ll[i].sort()
    
for v in l:
    index = bisect.bisect_right(ll[v[0] - 1], v[1])
    print("{:0=6}{:0=6}".format(v[0], index))

Submission status: Accepted

Solution code:
n,m=map(int,input().split())
city={}
year=[]
for i in range(m):
    p,y=map(int,input().split())
    city[y]=p
    year.append(y)
city=sorted(city.items())
answer={}
count=[]
for i in range(n):
    count.append(1)
for i in city:
    f=str(i[1]).zfill(6)
    l=str(count[i[1]-1]).zfill(6)
    count[i[1]-1]=count[i[1]-1]+1
    answer[i[0]]=f+l
for i in year:
    print(answer[i])

Submission status: Accepted

Solution code:
import sys
from collections import defaultdict
from operator import itemgetter

input = sys.stdin.readline

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

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

ans = [None] * M
for k, v in A.items():
    v.sort(key=itemgetter(0))
    for i in range(len(v)):
        _, j = v[i]
        c1 = str(k).zfill(6)
        c2 = str(i + 1).zfill(6)
        ans[j] = c1 + c2
print('\n'.join(ans))

Submission status: Accepted

Solution code:
# coding : UTF-8
import bisect
N,M = map(int,input().split())

PM_list = [ input() for _ in range(M) ]
PM_list = [ list(map(int,_.split(" "))) for _ in PM_list]
PM_dict = {}

for i in PM_list:
    if i[0] in PM_dict:
        PM_dict[i[0]].append(i[1])
    else:
        PM_dict[i[0]] = [i[1]]

for j in PM_dict:
    PM_dict[j].sort()

for k in PM_list:
    print("{}{}".format(str(k[0]).zfill(6),str(bisect.bisect_left(PM_dict[k[0]],k[1])+1).zfill(6)))

Submission status: Accepted

Solution code:
n,m=[int(i) for i in input().split()]
id=[[int(i) for i in input().split()]+[j] for j in range(m)]

pre_num=[0]*(n+1)
ans=[""]*m

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

for p, y, i in id:
    pre_num[p] += 1
    ans[i] = str(p).zfill(6) + str(pre_num[p]).zfill(6)

print("\n".join(ans))

Submission status: Accepted

Solution code:
n,m=[int(i) for i in input().split()]
id=[[int(i) for i in input().split()]+[j] for j in range(m)]

pre_num=[0]*(n+1)
ans=[""]*m

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

for p,y,i in id:
    pre_num[p]+=1
    ans[i]=str(p).zfill(6)+str(pre_num[p]).zfill(6)

print("\n".join(ans))

Submission status: Accepted

Solution code:
# coding: utf-8

N, M = map(int, input().split())
p_dict = {}
for i in range(M):
    p, y = map(int, input().split())
    if p not in p_dict.keys():
        p_dict[p] = [[y, p, i]]
    else:
        # yとp元の順番を入れとく
        p_dict[p].append([y, p, i])
ans = []
for p in p_dict.keys():
    p_dict[p].sort()
    for i in range(len(p_dict[p])):
        # 昇順で並べたときの順番を入れとく
        p_dict[p][i].append(i+1)
        ans.append(p_dict[p][i])
# ans = [y, p, input_index, sorted_index]
ans.sort(key=lambda x: x[2])
for y, p, oi, si in ans:
    print("{:06d}{:06d}".format(p, si))

Submission status: Accepted

Solution code:
#coding: utf-8
from copy import deepcopy


def main():
    N, M = map(int, input().split())
    p_dict = {}
    for i in range(M):
        p, y = map(int, input().split())
        if p not in p_dict.keys():
            p_dict[p] = [[y, p, i]]
        else:
            #yとp元の順番を入れとく
            p_dict[p].append([y, p, i])
    ans = []
    for p in p_dict.keys():
        p_dict[p].sort()
        for i in range(len(p_dict[p])):
            #昇順で並べたときの順番を入れとく
            p_dict[p][i].append(i+1)
            ans.append(p_dict[p][i])
    #ans = [y, p, input_index, sorted_index]
    ans.sort(key=lambda x: x[2])
    for y, p, oi, si in ans:
        print("{:06d}{:06d}".format(p, si))
if __name__ == "__main__":
    main()

Submission status: Accepted

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

prefs_list = []
prefs_dict = {}
for i in range(m):
  p, y = map(int, input().split())
  prefs_list.append([p,y])
  if p in prefs_dict:
    prefs_dict[p].append(y)
  else:
    prefs_dict[p] = [y]

for key in prefs_dict:
  prefs_dict[key].sort()



for pref in prefs_list:
  print(str(pref[0]).zfill(6) + str(bisect.bisect_left(prefs_dict[pref[0]], pref[1])+1).zfill(6))

Submission status: Accepted

Solution code:
# AtCoder Beginner Contest 113-C
if __name__ == "__main__":
    N, M = map(int, input().split())
    city_list = []
    for i in range(M):
        city_list.append(list(map(int, input().split())))
    pref = {}
    pref_sort = {}
    for i in range(M):
        key = city_list[i][0]
        val = city_list[i][1]
        if str(key) in pref:
            pref[str(key)].append(val)
        else:
            pref[str(key)] = [val]
    ans = {}
    for key, val in pref.items():
        val.sort()
        for i in range(len(val)):
            ans[(key, val[i])] = str(key).zfill(6) + str(i+1).zfill(6)
    for key, val in city_list:
        print(ans[str(key), val])

Submission status: Accepted

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

for i,l in enumerate(list):
    list_pre[l[0]-1].append([l[1],i])

ans = []

for i,l in enumerate(list_pre):
    l.sort()
    for j,l2 in enumerate(l):
        ans.append([i+1,j+1,l2[1]])

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

for l in ans:
    print('%06d%06d' % (l[0],l[1]))

Submission status: Accepted

Solution code:
nm = input().split()
n = int(nm[0])
m = int(nm[1])
pylist = [input().split() for _ in range(m)]
yplist = [(int(py[1]), int(py[0]), i) for i, py in enumerate(pylist)]
yplist.sort()
city_counts = {}

anslist = {}

for y, p, i in yplist:
    if p not in city_counts:
        city_counts[p] = 0
    city_counts[p] += 1
    anslist[i] = '%06d%06d' % (p, city_counts[p])


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

Submission status: Accepted

Solution code:
def set_format(name: int):
    """6桁に揃える"""
    formated_name = "{:0=6}".format(name)
    return formated_name

def main():
    N, M = [int(c) for c in input().split()]
    lists = []
    for i in range(M):
        city = i
        prefecture, year = [int(c) for c in input().split()]
        id_ = ""
        lists.append([city, prefecture, year, id_])

    prefectures = [0] * (N + 1)

    #年のソート
    lists.sort(key=lambda x: x[2])

    for i in range(M):
        # 県名
        prefecture_name = lists[i][1]
        lists[i][3] = set_format(prefecture_name) + set_format(prefectures[prefecture_name] + 1)
        prefectures[prefecture_name] += 1

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

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

if __name__ =='__main__':
    main()

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
import sys
from math import *
from itertools import *
from collections import *
from functools import *
try:
    from math import gcd
except Exception:
    from fractions import gcd


def solve(N: int, M: int, P: "List[int]", Y: "List[int]"):
    d = {}
    for i, (p, y) in enumerate(zip(P, Y)):
        d.setdefault(p, []).append((y, i))

    r = []
    for p, vs in d.items():
        r += [(n, "{:06}{:06}".format(p, i+1)) for i, (_, n) in enumerate(sorted(vs))]
    r.sort()

    return '\n'.join([c for _, c in r])


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))
    result = solve(N, M, P, Y)
    print(result)

if __name__ == '__main__':
    main()

Submission status: Accepted

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

city = sorted(city, key=lambda x: x[2])
d = defaultdict(int)
for i in range(m):
    d[city[i][1]] += 1
    city[i][3] = d[city[i][1]]
for _, p, _, x in sorted(city, key=lambda x:x[0]):
    print('%06d%06d' % (p, x))

Submission status: Accepted

Solution code:
import numpy as np
import copy
from operator import itemgetter

n,m=map(int,input().split())
l=[0]*m
for i in range(m):
    p,y=map(int,input().split())
    l[i]=[p*10**10+y,i,0]#p,y,index,code
buf=sorted(l,key=lambda x:x[0])
id=10**10
counter=1
#print(buf)
for i in range(m):
    #print(id)
    if id!=buf[i][0]//(10**10):
        id=buf[i][0]//(10**10)
        counter=1
    else:
        counter+=1
    buf[i][2]=id*10**6+counter
l=sorted(l,key=lambda x:x[1])
for i in range(m):
    print(str(0)*(12-len(str(l[i][2])))+str(l[i][2]))

Submission status: Accepted

Solution code:
import sys
_ = input()
PY = sorted([list(map(int, line.strip().split(' ')))+[i] for i,line in enumerate(sys.stdin)])
now_p = None
now_id = 0
for i in range(len(PY)):
  p,y,_ = PY[i]
  if now_p != p:
    now_p = p
    now_id = 1
  else:
    now_id += 1
  PY[i][1] = now_id
for p,id,i in sorted(PY, key=lambda x: x[2]):
  print('{:0>6}{:0>6}'.format(p,id))

Submission status: Accepted

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

class City():
    def __init__(self, idx, prefecture, year):
        self.idx = idx
        self.prefecture = prefecture
        self.year = year

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

    @property
    def id(self):
        return "{0:0>6}{1:0>6}".format(self.prefecture, self.rank)

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

rank_list = [1 for _ in range(N+1)]
for city in sorted(city_list, key=lambda city: city.year):
    prefecture = city.prefecture
    city.set_rank(rank_list[prefecture])
    rank_list[prefecture] += 1

for city in city_list:
    print(city.id)

Submission status: Accepted

Solution code:
#!/usr/bin/env python
N, M = map(int, input().split())
X = []
for m in range(M):
    p, y = map(int, input().split())
    X.append([m, p, y])

X_sort = sorted(X, key=lambda x:(x[1], x[2]))

c = 1
X_sort[0].append(str(X_sort[0][1]).zfill(6) + str(1).zfill(6))
for i,x in enumerate(X_sort[1:]):
    if x[1] == X_sort[i][1]:
        c += 1
        x.append(str(x[1]).zfill(6) + str(c).zfill(6))
    else:
        x.append(str(x[1]).zfill(6) + str(1).zfill(6))
        c = 1

Y = sorted(X_sort, key=lambda x:x[0])
for y in Y:
    print(y[3])

Submission status: Accepted

Solution code:
n, m = map(int, input().split())
cs = []
cd = {}
ps = {}
for _ in range(m):
  p, y = map(int, input().split())
  cs.append([p, y])
  if p in ps:
    ps[p].append(y)
  else:
    ps[p] = [y]
    
for p in ps:
  v = sorted(ps[p])
  for i, y in enumerate(v):
    cd[y] = i + 1
[print('{:06}{:06}'.format(c[0], cd[c[1]])) for c in cs]

Submission status: Accepted

Solution code:
N, M = map(int, input().split())
citys =[list(map(int, input().split())) for i in range(M)]
cs = {}
ans = {}
for p, y in citys:
    if p in cs:
        cs[p].append(y)
    else:
        cs[p] = [y]
for p, v in cs.items():
    v.sort()
    for i in range(len(v)):
        ans[(p, v[i])] = '0'*(6-len(str(p)))+str(p) + '0'*(6-len(str(i+1))) +str(i+1)
for p, y in citys:
    print(ans[(p, y)])

Submission status: Accepted

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

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

X.sort(key=lambda x: (x[1], x[2]))

XX = []
p = None
n = 0
for x in X:
    if x[1] != p:
        p = x[1]
        n = 1
    else:
        n += 1
    XX.append(x + (n,))

XX.sort(key=lambda xx: xx[0])

for xx in XX:
    print("{:06}{:06}".format(xx[1], xx[3]))

Submission status: Accepted

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

n = 1
p = 0
ans = []
for city in sorted(cities, key = lambda x:(x[1],x[2])):
  if p != city[1]:
    n = 1
    p = city[1] 
  ans.append((city[0], city[1], n))
  n += 1

ans = sorted(ans)

for x in ans:
  print('{:06}{:06}'.format(x[1],x[2]))

Submission status: Accepted

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

# input順,県P,Y年,P内通し番号
city_list=[]
for i in range(m):
    p,y=map(int,input().split())
    city_list.append([i,p,y])

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

city=city_list[0][1]
count=0
for i in range(m):
    if city == city_list[i][1]:
        count+=1
    else:
        city = city_list[i][1]
        count=1
    city_list[i].append(count)

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

for id in city_list:
    print(str(id[1]).zfill(6) + str(id[3]).zfill(6))

Submission status: Accepted

Solution code:
import sys
import bisect
input = sys.stdin.readline
N, M = map(int, input().split())
p_list = [[] for _ in [0]*(N+1)]
q_list = []
for _ in [0]*M:
    p,y = map(int, input().split())
    q_list.append((p,y))
    p_list[p].append(y)
p_list = [sorted(y_list) for y_list in p_list]
for p,y in q_list:
    x = bisect.bisect_left(p_list[p],y)
    ans = "%06d%06d"%(p,x+1)
    print(ans)

Submission status: Accepted

Solution code:
n,m = map(int,input().split())
p,y = [],[]
for i in range(m):
    v1,v2 = map(int,input().split())
    p.append(v1)
    y.append(v2)
    
py = zip(p,y,range(m))
py = sorted(py)
p,y,index = zip(*py)
 
ans = []
start = p[0]
count = 1
for i in range(m):
    if start == p[i]:
        ans.append(str(p[i]).zfill(6) + str(count).zfill(6))
        count += 1
    else:
        count = 1
        start = p[i]
        ans.append(str(p[i]).zfill(6) + str(count).zfill(6))
        count += 1
 
ans = zip(index,ans)
ans = sorted(ans)
index,ans = zip(*ans)
for i in ans:
    print(i)

Submission status: Accepted

Solution code:
def main():
  N,M = map(int, input().split())
  # PY = [list(map(int, input().split())) for _ in range(M)]
  PY = []
  for _ in range(M):
    PY.append(list(map(int,input().split())))  
  id = 1
  for row in PY:
    row.append(id)
    id += 1
  #print(PY)
  PY.sort(key = lambda x: (x[0], x[1]))
  #print(PY)

  tempP = 0
  for row in PY:
    if row[0] != tempP: 
      id = 1
    row.append(id)
    id += 1
    tempP = row[0]
  #print(PY)
  PY.sort(key = lambda x: x[2])
  #print(PY)

  for row in PY:
    print('{:0>6}{:0>6}'.format(row[0],row[3]))
  
main()

Submission status: Accepted

Solution code:
n,m = map(int,input().split())
p,y = [],[]
for i in range(m):
    v1,v2 = map(int,input().split())
    p.append(v1)
    y.append(v2)
    
py = zip(p,y,range(m))
py = sorted(py)
p,y,index = zip(*py)

ans = []
start = p[0]
count = 1
for i in range(m):
    if start == p[i]:
        ans.append(str(p[i]).zfill(6) + str(count).zfill(6))
        count += 1
    else:
        count = 1
        start = p[i]
        ans.append(str(p[i]).zfill(6) + str(count).zfill(6))
        count += 1

ans1 = zip(index,ans)
ans1 = sorted(ans1)
index,ans = zip(*ans1)
for i in ans:
    print(i)

Submission status: Accepted

Solution code:
N,M=map(int,input().split())
A=[]  
B=[]
for i in range(M) :
  L=list(map(int,input().split()))
  A.append(L)
  B.append(L)
B.sort()
P=1
Q=1
for m in range(M):
  if B[m][0]==P :
    B[m].append(Q)
  else :
    Q=1
    B[m].append(Q)
  P=B[m][0]
  Q+=1
for i in A :
  X=str(i[0])
  Y=str(i[2])
  print("0"*(6-len(X))+X+"0"*(6-len(Y))+Y)

Submission status: Accepted

Solution code:
from operator import itemgetter
import sys
input = sys.stdin.readline

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

l.sort(key=itemgetter(1, 2))
res = []
idx, pre_p, y = l[0]
count = 1
res.append([idx, str(pre_p).zfill(6) + str(count).zfill(6)])
for idx, p, y in l[1:]:
    if pre_p == p:
        count += 1
    else:
        count = 1
    
    res.append([idx, str(p).zfill(6) + str(count).zfill(6)])
    pre_p = p

res.sort(key=itemgetter(0))
for idx, n in res:
    print(n)

Submission status: Accepted

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

PY = [tuple([i] + list(map(int,input().split(' ')))) for i in range(1,M+1)]
sorted1_PY = sorted(PY,key=lambda x:(x[1],x[2]))


prefecture = None
number = 1
sorted2_PY = []
for b,c,d in sorted1_PY:
  if  c!= prefecture:
    number = 1
    sorted2_PY.append((number,b,c,d))
    prefecture = c
  else:
    number += 1
    sorted2_PY.append((number,b,c,d))
    prefecrure = c

sorted3_PY = sorted(sorted2_PY,key=lambda x:x[1])

for a,b,c,d in sorted3_PY:
  prefecture = c
  number =  a
  print((str(c).rjust(6, '0') + (str(a).rjust(6, '0'))))

Submission status: Accepted

Solution code:
from collections import*
import sys
input=sys.stdin.readline

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

for k,v in d.items():
    d[k]=list(enumerate(sorted(v)))
d2=defaultdict(int)
for k,v in d.items():
    for s,t in v:
        d2[(k,t)]=s+1
for i in l:
    print(str(i[0]).zfill(6)+str(d2[tuple(i)]).zfill(6))

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(key=lambda x:(x[0], x[1]))
#print(PY)

b = 0
c = []
pre = -1
for i in range(M):
  if PY[i][0] != pre:
    b = 0
  pre = PY[i][0]
  b += 1
  c.append([PY[i][2], "{0}{1}".format(str(PY[i][0]).zfill(6), str(b).zfill(6))])
#print(c)

c.sort(key=lambda x:(x[0]))
for i in range(M):
  print(c[i][1])

Submission status: Accepted

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

P_years = {}

for i in range(1,M+1):
    P,Y = map(int, input().split())
    Pi.append(P)
    Yi.append(Y)
    if P not in P_years.keys():
        P_years[P] = [(i,Y)]
    else:
        P_years[P].append((i,Y))

cities_order = [-1]*(M+1)
for k in P_years.keys():
    cities = sorted(P_years[k], key=lambda x: x[1])
    for j, city in enumerate(cities):
        cities_order[city[0]] = j+1

for j, p in enumerate(Pi):
    print("{:06}{:06}".format(p, cities_order[j+1]))

Submission status: Accepted

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

py = [list(map(int, input().split())) + [i] for i in range(m)]
py.sort(key=lambda x: x[1])

results = []
for p, y, i in py:
    x = cnt.get(p, 0) + 1
    results.append(("{:06d}{:06d}".format(p, x), i))
    cnt[p] = x
results.sort(key=lambda x: x[1])
for ans, _ in results:
    print(ans)