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())
ipy = []

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

count = {}
order = {}

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

Submission status: Accepted

Solution code:
import bisect
n, m = map(int, input().split())
p = []
y = []
py = []
categorized = [[] for i in range(n+1)]
for i in range(m):
    tmpp, tmpy = map(int, input().split())
    p.append(tmpp)
    y.append(tmpy)
    categorized[tmpp].append(tmpy)

for c in categorized:
    c.sort()
for i in range(m):
    order = bisect.bisect(categorized[p[i]], y[i])
    print('%06d%06d' % (p[i], order))

Submission status: Accepted

Solution code:
from operator import attrgetter

class City:
    def __init__(self, index, p, year):
        self.index = index
        self.p = p
        self.year = year
        self.rank = 0

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

city_list.sort(key=attrgetter('p', 'year'))

p = 1
rank = 0
for i in range(m):
    if city_list[i].p != p:
        p = city_list[i].p
        rank = 1
    else:
        rank += 1
    city_list[i].rank = rank

city_list.sort(key=attrgetter('index'))

for city in city_list:
    print('{0:0>6}{1:0>6}'.format(city.p, city.rank))

Submission status: Accepted

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

# print(data)
sortdata = sorted(data, key=lambda data:data[1])
# print(sortdata)

cnt = 1
sortdata[0].append(1)
for i in range(1,M):
    if sortdata[i][1][0] == sortdata[i-1][1][0]:
        cnt += 1
    else:
        cnt = 1
    sortdata[i].append(cnt)

sortdata = sorted(sortdata, key=lambda data:data[0])
for i in range(M):
    print(str(sortdata[i][1][0]).rjust(6,'0'),end = "")
    print(str(sortdata[i][2]).rjust(6,'0'))

Submission status: Accepted

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

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])
 
city_count = {}
order = {}
 
for i, p, y in sorted(iPY, key=lambda x: x[2]):
    if not p in city_count:
        city_count[p] = 0
    city_count[p] += 1
    order[p, i] = city_count[p]
    
for i, p, y in iPY:
    print('{:06}{:06}'.format(p, order[p, i]))

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([p, y, i])
city.sort()

out = [0]*M
cnt = 1
for i in range(len(city)):
	out[city[i][2]] = '{0:06d}{1:06d}'.format(city[i][0], cnt)
	try:
		if city[i+1][0] == city[i][0]: cnt += 1
		else: cnt = 1
	except(IndexError):
		cnt += 1

for o in out:
	print(o)

Submission status: Accepted

Solution code:
N,M = map(int,input().split())
l_input = []
for i in range(M):
    l_input.append(list(map(int,input().split())))
l_sorted = sorted(l_input,key=lambda x: x[1])
nids = dict()
cities = dict()
l_out = []
for s in l_sorted:
    ni = nids.get(s[0], 0)
    ni += 1
    cities[s[1]] = ni
    nids[s[0]] = ni

for c in l_input:
    print('{0:06}{1:06}'.format(c[0], cities[c[1]]))

Submission status: Accepted

Solution code:
n, m = map(int, input().split())
li_input = list()
counter = dict()
cities = dict()

for i in range(m):
    li_input.append(list(map(int, input().split())))

sorted_city = sorted(li_input, key=lambda x: x[1])

for c in sorted_city:
    idx = counter.get(c[0], 0)
    cities[c[1]] = idx

    # count up
    counter[c[0]] = idx + 1


for c in li_input:
    print('{0:06}{1:06}'.format(c[0], cities[c[1]] + 1))

Submission status: Accepted

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

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

cnt = [0] * n
for v in ipyo:
    p = v[1]
    cnt[p - 1] += 1
    v[3] = cnt[p - 1]

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

for v in ipyo:
    print('{0:06d}'.format(v[1]) + '{0:06d}'.format(v[3]))

Submission status: Accepted

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


PY.sort()
Ans={i:0 for i in range(M)}
counter=0

for i in range(M):
    if i==0:
        counter+=1
    elif PY[i][0]==PY[i-1][0]:
        counter+=1
    else:
        counter=1
    Ans[PY[i][2]]=str(PY[i][0]).zfill(6)+str(counter).zfill(6)
    
for i in range(M):
    print Ans[i]

Submission status: Accepted

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

