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: Wrong Answer

Solution code:
import sys
def input(): return sys.stdin.readline().rstrip()

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

    sorted_PY  = sorted(PY)
    ans = [{} for _ in range(N+1)]
    i = 0
    pre = sorted_PY[0][0]
    for p, y in sorted_PY:
        if pre != p:
            i = 0
        i += 1
        ans[p][y] = i

    for p, y in PY:
        print(str(p).zfill(6) + str(ans[p][y]).zfill(6))

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
def compress(arr):
    *XS, = set(arr)
    XS.sort()
    return {e: i for i, e in enumerate(XS)} 
n,m=map(int,input().split())
s=[[] for i in range(n+1)]
p=[0]*m
y=[0]*m
for i in range(m):
    p[i],y[i]=map(int,input().split())
    s[p[i]].append(y[i])
for i in range(1,n+1):
    s[i]=compress(s[i])
for i in range(m):
    print("0"*(6-len(str(p[i]))),p[i],"0"*(6-len(str(s[p[i]][y[i]]))),s[p[i]][y[i]]+1,sep="")

Submission status: Wrong Answer

Solution code:
import copy

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

cnt = [0]*(10**5+4)

yy = []
yp = []
for _ in range(m):
    a,b = map(int,input().split())
    a,b = b,a
    yy.append([a,0])
    yp.append([a,b])

inlist = copy.deepcopy(yp)
yp.sort()
yy = dict(yy)

for i in range(m):
    print(yp[i][1])
    cnt[yp[i][1]]+=1
    yy[yp[i][0]] = cnt[yp[i][1]]

for key,value in inlist:
    print("{:06}{:06}".format(value,yy[key]))

Submission status: Wrong Answer

Solution code:
n,m = [int(x) for x in input().split()]
py = []
for i in range(m):
    p,y = [int(x) for x in input().split()]
    py.append([p,y,i+1])

def zero(num):
    return str(num).zfill(6)


if m == 1:
    print(zero(py[0])+zero(1))
else:
    year_py = sorted(py, key=lambda x: x[1])
    dic = {str(x): 0 for x in range(1,n+1)}

    for i in range(m):
        dic[str(year_py[i][0])] += 1
        year_py[i].append(dic[str(year_py[i][0])])
    yb_py = sorted(year_py, key=lambda x: x[2])

    for i in range(m):
        print(zero(yb_py[i][0]) + zero(yb_py[i][3]))

Submission status: Wrong Answer

Solution code:
n,m = [int(x) for x in input().split()]
py = []
for i in range(m):
    p,y = [int(x) for x in input().split()]
    py.append([p,y,i+1])

def zero(num):
    return str(num).zfill(6)


if m == 1:
    print(zero(py[0])+zero(1))
else:
    year_py = sorted(py, key=lambda x: x[1])
    dic = {x: 0 for x in range(1,m+1)}

    #for i in range(m):
    #    dic[year_py[i][0]] += 1
    #    year_py[i].append(dic[year_py[i][0]])
    #yb_py = sorted(year_py, key=lambda x: x[2])

    #for i in range(m):
    #    print(zero(yb_py[i][0]) + zero(yb_py[i][3]))

Submission status: Wrong Answer

Solution code:
n,m = map(int,input().split())
year = [[] for i in range(n+1)]
for i in range(m):
    p,y = map(int,input().split())
    year[p].append((y,i+1))
nums = [[0]*2 for i in range(m+1)]
for i in range(n):
    if(len(year[i+1]) == 0):continue
    year[i+1] = sorted(year[i+1])
    for j in range(len(year[i+1])):
        pref = i+1
        city = year[i+1][j][1]
        nums[city][0] = pref
        nums[city][1] = j+1
for i in range(m+1):
    if i == 0:continue
    a = nums[i][0]
    b = nums[i][1]
    ans = "0"*(6-len(str(a)))+str(a)+"0"*(6-len(str(a)))+str(b)
    print(ans)

Submission status: Wrong Answer

Solution code:
def zeroPadding(num):
    return "%06d"%num

class Row:
    def __init__(self, i, pref_id, year):
        self.i = i
        self.pref_id = pref_id
        self.year = year
        self.city_id = -1
        
    def __str__(self):
        return "{i: %d, pref_id: %d, year: %d, city_id: %d}"%(self.i, self.pref_id, self.year, self.city_id)
        
    def set_city_id(self, city_id):
        self.city_id = city_id
            
    def get_sort_key(self):
        return zeroPadding(self.pref_id ) + zeroPadding(self.year ) 
            
    def get_str(self):
        return zeroPadding(self.pref_id ) + zeroPadding(self.city_id)

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

row_list = []

for i in range(M):
    d = list(map(int,input().split())) 
    row_list.append(Row(i, d[0], d[1]))

row_list = sorted(row_list, key=lambda x: x.get_sort_key())

now_pref_id = -1
cnt = 1

result = []
for i, row in enumerate(row_list):
    if row.pref_id != now_pref_id:
        now_pref_id = row.pref_id
        cnt = 1
    
    row.set_city_id(cnt)
    row_list[i] = row
    cnt += 1

[print(x.get_str()) for x in sorted(row_list, key=lambda x: x.i)]

Submission status: Wrong Answer

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

def zeroPadding(num):
    return "%06d"%num

class Row:
    def __init__(self, i, pref_id, year):
        self.i = i
        self.pref_id = pref_id
        self.year = year
        self.city_id = -1
        
    def __str__(self):
        return "{i: %d, pref_id: %d, year: %d, city_id: %d}"%(self.i, self.pref_id, self.year, self.city_id)
        
    def set_city_id(self, city_id):
        self.city_id = city_id
            
    def get_sort_key(self):
        return zeroPadding(self.pref_id ) + zeroPadding(self.year ) 
            
    def get_str(self):
        return zeroPadding(self.pref_id ) + zeroPadding(self.city_id)

row_list = [Row(i, d[0], d[1]) for i,d in enumerate(P)]
sorted_row_list = sorted(row_list, key=lambda x: x.get_sort_key())


now_pref_id = -1
cnt = 1

result = []
for i, row in enumerate(sorted_row_list):
    if row.pref_id != now_pref_id:
        now_pref_id = row.pref_id
        cnt = 1
    
    row.set_city_id(cnt)
    sorted_row_list[i] = row
    cnt += 1

[print(x.get_str()) for x in sorted(sorted_row_list, key=lambda x: x.i)]

Submission status: Wrong Answer

Solution code:
import numpy as np
n, m = map(int, input().split())
py = [list(map(int, input().split())) for i in range(m)]
py2 = [py[i].append(i) for i in range(m)]
py.sort(key=lambda x: x[1])
now = py[0][0]
count = 0
anslist = np.empty((m, 2))
for i in range(m):
    if now == py[i][0]:
        count += 1
    else:
        now = py[i][0]
        count = 1
    anslist[py[i][2], 0] = py[i][0]
    anslist[py[i][2], 1] = count

for x, y in anslist:
    print("{:06}".format(int(x)) + "{:06}".format(int(y)))

Submission status: Wrong Answer

Solution code:
import numpy as np
n, m = map(int, input().split())
py = [list(map(int, input().split())) for i in range(m)]
py2 = [py[i].append(i) for i in range(m)]
py.sort(key=lambda x: x[1])
now = py[0][0]
count = 0
anslist = np.empty((m, 2))
print(py)
for i in range(m):
    if now == py[i][0]:
        count += 1
    else:
        now = py[i][0]
        count = 1
    anslist[py[i][2], 0] = py[i][0]
    anslist[py[i][2], 1] = count

for x, y in anslist:
    print("{:06}".format(int(x)) + "{:06}".format(int(y)))

Submission status: Wrong Answer

Solution code:
n, m = map(int, input().split())
py = [list(map(int, input().split())) for i in range(m)]
py.sort(key=lambda x: x[1])
now = py[0][0]
count = 0
for i in range(m):
    if now == py[i][0]:
        count += 1
    else:
        now = py[i][0]
        count = 1
    print("{:06}".format(py[i][0]) + "{:06}".format(count))

Submission status: Wrong Answer

Solution code:
n, m = map(int, input().split())
py = [list(map(int, input().split())) for i in range(m)]
py.sort(key=lambda x: x[1])
now = py[0][0]
count = 0
for i in range(m):
    if now == py[i][0]:
        count += 1
    else:
        now = py[i][0]
        count = 1
    print("{:04}".format(py[i][0]) + "{:04}".format(count))

Submission status: Wrong Answer