def FillZero(num,f=6):
    s = ""
    s += (f - len(str(num))) * "0"
    s += str(num)
    return(s)

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

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

key0 = l[0][0]
key1 = 0
for i in range(M):
    if key0 == l[i][0]:
        key1 += 1
        l[i][1] = key1
    else:
        key1 = 1
        l[i][1] = key1
        key0 = l[i][0]

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

for i in range(M):
    print(FillZero(l[i][0]) + FillZero(l[i][1]))

Submission status: Accepted

Solution code:
from collections import defaultdict


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

    res = []
    for p in cs.keys():
        cs[p].sort()
        for j, (y, i) in enumerate(sorted(cs[p])):
            res.append((i, "{:06d}{:06d}".format(p, j + 1)))

    for t in sorted(res):
        print(t[1])


if __name__ == '__main__':
    main()

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])
    
city_count = {}
order = {}

for i, p, y in sorted(ipy, key = lambda x: x[2]):
    if not p in city_count:
        city_count[p] = 0
    city_count[p] += 1
    order[i, p] = city_count[p]

for i, p, y in ipy:
    print('{:06}{:06}'.format(p, order[i, p]))

Submission status: Accepted

Solution code:
n,m = map(int,input().split())
py = [list(map(int,input().split())) + [_] for _ in range(m)]
py.sort()
result = ['' for _ in range(m)] #ここで先にリストを作るから後から飛び飛びのインデックス指定で値を埋めていける

a = 1 #県のインデックスを表す変数
b = 1 #市の県の中でのインデックスを表す変数
for i in range(m):
    if py[i][0] != a:
        b=1
        a = py[i][0] 
        result[py[i][2]] = str(a).zfill(6) + str(b).zfill(6)
        b+=1
    else:
        result[py[i][2]] = str(a).zfill(6) + str(b).zfill(6)
        b+=1

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

Submission status: Accepted

Solution code:
import numpy as np

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

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

for i in range(M):
    cityList[P[i]-1].append((P[i],Y[i],i))

for i in range(N):
    cityList[i]=sorted(cityList[i])

for i in range(N):
    for j,item in enumerate(cityList[i]):
        ans[item[2]]="%06d%06d" % (item[0],j+1)

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

Submission status: Accepted

Solution code:
from bisect import bisect_left

N, M = map(int, input().split())
P, Y = [], []
v = [[] for _ in range(N+1)]

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

for i in range(N+1):
    v[i].sort()

for x, y in zip(P, Y):
    print ("%06d" % x, end = "")
    print ("%06d" % int(bisect_left(v[x], y) + 1))

Submission status: Accepted

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

sorted_inputs = {}
ans = [None]*M

for i in range(M):
    P, Y = map(int, input().split())
    if sorted_inputs.get(P) is None:
        sorted_inputs[P] = [(Y, i)]
    else:
        sorted_inputs[P].append((Y, i))

for pref, l in sorted_inputs.items():
    l.sort() # Yでソートされる
    for j, (Y, i) in enumerate(l):
        first = str(pref).rjust(6, '0')
        latter = str(j+1).rjust(6, '0')
        ans[i] = first + latter

for item in ans:
    print(item)

Submission status: Accepted

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

for i in range(M):
    py.append(list(map(int, input().split())) + [i])
py.sort()

result = ['' for i in range(M)]

n = 0
count = 1
for i in range(M):
    if py[i][0] != n:
        count = 1
        n = py[i][0]
    result[py[i][2]] = str(py[i][0]).zfill(6) + str(count).zfill(6)
    count += 1

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

Submission status: Accepted

Solution code:


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

arr = []
town = [[0]*2 for i in range(M)] #所属県、順番
count = [0]*(N+1)
for i in range(M):
    p,y= map(int,input().split())
    arr.append([i,p,y])

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

for i in arr:
    temp = i[1]
    town[i[0]][0] = temp
    town[i[0]][1] = count[i[1]]+1
    count[i[1]] += 1

for i in town:
    print(str(i[0]).zfill(6)+str(i[1]).zfill(6))

Submission status: Accepted

Solution code:
N,M=map(int,input().split())
P=[[] for i in range(M)]
Y=[1 for i in range(N+1)]
for i in range(M):
    a,b=map(int,input().split())
    P[i].append(i)
    P[i].append(a)
    P[i].append(b)