Solution code:
import sys
from heapq import heapify

def main():
    N,M = map(int, input().split())
    PY_input = []
    PY = [[] for i in range(N+1)]
    for _ in range(M):
        p, y = map(int, sys.stdin.readline().split())
        PY_input.append((p, y))
        PY[p].append(y)

    for i in PY:
        heapify(i)

    for p, y in PY_input:
        print("{:06}{:06}".format(p, PY[p].index(y)+1))



if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
N, M = map(int, input().split())
arr = [0 for _ in range(M)]
for i in range(M):
    p, y = map(int, input().split())
    arr[i] = [p, y, i]

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

arr[0][1] = 1
ans_list = [0] * M
for i in range(0, M):
    if i == 0:
        ans_list[i] = [str(arr[0][0]).zfill(6) + str(arr[0][1]).zfill(6), arr[i][2]]
        continue
    if arr[i][0] == arr[i - 1][0]:
        arr[i][1] = arr[i - 1][1] + 1
    else:
        arr[i][1] = 1
    ans_list[i] = [str(arr[i][0]).zfill(6) + str(arr[i][1]).zfill(6), arr[i][2]]

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

Submission status: Wrong Answer

Solution code:
N, M = map(int, input().split())
arr = [0 for _ in range(M)]
for i in range(M):
    p, y = map(int, input().split())
    arr[i] = [p, y, i]
print(arr)
arr.sort(key=lambda x:x[1])
print(arr)
arr[0][1] = 1
ans_list = [0] * M
for i in range(0, M):
    if i == 0:
        ans_list[i] = [str(arr[0][0]).zfill(6) + str(arr[0][1]).zfill(6), arr[i][2]]
        continue
    if arr[i][0] == arr[i - 1][0]:
        arr[i][1] = arr[i - 1][1] + 1
    else:
        arr[i][1] = 1
    ans_list[i] = [str(arr[i][0]).zfill(6) + str(arr[i][1]).zfill(6), arr[i][2]]
print(ans_list)
ans_list.sort(key=lambda x:x[1])
for i in range(M):
    print(ans_list[i][0])

Submission status: Wrong Answer

Solution code:
N, M = map(int, input().split())
arr = [0 for _ in range(M)]
for i in range(M):
    arr[i] = list(map(int, input().split()))
arr_sort = sorted(arr)

arr_sort[0][1] = 1
for i in range(0, M):
    if i == 0:
        print(str(arr_sort[0][0]).zfill(6) + str(arr_sort[0][1]).zfill(6))
        continue
    if arr_sort[i][0] == arr_sort[i - 1][0]:
        arr_sort[i][1] = arr_sort[i - 1][1] + 1
    else:
        arr_sort[i][1] = 1
    print(str(arr_sort[i][0]).zfill(6) + str(arr_sort[i][1]).zfill(6))

Submission status: Wrong Answer

Solution code:
from operator import itemgetter
def main():
    N,M = map(int,input().split())
    py = [list(map(int,input().split())) for _ in range(M)]
    [py[i].append(i) for i in range(M)]
    py = sorted(py,key=itemgetter(0))
    py = sorted(py,key=itemgetter(1))
    now = 0
    num = 1
    ans = []
    for i in range(M):
        if now != py[i][0]:
            now = py[i][0]
            num = 1
        else:
            num += 1
        tmp = str(now).zfill(6)+str(num).zfill(6)
        ans.append([tmp,py[i][2]])
    ans = sorted(ans,key=itemgetter(1))
    for i in range(M):
        print(ans[i][0])


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import sys
def input():
    return sys.stdin.readline()[:-1]
N,M=map(int,input().split())
l=[None]*M
for i in range(M):
    P,Y=map(int,input().split())
    l[i]=(P,Y,i)
l.sort()
a=[None]*M
s=0
t=1
for i in l:
    if i[0]==s:
        t+=1
    else:
        t=1
        s=i[0]
    a[i[2]]="{:06d}".format(i[0]) + "{:06d}".format(t)
print(a)

Submission status: Wrong Answer

Solution code:
N,M = map(int,input().split())
p,y = 0,0
my_dict = dict()
def genFrstSix(P):
	str_ = str(P)
	while(len(str(str_))<6):
		str_ = "0"+ str_
		# print(str_)
	return str_
P,Y,tup=[],[],[]
for i in range(M):
	p,y = map(int,input().split())
	tup.append((p,y))
	if p in my_dict.keys():
		my_dict[p].append(y)
	else:
		my_dict[p] = [y]

print(tup)	
L = []
# print(sorted(my_dict.items(), key =lambda item: x[1]))
for key,values in my_dict.items():
	for each in values:
		L.append([(key,each),genFrstSix(key)+genFrstSix(values.index(each)+1)])
		
# for key,values in sorted(my_dict.items(), key =lambda x: x[0]):
# 	# print(key,values)
	# for each in values:
	# 	L.append([(key,each),genFrstSix(key)+genFrstSix(values.index(each)+1)])

for i in range(len(tup)):
	for j in range(len(L)):
		# print(tup[i],L[j][0])
		if tup[i] == L[j][0]:
			print(L[j][1])

Submission status: Wrong Answer

Solution code:
N,M = map(int,input().split())
p,y = 0,0
my_dict = dict()
def genFrstSix(P):
	str_ = str(P)
	while(len(str(str_))<6):
		str_ = "0"+ str_
		# print(str_)
	return str_
P,Y,tup=[],[],[]
for i in range(M):
	p,y = map(int,input().split())
	tup.append((p,y))
	if p in my_dict.keys():
		my_dict[p].append(y)
	else:
		my_dict[p] = [y]
	
L = []
for key,values in sorted(my_dict.items(), key =lambda x: x[0]):
	# print(key,values)
	for each in values:
		L.append([(key,each),genFrstSix(key)+genFrstSix(values.index(each)+1)])
# print(L)
# print(tup)
for i in range(len(tup)):
	for j in range(len(L)):
		# print(tup[i],L[j][0])
		if tup[i] == L[j][0]:
			print(L[j][1])

Submission status: Wrong Answer

Solution code:
N,M = map(int,input().split())
p,y = 0,0
my_dict = dict()
def genFrstSix(P):
	str_ = str(P)
	while(len(str(str_))<6):
		str_ = "0"+ str_
		# print(str_)
	return str_
P,Y,tup=[],[],[]
for i in range(M):
	p,y = map(int,input().split())
	P.append(p)
	Y.append(y)
	tup.append((p,y))

for i in range(len(P)):
	if P[i] in my_dict.keys():
		my_dict[P[i]].append(Y[i])
	else:
		my_dict[P[i]] = [Y[i]]
# print(my_dict)

# print(genFrstSix(12))
# print(my_dict)
L = []
for key,values in sorted(my_dict.items(), key =lambda x: x[0]):
	# print(key,values)
	for each in values:
		L.append([(key,each),genFrstSix(key)+genFrstSix(values.index(each)+1)])
# print(L)
# print(tup)
for i in range(len(tup)):
	for j in range(len(L)):
		# print(tup[i],L[j][0])
		if tup[i] == L[j][0]:
			print(L[j][1])

Submission status: Wrong Answer

Solution code:
n, m = [int(x) for x in input().split(' ')]

cities = list()
for i in range(m):
    pi, pm = [int(x) for x in input().split(' ')]
    cities.append((pi, pm))

p = [0] * (n+1)
for city in sorted(cities, key=lambda city: city[1]): # sort by year
    p[city[0]] += 1 # city birth order
    print('{:06d}{:06d}'.format(city[0], p[city[0]]))

Submission status: Wrong Answer

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

x = sorted(py)[0][1]
a = 1
ans = []
for i, p, y in py:
    if x != int(p):
        x = int(p)
        a = 1
    
    ans.append([i, p.zfill(6)+str(a).zfill(6)])
    a += 1

for i, v in sorted(ans):
    print(v)

Submission status: Wrong Answer

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

x = 1
a = 1
ans = []
for i, p, y in py:
    if x != int(p):
        x += 1
        a = 1
    
    ans.append([i, p.zfill(6)+str(a).zfill(6)])
    a += 1

for i, v in sorted(ans):
    print(v)

Submission status: Wrong Answer

Solution code:
import sys
from collections import defaultdict
sys.setrecursionlimit(10 ** 7)

# 座標圧縮
# 座圧

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

PREFECTURE = defaultdict(list)
for p, y in PY:
    PREFECTURE[p].append(y)

print(PREFECTURE)