P.sort(key=lambda x:x[2])
for i in range(M):
    P[i].append(str(P[i][1]*1000000+Y[P[i][1]]))
    Y[P[i][1]]+=1
P.sort(key=lambda x:x[0])
for i in range(M):
    print(P[i][3].zfill(12))

Submission status: Accepted

Solution code:
import bisect

N, M = map(int, input().split())
P = [0 for _ in range(M)]
Y = [0 for _ in range(M)]
y_p = [[] for _ in range(N+1)]
for i in range(M):
    P[i], Y[i] = map(int, input().split())
    y_p[P[i]].append(Y[i])

for p in set(P):
    y_p[p].sort()

for p, y in zip(P, Y):
    order = bisect.bisect_left(y_p[p], y) + 1
    ans = str(p).zfill(6) + str(order).zfill(6)
    print(ans)

Submission status: Accepted

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

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

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

num = None
i   = 0
for a in aa:
    if a[0] == num:
        i += 1
        a.append('{:0=6}{:0=6}'.format(a[0], i))
    else:
        i = 1
        num = a[0]
        a.append('{:0=6}{:0=6}'.format(a[0], i))

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

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:

if __name__ == '__main__':
    ken_num, city_num = list(map(int, input().split()))
    data = []
    for i in range(city_num):
        element = list(map(int, input().split()))
        element.append(i)
        data.append(element)

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

    count = 1
    ken_num = 1
    ans_data = {}

    for i in range(city_num):
        number = data[i][2]
        if data[i][0] != ken_num:
            count = 1
            ken_num = data[i][0]
        chr = "{0:06d}".format(ken_num) + "{0:06d}".format(count)
        ans_data.update({number:chr})
        count += 1

    for i in range(city_num):
        print(ans_data[i])

Submission status: Accepted

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

city_to_pref, city_to_birth, pref_to_birth_list = {}, {}, defaultdict(list)
pref_counter = Counter()
city_id = {}
for i in range(m):
    pref, birth = map(int, input().split())
    city_to_pref[i] = pref
    city_to_birth[i] = birth
    pref_to_birth_list[pref].append(birth)


def get_city_index(i, pref):
    birth = city_to_birth[i]
    return pref_birth_to_id[pref][birth]


def give_id(i):
    p = city_to_pref[i]
    x = get_city_index(i, p) + 1
    return '{:0=6}{:0=6}'.format(p, x)


pref_birth_to_id = defaultdict(lambda : defaultdict(int))
for pref, births in pref_to_birth_list.items():
    for i, birth in enumerate(sorted(births)):
        pref_birth_to_id[pref][birth] = i

for i in range(m):
    print(give_id(i))

Submission status: Accepted

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

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

cnt = 1
prev_p = 0
for i in py:
    p, y = i[1][0], i[1][1]
    if prev_p == p:
        cnt += 1
    else:
        cnt = 1

    ans = str(p).zfill(6) + str(cnt).zfill(6)
    i.append(ans)
    prev_p = p

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

Submission status: Accepted

Solution code:
#coding:utf-8
#参考：https://beta.atcoder.jp/contests/abc113/submissions/3806710


if __name__ == "__main__":
    N, M = map(int, input().split())
    city_list = []
    for i in range(M):
        p, y = map(int, input().split())
        city_list.append([i, p, y])

    city_count = {}
    order_dic = {}
    for i, p, y in sorted(city_list, key = lambda x: x[2]):
        if not p in city_count:
            city_count[p] = 0
        city_count[p] += 1
        order_dic[i, p] = city_count[p]

    for i, p, y in city_list:
        print("{:06}{:06}".format(p, order_dic[i,p]))

Submission status: Accepted

Solution code:
class City:
    def __self__(self, prefecture = 0, year = 0, rowid = 0):
        self.prefecture = prefecture
        self.year = year
        self.rowid = rowid
    def __lt__(self, rhs):
        if self.prefecture < rhs.prefecture or (self.prefecture == rhs.prefecture and self.year < rhs.year):
            return True
        return False

def solution(cities):
    n = len(cities)
    foo = [None for i in range(n)]
    cities = sorted(cities)
    prev, offset = -1, 0
    for i in range(n):
        if cities[i].prefecture != prev:
            prev = cities[i].prefecture
            offset = 1
        foo[cities[i].rowid] = '%06d%06d' % (cities[i].prefecture, offset)
        offset += 1
    return foo