for i in PREFECTURE.keys():
    ys = sorted(PREFECTURE[i])
    y_to_i = {y: i+1 for i, y in enumerate(ys)}
    PREFECTURE[i] = y_to_i

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

Submission status: Wrong Answer

Solution code:

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

py.sort(key=lambda na:(na[1],na[2]))

count=0
m_city=py[0][1]
for i in range(m):
    si=py[i][1]
    if m_city==si:
        count+=1
        py[i].append(count)
    else:
        count=1
        py[i].append(count)
    
py.sort(key=lambda na:na[0])
for i in range(m):
    print('{:0>6}'.format(py[i][1]),end="")
    print('{:0>6}'.format(py[i][3]))

Submission status: Wrong Answer

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

py.sort(key=lambda na:(na[1],na[2]))

count=0
m_city=py[0][1]
for i in range(m):
    si=py[i][1]
    if m_city==si:
        count+=1
        py[i].append(count)
    else:
        count=1
        py[i].append(count)
    
py.sort(key=lambda na:na[0])


for i in range(m):
    for j in range(6-len(str(py[i][1]))):
        print(0,end="")
    print(py[i][1],end="")
    for j in range(6-len(str(py[i][3]))):
        print(0,end="")
    print(py[i][3])

Submission status: Wrong Answer

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

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

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

now_pre = py[0][1]
now_idx = 0
for i in py:
    num_p = str(i[1]).zfill(6)
    if i[1] == now_pre:
        now_idx += 1
    else:
        now_idx = 1
    num_y = str(now_idx).zfill(6)
    i[3] = num_p + num_y

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

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

Submission status: Wrong Answer

Solution code:
# coding: utf-8
N,M=map(int,input().split())
L=[[] for i in range(N)]
#print(L)


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

#print(L)

for i in range(N):
    L[i].sort()
    
#print(L)

for i in range(N):
    if L[i]!=[]:
        for j in range(len(L[i])):
            ans=str(i+1).zfill(6)+str(j+1).zfill(6)
            print(ans)

Submission status: Wrong Answer

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

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

city = [sorted(city[i]) for i in range(n)]

for i in range(m):
   tmp = city[x[i][0]-1].index(x[i][1])
   print('{:0>4}{:0>4}'.format(x[i][0], tmp+1))

Submission status: Wrong Answer

Solution code:
#ABC113_C

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

PYi.sort()

prep=PYi[0][0]
cc=1#city code
PYi[0][1]=cc
for j in range(1,M):
    p=PYi[j][0]
    if prep==p:
        cc+=1
    else:
        cc=1
    PYi[j][1]=cc
    prep=p
        
PYi.sort(key=lambda x:x[2])

def padding(A):
    A=str(A)
    while len(A)<6:
        A=str(0)+A
    return A

for i in range(M):
    print(padding(PYi[i][0]),padding(PYi[i][1]))

Submission status: Wrong Answer

Solution code:
import collections
import bisect
n,m=map(int,input().split())
p=[[int(j) for j in input().split()] for i in range(m)]
a=collections.defaultdict(list)
for x,y in sorted(p):
    a[x]+=[y]
print(a)
for x,y in p:
    z=bisect.bisect(a[x],y)
    print("%06d%06d"%(x,z))

Submission status: Wrong Answer

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],x[2]))
now = py[0][1]
n = 1
for i in py:
  if now != i[1]:
    n = 1
    i.append(n)
    now = i[1]
  else:
    i.append(n)
    n += 1
 
for i in sorted(py,key=lambda x:x[0]):
  print("{}{}".format(str(i[1]).zfill(6),str(i[3]).zfill(6)))

Submission status: Wrong Answer

Solution code:
n, m = map(int, input().split())
name = []
city = []
prefecture = [1] * n
for i in range(m):
    a = list(map(int, input().split())) + [i+1]
    city.append(a)
    name.append("{}{}".format("0" * (6 - len(str(a[0]))), a[0]))


for i in range(m):
    p, y, num = city[i]
    x = prefecture[p-1]
    name[num-1] += "{}{}".format("0" * (6 - len(str(x))), x)
    prefecture[p-1] += 1
for i in name:
    print(i)

Submission status: Wrong Answer