def main():
    n, m = [int(i) for i in input().strip().split()]
    cities = [City() for i in range(m)]
    for i in range(m):
        p, y = [int(i) for i in input().strip().split()]
        cities[i].prefecture = p
        cities[i].year = y
        cities[i].rowid = i
    foo = solution(cities)
    for row in foo:
        print(row)

if __name__ == '__main__':
    main()

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 x: (x[1],x[2]))

index=1
for i in range(M):
    if i>0:
        if city[i-1][1] != city[i][1]:
            index=1
    
    city[i][2]=index
    index+=1

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

for i in range(M):
    print(str(city[i][1]).zfill(6)+str(city[i][2]).zfill(6))

Submission status: Accepted

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

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

city_count = {}
city = {}

for i,p,y in sorted(city_list, key=lambda x: x[2]):
    if not p in city_count:
        city_count[p] = 1
    else:
        city_count[p] += 1
    city[i,p] = city_count[p]

for i,p,y in city_list:
    print("{:0=6}{:0=6}".format(p, city[i,p]))

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])
    
city_count = {}
city = {}
    
for i, p, y in sorted(ipy, key=lambda x: x[2]):
    if not p in city_count:
        city_count[p] = 1
    else:
        city_count[p] += 1
    city[i, p] = city_count[p]

for i, p, y in ipy:
    print('{:06}{:06}'.format(p, city[i, p]))

Submission status: Accepted

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

# from time import time
# 
# start = time()


def six(n):
    n_str = str(n)
    while len(n_str) < 6:
        n_str = "0" + n_str

    return n_str


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

id_list = [None] * M
dic_P = {}
info = []
info_idx = 0

for i in range(M):
    P, Y = map(int, input().split())
    if P in dic_P.keys():
        info[dic_P[P]].append([i, P, Y])
    else:
        dic_P[P] = info_idx
        info_idx += 1
        info.append([[i, P, Y]])

for group in info:
    group.sort(key=lambda a_i: a_i[2], reverse=False)
    for i, pair in enumerate(group):
        id = six(pair[1]) + six(i+1)
        id_list[pair[0]] = id

for id in id_list:
    print(id)

# print(time() - start)

Submission status: Accepted

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

# from time import time
# 
# start = time()


def six(n):
    n_str = str(n)
    while len(n_str) < 6:
        n_str = "0" + n_str

    return n_str


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

id_list = [None] * M
dic_P = {}
info = []
info_idx = 0

for i in range(M):
    P, Y = map(int, input().split())
    id_list[i] = [P, Y, ""]
    if P in dic_P.keys():
        info[dic_P[P]].append([i, P, Y])
    else:
        dic_P[P] = info_idx
        info_idx += 1
        info.append([[i, P, Y]])

for group in info:
    group.sort(key=lambda a_i: a_i[2], reverse=False)
    for i, pair in enumerate(group):
        id = six(pair[1]) + six(i+1)
        id_list[pair[0]] = id

for id in id_list:
    print(id)

# print(time() - start)

Submission status: Accepted

Solution code:
from operator import itemgetter
N, M = map(int, input().split())
c=[]
for i in range(M):
	c.append(list(map(int, input().split())))
for i in range(M):
	c[i].append(i)
C = sorted(sorted(c,key=itemgetter(1)), key=itemgetter(0))
x = 0
for i in range(M):
	if i > 0  and C[i][0] - C[i-1][0] != 0:
		x = 1
	else:
		x += 1
	C[i].append(x)
c = sorted(C, key=itemgetter(2))
for i in range(M):
	print("{:06d}{:06d}".format(c[i][0], c[i][3]))

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[1], x[2]))

num = None
count = 1

for i in range(len(ipy)):
    if num == None:
        num = ipy[i][1]

    if num != ipy[i][1]:
        count = 1
        num = ipy[i][1]

    bangou = str(ipy[i][1]).zfill(6) + str(count).zfill(6)

    ipy[i].append(bangou)

    count += 1

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

for i in range(len(ipy)):
    print(ipy[i][3])

Submission status: Accepted

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

v = [[] for i in range(N)]
for i in range(M):
    Pi, Yi = map(int, input().split())
    v[Pi-1].append((Yi, i))

ids = []
for ps,p in zip(v,range(len(v))):
    for c,i in zip(sorted(ps, key=(lambda x:x[0])), range(len(ps))):
        ids.append(('{0:06d}{1:06d}'.format(p+1,i+1) ,c[1]))

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

Submission status: Accepted

Solution code:
N,M = map(int,input().split(" "))
dic = {}
for i in range(M):
    P,Y = map(int,input().split(" "))
    if not P in dic: 
        dic[P] = [(Y,i)]
    else:
        dic[P].append((Y,i))

ans = [0] * M
for key in dic.keys():
    dic[key].sort(key=lambda x:x[0])
    l = len(dic[key])
    for i in range(l):
        ans[dic[key][i][1]] = (key,i+1)

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

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])

city_count = {}
order = {}

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

Submission status: Accepted

Solution code:
from operator import itemgetter, attrgetter

N, M = list(map(int,input().strip().split()))
ar = []
ans = []
num = 0

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

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

for i in ar:
    a,b,c = i
    if num != a:
        num = a
        num2 = 0
    num2 += 1
    ans.append([str(num).zfill(6)+str(num2).zfill(6),c])

ans.sort(key=itemgetter(1))

for i in range(M):
    py,c = ans[i]
    print(py)

Submission status: Accepted

Solution code:
NM = input().split()

N = int(NM[0])
M = int(NM[1])

PY = []
for i in range(1,M+1):
    sc = input()
    PY.append([int(sc.split()[0]),int(sc.split()[1]),i])

P_city = {}
for i in PY:
    if not i[0] in P_city:
        P_city[i[0]] = []
    P_city[i[0]].append([i[1],i[2]])
    
ans = {}
for i,j in P_city.items():
    j.sort()
    for index,k in enumerate(j):
        ans[k[1]] = str(i).zfill(6)+str(index+1).zfill(6)

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

Submission status: Accepted

Solution code:
from collections import defaultdict

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

Q=[]

for i in range(M):
  P,Y=map(int,input().split())
  Q.append([P,Y,i])
  
Q = sorted(Q,key=lambda x:x[1])
Q = sorted(Q,key=lambda x:x[0])

nowP=Q[0][0]
nownum=0

for l in Q:
  s=str(l[0]).zfill(6)
  if l[0]==nowP:
    nownum+=1
  else:
    nowP=l[0]
    nownum=1
  s+=str(nownum).zfill(6)
  l.append(s)
  
Q = sorted(Q,key=lambda x:x[2])

for l in Q:
  print(l[3])

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
n, m = map(int, input().split())
cities = []
for _ in range(m):
  cities.append(list(map(int, input().split())))
sort_cities = sorted(cities, key=lambda x:x[1])
pre = [0 for _ in range(n)]
ans = {}
for city in sort_cities:
  pre[city[0]-1]+=1
  st_city = str(city[0])
  st_pre = str(pre[city[0]-1])
  len_0 = (6-len(st_city))*'0'
  ans[len_0+st_city+str(city[1])] = len_0+st_city+(6-len(st_pre))*'0'+st_pre
for a in cities:
  print(ans[(6-len(str(a[0])))*'0'+str(a[0])+str(a[1])])

Submission status: Accepted

Solution code:
import bisect

N, M = map(int, input().split())
P = [0 for _ in range(M)]
Y = [0 for _ in range(M)]
y_p = [[] for _ in range(N+1)]
for i in range(M):
    P[i], Y[i] = map(int, input().split())
    y_p[P[i]].append(Y[i])

for p in set(P):
    y_p[p].sort()

for p, y in zip(P, Y):
    order = bisect.bisect_left(y_p[p], y)+1
    ans = str(p).zfill(6) + str(order).zfill(6)
    print(ans)

Submission status: Accepted

Solution code:
import bisect

N, M = map(int, input().split())
P = [0 for _ in range(M)]
Y = [0 for _ in range(M)]
y_p = [[] for _ in range(1, N+1)]
for i in range(M):
    P[i], Y[i] = map(int, input().split())
    y_p[P[i]-1].append(Y[i])

for p in set(P):
    y_p[p-1].sort()