Solution code:
n, m = map(int, input().split())
name = []
city = []
prefecture = [1] * n
for i in range(m):
    a = list(map(int, input().split())) + [i+1]
    city.append(a)
    name.append("{}{}".format("0" * (6 - len(str(a[0]))), a[0]))
city_1 = sorted(city, key=lambda x: x[0])
city_sorted = sorted(city, key=lambda x: x[1])

x = 1
for i in range(m):
    p, y, num = city_sorted[i]
    x = prefecture[p-1]
    name[num-1] += "{}{}".format("0" * (6 - len(str(x))), x)
    x += 1
for i in name:
    print(i)

Submission status: Wrong Answer

Solution code:
n, m = map(int, input().split())
name = []
city = []
for i in range(m):
    a = list(map(int, input().split())) + [i+1]
    city.append(a)
    name.append("{}{}".format("0" * (6 - len(str(a[0]))), a[0]))
city_1 = sorted(city, key=lambda x: x[0])
city_sorted = sorted(city, key=lambda x: x[1])
check = set([])
x = 0
for i in range(m):
    p, y, num = city_sorted[i]
    if p in check:
        pass
    else:
        check.add(p)
        x = 1
    name[num-1] += "{}{}".format("0" * (6 - len(str(x))), x)
    x += 1
for i in name:
    print(i)

Submission status: Wrong Answer

Solution code:
import math

N,M = map(int,input().split())
n_of_city = [0]*N
MAIN = []
for i in range(M):
    P,Y = map(int,input().split())
    left_number = "0"*(5 - round(math.log10(P))) + str(P)
    MAIN.append([i,P,Y,left_number])
    
MAIN.sort(key=lambda x:x[2])
for city in MAIN:
    n_of_city[city[1] - 1] += 1
    num = n_of_city[city[1] - 1]
    right_number = "0"*(5 - round(math.log10(num))) + str(num)
    city.append(right_number)

MAIN.sort(key=lambda x:x[0])
for city in MAIN:
    print(city[3] + city[4])

Submission status: Wrong Answer

Solution code:
import math
import numpy as np
from fractions import gcd
import fractions
import statistics
import collections
from functools import reduce
import itertools
from collections import defaultdict

N,M=map(int, input().split())
city = defaultdict(list)
p = [0] * M
y = [0] * M

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

city_sorted = defaultdict(list)
for key,v in city.items():
    city_sorted[key] = sorted(v)

for a in range(M):
    key = p[a]
    for (i,x) in enumerate(city_sorted[key]):
        if (y[a] == x):
            print(str(key).zfill(5)+str(i+1).zfill(5))

Submission status: Wrong Answer

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

ans=[]
for i in range(m):
    if not py[i][0] in _dict:
        _dict[py[i][0]]=1
    else:
        _dict[py[i][0]]+=1
    p="0"*(6-len(str(py[i][0])))+str(py[i][0])
    y="0"*(6-len(str(py[i][0])))+str(_dict[py[i][0]])
    ans.append([p+y,py[i][2]])

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

Submission status: Wrong Answer

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)
_dict = {}

ans=[]
for i in range(m):
    if not py[i][0] in _dict:
        _dict[py[i][0]]=1
    else:
        _dict[py[i][0]]+=1
    p="0"*(6-len(str(py[i][0])))+str(py[i][0])
    y="0"*(6-len(str(py[i][0])))+str(_dict[py[i][0]])
    ans.append([p+y,py[i][2]])

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

Submission status: Wrong Answer

Solution code:
import copy

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

dic = {}
pref_set = []
for i in range(m):
    p,y = map(int,input().split())
    dic[y] = p
    #pref_set.append(p)

#pref_set = sorted(list(set(pref_set)))

sort_dic = copy.deepcopy(dic)
sort_t = sorted(sort_dic.items(),key=lambda x:x[0])
#print(dic)
#print(sort_t)
sort_t = sorted(sort_t,key=lambda x:x[1])
#print(sort_t)

counter = 1
pref = sort_t[0][1]
ans_dic = {}
for y,p in sort_t:
    #print(p,"   ",y)
    # 違う場合
    if p != pref:
        counter = 1
        pref = p
    tmp = str(p).zfill(6) + str(counter).zfill(6)
    ans_dic[y] = tmp
    counter += 1

for val in dic.keys():
    print(str(ans_dic[val]))

Submission status: Wrong Answer

Solution code:
import copy

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