for p, y in zip(P, Y):
    order = bisect.bisect_left(y_p[p-1], y)
    ans = str(p).zfill(6) + str(order+1).zfill(6)
    print(ans)

Submission status: Accepted

Solution code:
import bisect
N,M=map(int,input().split())
A=[[]for i in range(N)]
L=[]

for i in range(M):
    P,Y=map(int,input().split())
    A[P-1].append(Y)
    L.append([P-1,Y])
#print(A)
#print(L)

for j in range(N):
    A[j].sort()
#print(A)

for k in range(len(L)):
    ans1=str((L[k][0]+1)+1000000)
    ans1=ans1[1:]
    ans2=bisect.bisect_left(A[L[k][0]],L[k][1])
    ans2=str(ans2+1+1000000)
    ans2=ans2[1:]
    print(ans1+ans2)

Submission status: Accepted

Solution code:
#!/mnt/c/Users/moiki/bash/env/bin/python
N,M = list(map(int, input().split()))
P =[]
Y = []
yp = [(0,0,0)] * M
for i in range(M):
    P.append(0)
    Y.append(0)
    P[i], Y[i] = list(map(int, input().split()))
    yp[i] = (Y[i], P[i], i)

yp.sort()
dic = {}
# for i in range(M):
#     dic[P[i]] = [Y[i]] if not P[i] in dic else dic[P[i]] + [Y[i]]
#     dic[P[i]] = sorted(dic[P[i]])

# print(yp)
pre = [0] * (N+1)
ansnum = [0] * M
for (y,p,i) in yp:
    pre[p] += 1
    ansnum[i] = "{0:06d}{1:06d}".format(p, pre[p])

import numpy as np
for i in range(M):
    print(ansnum[i])
    # num = yp[]
    # num = dic[P[i]].index(Y[i]) + 1
    # print("{0:06d}{1:06d}".format(P[i], num))

Submission status: Accepted

Solution code:
def makelist(n, m):
    return [[0 for _ in range(m)] for _ in range(n)]


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

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

pre = [0]*(N+1)
ans = [0]*M

yp.sort()
for (y, p, i) in yp:
    pre[p] += 1
    right = str(pre[p])
    left = str(p)

    ans[i] = "0"*(6-len(left)) + left + "0"*(6-len(right)) + right

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

Submission status: Accepted

Solution code:
def zerofill(s):
    return '0'*(6-len(s)) + s

n, m = map(int, input().split())
list = []
for i in range(m):
    p, y = map(int, input().split())
    list.append([p, y, i])
num = ['']*m # 認識番号
list.sort()
cnt = 0
p = 1
for v in list:
    if(v[0]!=p):
        p = v[0]
        cnt = 1
    else:
        cnt += 1
    num[v[2]] = zerofill(str(v[0])) + zerofill(str(cnt))
for val in num:
    print(val)

Submission status: Accepted

Solution code:
import pprint

nn, mm = map(int, input().split())
#nn, mm = 2, 3

list = []

for i in range(mm):
    p, y = map(int, input().split())
    dict = {}
    dict['i'] = i
    dict['p'] = p
    dict['y'] = y
    list.append(dict)

'''

2 3
1 32
2 63
1 12

dict = {}
dict['i']=1
dict['p']=1
dict['y']=32
list.append(dict)

dict = {}
dict['i']=2
dict['p']=2
dict['y']=63
list.append(dict)

dict = {}
dict['i']=3
dict['p']=1
dict['y']=12
list.append(dict)
'''

#pprint.pprint(list)

list.sort(key=lambda x: x['y'])

#print()
#pprint.pprint(list)


count_dict = {}

for l in list:
    if l['p'] in count_dict:
        count_dict[l['p']] += 1
    else:
        count_dict[l['p']] = 1
    l['ORDER'] = str(count_dict[l['p']]).zfill(6)

#pprint.pprint(count_dict)

list.sort(key=lambda x: x['i'])

#print()


for l in list:
    print(str(l['p']).zfill(6) + l['ORDER'])

'''
#list[0]['xx'] = 111


d = list[0]
d['xx'] = 111

pprint.pprint(list)
'''

Submission status: Accepted

Solution code:
n,m=map(int,input().split())
l=list(list(map(int,input().split())) for i in range(m))
for i in range(m):
    l[i].append(i)