dic = {}
pref_set = []
for i in range(m):
    p,y = map(int,input().split())
    dic[y] = p
    #pref_set.append(p)

#pref_set = sorted(list(set(pref_set)))

sort_dic = copy.deepcopy(dic)
sort_t = sorted(sort_dic.items(),key=lambda x:x[0])
#print(dic)
print(sort_t)
sort_t = sorted(sort_t,key=lambda x:x[1])
print(sort_t)

counter = 1
pref = sort_t[0][1]
ans_dic = {}
for y,p in sort_t:
    #print(p,"   ",y)
    # 違う場合
    if p != pref:
        counter = 1
        pref = p
    tmp = str(p).zfill(6) + str(counter).zfill(6)
    ans_dic[y] = tmp
    counter += 1

for val in dic.keys():
    print(str(ans_dic[val]))

Submission status: Wrong Answer

Solution code:
import copy

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

dic = {}
pref_set = []
for i in range(m):
    p,y = map(int,input().split())
    dic[y] = p
    #pref_set.append(p)

#pref_set = sorted(list(set(pref_set)))

sort_dic = copy.deepcopy(dic)
sort_t = sorted(sort_dic.items(),key=lambda x:x[0],reverse=True)
#print(dic)
#print(sort_t)
sort_t = sorted(sort_t,key=lambda x:x[1])
#print(sort_t)

counter = 1
pref = sort_t[0][1]
ans_dic = {}
for y,p in sort_t:
    #print(p,"   ",y)
    # 違う場合
    if p != pref:
        counter = 1
        pref = p
    tmp = str(p).zfill(6) + str(counter).zfill(6)
    ans_dic[y] = tmp
    counter += 1

for val in dic.keys():
    print(str(ans_dic[val]))

Submission status: Wrong Answer

Solution code:
import copy

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

dic = {}
pref_set = []
for i in range(m):
    p,y = map(int,input().split())
    dic[y] = p
    #pref_set.append(p)

#pref_set = sorted(list(set(pref_set)))

sort_dic = copy.deepcopy(dic)
sort_t = sorted(sort_dic.items(),key=lambda x:x[0])
#print(dic)
#print(sort_t)
sort_t = sorted(sort_t,key=lambda x:x[1])
#print(sort_t)

counter = 1
pref = sort_t[0][1]
ans_dic = {}
for y,p in sort_t:
    #print(p,"   ",y)
    # 違う場合
    if p != pref:
        counter = 1
        pref = p
    tmp = str(p).zfill(6) + str(counter).zfill(6)
    ans_dic[y] = tmp
    counter += 1

L = []
for val in dic.keys():
    L.append(str(ans_dic[val]))

for i in L:
    print(i)

Submission status: Wrong Answer

Solution code:
import copy

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

dic = {}
pref_set = []
for i in range(m):
    p,y = map(int,input().split())
    dic[y] = p
    #pref_set.append(p)

#pref_set = sorted(list(set(pref_set)))

sort_dic = copy.deepcopy(dic)
sort_t = sorted(sort_dic.items(),key=lambda x:x[0])
#print(dic)
#print(sort_t)
sort_t = sorted(sort_t,key=lambda x:x[1])
#print(sort_t)

counter = 1
pref = sort_t[0][1]
ans_dic = {}
for y,p in sort_t:
    #print(p,"   ",y)
    # 違う場合
    if p != pref:
        counter = 1
        pref = p
    tmp = str(p).zfill(6) + str(counter).zfill(6)
    ans_dic[y] = tmp
    counter += 1

for val in dic.keys():
    print(str(ans_dic[val]))

Submission status: Wrong Answer

Solution code:
import copy

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

dic = {}
pref_set = []
for i in range(m):
    p,y = map(int,input().split())
    dic[y] = p
    #pref_set.append(p)

#pref_set = sorted(list(set(pref_set)))

sort_dic = copy.deepcopy(dic)
sort_t = sorted(sort_dic.items(),key=lambda x:x[0])
#print(dic)
#print(sort_t)
sort_t = sorted(sort_t,key=lambda x:x[1])
#print(sort_t)

counter = 1
pref = sort_t[0][1]
ans_dic = {}
for y,p in sort_t:
    print(p,"   ",y)
    # 違う場合
    if p != pref:
        counter = 1
        pref = p
    tmp = str(p).zfill(6) + str(counter).zfill(6)
    ans_dic[y] = tmp
    counter += 1