l.sort(key =lambda x:x[1])
l.sort(key =lambda x:x[0])
i=0
b=l[0][0]
for e in l:
    if b==e[0]:
        i+=1
    else:
        i=1
    e.append("%06d"%e[0]+"%06d"%i)
    b=e[0]
l.sort(key=lambda x:x[2])
for e in l:
    print(e[3])

Submission status: Accepted

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

for i in range(M):
  p, y = map(int, input().split())
  D[p-1].append((y, i)) #市ごとにリストに入れる．この時，元の順番をタプルの1番目の要素として入れておく
    
ans = [None]*M

for i, d in enumerate(D): #enumerateは要素の中身とインデックス番号を持ってこれる．print(i, d)で確認
  d.sort()
  for k, (y, j) in enumerate(d): #こちらも同様．(y, j)となっているため，yには年数が，jには元の順番の情報が入る
    ans[j] = str(i+1).zfill(6) + str(k+1).zfill(6) #ans[j]に12桁の認識番号を挿入

print(*ans, sep = '\n') 
#普通にprint(ans)とするとリストが出力される
#print(*ans)とすると，リストの要素がスペース区切りで出力される
#printのオプションsepで，文字の区切りをスペース出なく，改行に指定

Submission status: Accepted

Solution code:
from collections import defaultdict

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

KEN = defaultdict(list)
KENOUT = defaultdict(dict)
OUTPUT = []
for i in range(M):
    p,y = map(int,input().split())
    KEN[p].append(y)
    OUTPUT.append((p,y))

for p in KEN:
    for i,y in enumerate(sorted(KEN[p])):
        KENOUT[p][y] = i+1
        
for p,y in OUTPUT:
    print(str(p).zfill(6)+str(KENOUT[p][y]).zfill(6))

Submission status: Accepted

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

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

answer_list = [0] * M
prefectures = [0] * (N+1)
data_set = [0] * M

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

data_set.sort()

for i in range(M):
	answer = ''
	P, Y, a = data_set[i]
	prefectures[P] += 1

	for j in range(6-len(list(str(P)))):
		answer += '0'

	answer += str(P)

	for k in range(6-len(list(str(prefectures[P])))):
		answer += '0'

	answer += str(prefectures[P])

	answer_list[a] = answer

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

Submission status: Accepted

Solution code:
N, M = (int(i) for i in input().split())
P, Y = ({}, {})
for i in range(M):
    pp, yy = (int(i) for i in input().split())
    P[i] = pp
    Y[i] = yy

Y = sorted(Y.items(), key=lambda x:x[1])
Pnum = {}
Res = {}
for i, yy in Y:
    pp = P[i]
    if Pnum.get(pp):
        Pnum[pp] += 1
    else:
        Pnum[pp] = 1
    Res[i] = "{:0=6}{:0=6}".format(pp, Pnum[pp])

Res = sorted(Res.items(), key=lambda x:x[0])
for i, rr in Res:
    print(rr)

Submission status: Accepted

Solution code:
from bisect import bisect_left


n,m = list(map(int,input().split()))
a = [[0] for i in range(n)]
b = [None]*m
for i in range(m):
    p,s = list(map(int,input().split()))
    p-=1
    a[p].append(s)
    b[i] = [p,s]
for i in range(len(a)):
    a[i].sort()
for i in range(len(b)):
    ken = b[i][0]
    si = bisect_left(a[ken], b[i][1])
    ken = str(ken+1).zfill(6)
    si = str(si).zfill(6)
    print("".join([ken,si]))

Submission status: Accepted

Solution code:
# https://abc113.contest.atcoder.jp/tasks/abc113_c
def pad(n):
    return '{:0>6}'.format(n)


N, M = map(int, input().split())
work = [None for _ in range(M)]
orig = [None for _ in range(M)]  # retains original order
for i in range(M):
    Pi, Yi = map(int, input().split())
    data = [Pi, Yi, 1, i]
    work[i] = data
    orig[i] = data

work.sort(key=lambda x: x[1])  # sort by year
work.sort(key=lambda x: x[0])  # sort by prefectures

for i in range(1, M):
    if work[i][0] == work[i - 1][0]:
        work[i][2] = work[i - 1][2] + 1

ans = ''
for di in orig:
    ans += (pad(di[0]) + pad(di[2])) + '\n'
print(ans)