for val in dic.keys():
    print(str(ans_dic[val]))

Submission status: Wrong Answer

Solution code:
import copy

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

dic = {}
pref_set = []
for i in range(m):
    p,y = map(int,input().split())
    dic[y] = p
    #pref_set.append(p)

#pref_set = sorted(list(set(pref_set)))

sort_dic = copy.deepcopy(dic)
sort_t = sorted(sort_dic.items(),key=lambda x:x[1])
#print(dic)
#print(sort_t)
sort_t = sorted(sort_t,key=lambda x:x[0])
#print(sort_t)

counter = 1
pref = sort_t[0][1]
ans_dic = {}
for y,p in sort_t:
    # 違う場合
    if p != pref:
        counter = 1
        pref = p
    tmp = str(p).zfill(6) + str(counter).zfill(6)
    ans_dic[y] = tmp
    counter += 1

for val in dic.keys():
    print(str(ans_dic[val]))

Submission status: Wrong Answer

Solution code:
import copy

n,m = map(int,input().split())
dic = {}

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

sd = copy.deepcopy(dic)
#print(sd.items())
sd = sorted(sd.items(),key=lambda x:x[0])
sd = sorted(sd,key=lambda x:x[1])

ken = sd[0][1]
counter = 0
ans_dic = {}

for y,k in sd:
    if ken == k:
        counter +=1
    else:
        counter = 1
        ken = k
    tmp = str(k).zfill(6) + str(counter).zfill(6)
    ans_dic[y] = tmp

for i in dic.keys():
    print(ans_dic[i]+"\n")

Submission status: Wrong Answer

Solution code:
import copy

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

dic = {}
pref_set = []
for i in range(m):
    p,y = map(int,input().split())
    dic[y] = p
    #pref_set.append(p)

#pref_set = sorted(list(set(pref_set)))

sort_dic = copy.deepcopy(dic)
sort_t = sorted(sort_dic.items(),key=lambda x:x[1])
#print(dic)
#print(sort_t)
sort_t = sorted(sort_t,key=lambda x:x[0])
#print(sort_t)

counter = 1
pref = sort_t[0][1]
ans_dic = {}
for y,p in sort_t:
    # 違う場合
    if p != pref:
        counter = 1
        pref = p
    # zeroume dic化
    tmp = str(p).zfill(6) + str(counter).zfill(6)
    ans_dic[y] = tmp
    #########
    counter += 1

for val in dic.keys():
    print(str(ans_dic[val]))

Submission status: Wrong Answer

Solution code:
import copy

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

dic = {}
pref_set = []
for i in range(m):
    p,y = map(int,input().split())
    dic[y] = p
    #pref_set.append(p)

#pref_set = sorted(list(set(pref_set)))

sort_dic = copy.deepcopy(dic)
sort_t = sorted(sort_dic.items(),key=lambda x:x[1])
#print(dic)
#print(sort_t)
sort_t = sorted(sort_t,key=lambda x:x[0])
#print(sort_t)

counter = 1
pref = sort_t[0][1]
ans_dic = {}
for y,p in sort_t:
    # 違う場合
    if p != pref:
        counter = 1
        pref = p
    # zeroume dic化
    tmp = str(p).zfill(6) + str(counter).zfill(6)
    ans_dic[y] = tmp
    #########
    counter += 1

for val in dic.keys():
    print(ans_dic[val])

Submission status: Wrong Answer

Solution code:
import numpy as np
from itertools import groupby, accumulate

N, M = map(int, input().split())
P = []
Y = []
for i in range(M):
    p1, y1 = map(int, input().split())
    P.append(p1)
    Y.append(y1)
    
y = np.argsort(P)
yy = [P[i] for i in y]
nn = [0] + [len(list(j)) for i, j in groupby(yy)]
n = list(accumulate(nn))
city = [np.argsort(yy[n[i]:n[i+1]]) for i in range(len(n)-1)]

k = []
for i in range(1,len(n)):
    for j in range(nn[i]):
        k.append(str(i).rjust(6,"0") + str(city[i-1][j]+1).rjust(6,"0"))
    
ans = [0] * M    
for i in range(M):
    ans[y[i]] = k[i]
    
for i in range(M):
    print(ans[i])