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:
from collections import defaultdict
n,m = [int(x) for x in input().split()]
l = [input().split() for _ in range(m)]
d = defaultdict(list)
for p,y in l:
    d[p].append(y)
print(d)
for p,y in l:
    i = list(sorted(d[p])).index(y)
    print("%05d%05d" % (int(p), i + 1))

Submission status: Wrong Answer

Solution code:
from collections import defaultdict
n,m = [int(x) for x in input().split()]
l = [input().split() for _ in range(m)]
d = defaultdict(list)
for p,y in l:
    d[p].append(y)
print(d)
for p,y in l:
    i = list(sorted(d[p])).index(y)
    print("%05d%05d" % (int(p), i))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
import numpy as np 
n , m = map(int, input().split())
l = np.array([list(map(int, input().split())) for _ in range(m)])
l2 = np.zeros(m)

l = np.sort(l , axis = 0)
l2 = l[:,0]*(10**6) + l[:,1]
l2 = np.sort(l2)

l2[0] = l[0,0]*(1000000) + 1
j = 2
for i in range(1,m):
    if l[i-1,0] == l[i,0]:
        l2[i] = l[i,0]*1000000 + j
        j += 1
    else :
        l2[i] = l[i,0]*1000000 + 1
        j = 2

for i in l2 :
    print('{0:012d}'.format(i))

Submission status: Wrong Answer

Solution code:
import numpy as np 
n , m = map(int, input().split())
l = np.array([list(map(int, input().split())) for _ in range(m)])
l2 = np.zeros(m)

l2 = l[:,0]*(10**6) + l[:,1]
l2 = np.sort(l2)

j = 1000000
k = 1
for i in range(m):
    if j+1000000 > l2[i]:
        l2[i] = j + k
        k += 1
    else :
        j += 1000000
        l2[i] = j + 1
        k = 2

for i in l2 :
    print('{0:012d}'.format(i))

Submission status: Wrong Answer

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

info_list = []

for i in range(m):
    pi, yi = map(int, input().split())
    info_list.append([i+1, pi, yi])
print(info_list)

from operator import itemgetter
info_list.sort(key = itemgetter(2))
print(info_list)


xth = [1 for i in range(1, n+1)]
print(xth)

for info in info_list:
    info.append(str(info[1]).zfill((6)) + str(xth[info[1]-1]).zfill(6))
    xth[info[1]-1]+=1


info_list.sort(key = itemgetter(0))

for ele in info_list:
    print(ele[3])

Submission status: Wrong Answer

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

info_list = []

for i in range(m):
    pi, yi = map(int, input().split())
    info_list.append([i, pi, yi])
print(info_list)

from operator import itemgetter
info_list.sort(key = itemgetter(1))
info_list.sort(key = itemgetter(2))
print(info_list)

p = info_list[0][1]
j = 1
for ele in info_list:
    if ele[1] == p:
        ele.append(str(ele[1]).zfill(6) + str(j).zfill(6))
        j+=1
    else:
        p+=1
        j=1
        ele.append(str(ele[1]).zfill(6) + str(j).zfill(6))

info_list.sort(key = itemgetter(0))

for ele in info_list:
    print(ele[3])

Submission status: Wrong Answer

Solution code:
def ins(arr, x):
    b=len(arr)-1
    a=0
    while (b-a)>1:
        m=int((a+b)/2)
        if x>=arr[m]:
            a=m
        else:
            b=m      
    if b==-1:
        return 0
    elif arr[b]<x:
        return b+1
    elif arr[a]>x:
        return a
    
    return b

N,M=map(int,input().split(' '))
ys=(tuple(map(int,input().split(' '))) for i in range(M))

citys=[[] for i in range(N)]
dic={}
for y in ys:
    ci=y[0]-1
    index=ins(citys[ci], y[1])
    citys[ci].insert(index, y[1])

for city in citys:
    for i in range(len(city)):
        dic[city[i]]=i+1
        
for y in ys:
    number=str(10**12+y[0]*10**6+dic[y[1]])[-12:]
    print(number)

Submission status: Wrong Answer

Solution code:
def ins(arr, x):
    b=len(arr)-1
    a=0
    while (b-a)>1:
        m=int((a+b)/2)
        if x>=arr[m]:
            a=m
        else:
            b=m      
    if b==-1:
        return 0
    elif arr[b]<x:
        return b+1
    return a

N,M=map(int,input().split(' '))
ys=[tuple(map(int,input().split(' '))) for i in range(M)]

citys=[[] for i in range(N)]
dic={}
for y in ys:
    ci=y[0]-1
    index=ins(citys[ci], y[1])
    citys[ci].insert(index, y[1])

for city in citys:
    for i in range(len(city)):
        dic[city[i]]=i+1

for y in ys:
    number=str(10**6+y[0])[-6:]+str(10**6+dic[y[1]])[-6:]
    print(number)

Submission status: Wrong Answer

Solution code:
def ins(arr, x):
    b=len(arr)-1
    a=0
    while (b-a)>1:
        m=int((a+b)/2)
        if x>=arr[m]:
            a=m
        else:
            b=m      
    if b==-1:
        return 0
    elif arr[b]<x:
        return b+1
    return a

N,M=map(int,input().split(' '))
ys=[tuple(map(int,input().split(' '))) for i in range(M)]

citys=[[] for i in range(N)]
dic={}
for y in ys:
    ci=y[0]-1
    index=ins(citys[ci], y[1])
    citys[ci].insert(index, y[1])

for city in citys:
    for i in range(len(city)):
        dic[city[i]]=i+1

for y in ys:
    number=str(10**12+y[0]*10**6)[-12:]+str(dic[y[1]])[-6:]
    print(number)

Submission status: Wrong Answer

Solution code:
def ins(arr, x):
    b=len(arr)-1
    a=0
    while (b-a)>1:
        m=int((a+b)/2)
        if x>=arr[m]:
            a=m
        else:
            b=m      
    if b==-1:
        return 0
    elif arr[b]<x:
        return b+1
    return a

N,M=map(int,input().split(' '))
ys=[tuple(map(int,input().split(' '))) for i in range(M)]

citys=[[] for i in range(N)]
dic={}
for y in ys:
    ci=y[0]-1
    index=ins(citys[ci], y[1])
    citys[ci].insert(index, y[1])

for city in citys:
    for i in range(len(city)):
        dic[city[i]]=i+1

for y in ys:
    number=str(10**12+dic[y[1]]+y[0]*10**6)[-12:]
    print(number)

Submission status: Wrong Answer

Solution code:
def ins(arr, x):
    b=len(arr)-1
    a=0
    while (b-a)>1:
        m=int((a+b)/2)
        if x>=arr[m]:
            a=m
        else:
            b=m      
    if b==-1:
        return 0
    elif arr[b]<x:
        return b+1
    return a
N,M=map(int,input().split(' '))
ys=[tuple(map(int,input().split(' '))) for i in range(M)]
citys=[[] for i in range(N)]
dic={}
for y in ys:
    ci=y[0]-1
    index=ins(citys[ci], y[1])
    citys[ci].insert(index, y[1])
for city in citys:
    for i in range(len(city)):
        dic[city[i]]=i+1
for y in ys:
    number=str(10**12+dic[y[1]]+y[0]*10**6)[1:]
    print(number)

Submission status: Wrong Answer

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

prefectures = []

i = 0
while i < m:
    p, y = map(int, input().split())
    prefectures.append((i, p, y))
    i += 1
prefectures.sort(key=lambda x: x[2])

answers = []
pre_id = 0
rank = 1
for i, p, y in prefectures:
    if p != pre_id:
        pre_id = p
        rank = 1
    answers.append((i, str(p).zfill(6) + str(rank).zfill(6)))
    rank += 1

answers.sort()

for i, answer in answers:
    print(answer)

Submission status: Wrong Answer

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

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

pref_s = sorted(pref, key = lambda p:p[1],reverse=True)
p_counter = [0 for i in range(n + 1)]

while True:
    try:
        city = pref_s.pop()
        p_counter[city[0]] += 1
        print("{0:06}{1:06}".format(city[0],p_counter[city[0]]))
    except:
        break

Submission status: Wrong Answer

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

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

pref_s = sorted(pref, key = lambda p:p[1])
p_counter = [0 for i in range(n + 1)]

while True:
    try:
        city = pref_s.pop(0)
        p_counter[city[0]] += 1
        print("{0:06}{1:06}".format(city[0],p_counter[city[0]]))
    except:
        break

Submission status: Wrong Answer

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

pref = []
while m > 0:
    p,y = input().split()
    pref.append((int(p), int(y)))
    m -= 1

pref_s = sorted(pref, key = lambda p:p[1])
p_counter = [0 for i in range(n + 1)]

while True:
    try:
        city = pref_s.pop(0)
        p_counter[city[0]] += 1
        print("{0:06}{1:06}".format(city[0],p_counter[city[0]]))
    except:
        break

Submission status: Wrong Answer

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

num = {}
for i in range(M):
    P_i, Y_i = map(int, input().split())
    if P_i in num:
        num[P_i].append((Y_i, i))
    else:
        num[P_i] = [(Y_i, i)]

display = [0] * M
for i in num.keys():
    k = str(0) * (6 - len(str(i))) + str(i)
    for index, j in enumerate(sorted(num[i], key=lambda x: x[0])):
        l = str(0) * (6 - len(str(index))) + str(index + 1)
        display[j[1]] = k + l

for item in display:
    print(item)

Submission status: Wrong Answer

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

num = {}
for i in range(M):
    P_i, Y_i = map(int, input().split())
    if P_i in num:
        num[P_i].append((Y_i, i))
    else:
        num[P_i] = [(Y_i, i)]

display = [0] * M
for i in num.keys():
    k = str(0) * (6 - len(str(i))) + str(i)
    for index, j in enumerate(sorted(num[i], key=lambda x: x[0])):
        l = str(0) * (6 - len(str(index))) + str(index + 1)
        print(i, j)
        display[j[1]] = k + l

for item in display:
    print(item)

Submission status: Wrong Answer

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

num = {}
for i in range(M):
    P_i, Y_i = map(int, input().split())
    if P_i in num:
        num[P_i].append((Y_i, i))
    else:
        num[P_i] = [(Y_i, i)]

display = [0] * M
for i in sorted(num.keys()):
    k = str(0) * (6 - len(str(i))) + str(i)
    for index, j in enumerate(sorted(num[i], key=lambda x: x[0])):
        l = str(0) * (6 - len(str(index))) + str(index + 1)
        display[j[1]] = k + l

for item in display:
    print(item)

Submission status: Wrong Answer

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

p_y_list = []

for i in range(M):
    p_y_list.append(tuple(int(x) for x in input().split()))
p_y_list.sort(key = lambda x:x[1])
p_y_list.sort(key = lambda x:x[0])

p_y_id_list = []
p = p_y_list[0][0]
y_c = 1
for i in p_y_list:
    if i[0] == p:
        p_y_id_list.append((i[0],y_c))
        y_c += 1
    else:
        p = i[0]
        y_c = 1
        p_y_id_list.append((i[0],y_c))

p_y_id_list.sort(key = lambda x:x[0] , reverse =True)
p_y_id_list.sort(key = lambda x:x[1] , reverse =True)
for i in p_y_id_list:
    print(str(i[0]).rjust(6,"0") + str(i[1]).rjust(6,"0"))

Submission status: Wrong Answer

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

p_y_list = []

for i in range(M):
    p_y_list.append(tuple(int(x) for x in input().split()))
p_y_list.sort(key = lambda x:x[1])
p_y_list.sort(key = lambda x:x[0])

p_y_id_list = []
p = p_y_list[0][0]
y_c = 1
for i in p_y_list:
    if i[0] == p:
        p_y_id_list.append((i[0],y_c))
        y_c += 1
    else:
        p = i[0]
        y_c = 1
        p_y_id_list.append((i[0],y_c))

p_y_id_list.sort(key = lambda x:x[1] , reverse =True)
p_y_id_list.sort(key = lambda x:x[0] , reverse =True)
for i in p_y_id_list:
    print(str(i[0]).rjust(6,"0") + str(i[1]).rjust(6,"0"))

Submission status: Wrong Answer

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

for i in range(m):
    a,b=pre[i][0],pre[i][1]
    s_pre[a-1].append(b)
    s_pre[a-1].sort()

for i in range(m):
    a=pre[i][0]
    for j in range(len(s_pre[a-1])):
        if s_pre[pre[i][0]-1][j]==pre[i][1]:
            print('{:0=4}'.format(pre[i][0]),'{:0=4}'.format(j+1),sep="")

Submission status: Wrong Answer

Solution code:
N,M = map(int,input().split())
t = [[] for i in range(N)]
ans = []
for i in range(M): 
    p,y = map(int,input().split())
    t[p-1].append([y,i])
    ans.append('')
for i in range(N):
    t[i].sort(key=lambda x:x[0])
    for j in range(len(t[i])):
        ans[t[i][j][1]] = '0'*(6-(len(str(i+1))))+str(i+1)+'0'*(6-(len(str(j))))+str(j+1)
for i in range(M):
    print(ans[i])

Submission status: Wrong Answer

Solution code:
N,M = map(int,input().split())
t = [[] for i in range(N)]
ans = []
for i in range(M): 
    p,y = map(int,input().split())
    t[p-1].append([y,i])
    ans.append('')
for i in range(N):
    t[i].sort(key=lambda x:x[0])
    for j in range(len(t[i])):
        ans[t[i][j][1]] = '0'*(6-(len(str(i))))+str(i+1)+'0'*(6-(len(str(j))))+str(j+1)
for i in range(M):
    print(ans[i])

Submission status: Wrong Answer

Solution code:
def main():
    '''
    メイン関数
    '''
    # 入力を取得
    N, M = map(int, input().split())

    PY_list = []
    PY_dict = {}
    P_list = []
    Y_list = []

    for i in range(0,M) :
        P, Y = map(int, input().split())
        P_list.append(P)        
        Y_list.append(Y)
        PY_list.append((P,Y))

    # 県の集合
    P_set = set(P_list)
    print(P_set)
    # 県ごとに、県と年の連結文字のリストを作り、ソートする
    for P in P_set :
        P_t_list = [ str(PY[0])+str(PY[1]) for PY in PY_list if PY[0] == P]
        P_t_list.sort()
        #         
        for PY in PY_list :
            if PY[0] == P :
                PY_dict[str(PY[0])+str(PY[1])] = P_t_list.index(str(PY[0])+str(PY[1])) + 1
        




    for PY in PY_list :
        P_0padding = '{0:06d}'.format(PY[0])
        Y_0padding = '{0:06d}'.format(PY_dict[str(PY[0])+str(PY[1])])
        print(P_0padding+Y_0padding)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import sys
from itertools import chain


s = sys.stdin.readlines()
n, m = map(int, s[0].split())
table = [list(chain([i], py.split())) for i, py in zip(range(m), s[1:])]

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

_i = table[0][0]
_p = table[0][1]
count = 1
result = [[_i, _p, count]]

for i, p, _ in table[1:]:
    if p == _p:
        count += 1
    else:
        count = 1
        _p = p
    result.append([i, p, count])

result.sort(key=lambda x: x[0])
print('\n'.join([str(p).rjust(6, '0') + str(count).rjust(6, '0') for _, p, count in result]))

Submission status: Wrong Answer

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

P = [0]*M
Y = [0]*M

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

A = [0]*M
C = [0]*M

B = [0]*M
for i in range(M):
    B[i] = Y[i]*100000+i

B.sort()

for i in range(M):
    d = B[i] % 100000
    k = P[d] - 1

    C[d] = A[k]
    A[k] += 1

for i in range(M):
    print('%06d%06d' % (P[i],C[i]+1))

Submission status: Wrong Answer

Solution code:
N, M = [int(i) for i in input().split()]
PY = []
for i in range(M):
    PY.append([int(j) for j in input().split()] + [i] + [str(0) * 12])

PY.sort(key=lambda x: x[1] + x[0] * 10 ** 10)
# PY.sort(key=lambda x: x[0])

count = 1
pre = PY[0][0]
for i in PY:
    if pre != i[0]:
        count = 1
        pre = i[0]
        i[3] = str(pre).zfill(6) + str(count).zfill(6)
    else:
        i[3] = str(pre).zfill(6) + str(count).zfill(6)
        count += 1

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

Submission status: Wrong Answer

Solution code:
n, m = map(int, input().split())
i_p_y_pairs = [tuple(map(int, (("%d " % i) + input()).split())) for i in range(m)]
i_p_y_pairs.sort(key=(lambda i_p_y: i_p_y[2]))

ret = []
current_p_idx = 0
current_p = i_p_y_pairs[current_p_idx][1]
for idx in range(m):
    p = i_p_y_pairs[idx][1]
    if p != current_p:
        current_ipy_pairs = i_p_y_pairs[current_p_idx:idx]
        current_ipy_pairs.sort(key=lambda ipy: ipy[2])
        for _idx_, ipy in enumerate(current_ipy_pairs):
            ret.append((ipy[0], "%06d" % current_p + "%06d" % (_idx_+1)))
        current_p_idx = idx
        current_p = i_p_y_pairs[current_p_idx][1]
else:
    current_ipy_pairs = i_p_y_pairs[current_p_idx:]
    current_ipy_pairs.sort(key=lambda ipy: ipy[2])
    for _idx_, ipy in enumerate(current_ipy_pairs):
        ret.append((ipy[0], ("%06d" % current_p + "%06d" % (_idx_+1))))

ret.sort(key=lambda x: x[0])
for r in ret:
    print(r[1])

Submission status: Wrong Answer

Solution code:
n, m = map(int, input().split())
i_p_y_pairs = [tuple(map(int, (("%d " % i) + input()).split())) for i in range(1, m+1)]
i_p_y_pairs.sort(key=(lambda i_p_y: i_p_y[2]))

ret = []
current_p = i_p_y_pairs[0][1]
current_p_idx = 0
for idx in range(m):
    p = i_p_y_pairs[idx][1]
    if p != current_p:
        current_ipy_pairs = i_p_y_pairs[current_p_idx:idx]
        current_ipy_pairs.sort(key=lambda i_p_y: i_p_y[2])
        for _idx_, ipy in enumerate(current_ipy_pairs):
            ret.append((ipy[0], "%06d" % current_p + "%06d" % (_idx_+1)))
        current_p_idx = idx
else:
    current_ipy_pairs = i_p_y_pairs[current_p_idx:]
    current_ipy_pairs.sort(key=lambda i_p_y: i_p_y[2])
    for _idx_, ipy in enumerate(current_ipy_pairs):
        ret.append((ipy[0], "%06d" % current_ipy_pairs[0][1] + "%06d" % (_idx_+1)))

ret.sort(key=lambda x: x[0])
for r in ret:
    print(r[1])

Submission status: Wrong Answer

Solution code:
N,M=map(int,input().split())
P=[]
Y=[]
cities=[]
for i in range(M):
    try:
        s = input()
        p,y = s.split()
        city=(p,y)
        cities.append(city) 
        P.append(p)
        Y.append(y)
 
    except:
        break
sort_city=sorted(cities,key=lambda x:(x[0],x[1]))
prefs = sorted(set(P))
 
a=0
b=0
for i in sort_city:
    if i[0]==b:
        a+=1
    else:
        a=1
        b=i[0]
    print(str(i[0]).rjust(6,'0')+str(a).rjust(6,'0'))

Submission status: Wrong Answer

Solution code:
n,m = map(int,input().split())
l = [list(map(int,input().split())) for i in range(m)]
s = []
for i in enumerate(l):
    s.append(i)
a = 1
for i in range(m):
    if i==0:
        s[0][1][1]=1
    elif s[i][1][0]==s[i-1][1][0]:
        a+=1
        s[i][1][1]=a
    elif s[i][1][0] != s[i-1][1][0]:
        a=1
        s[i][1][1]=a
s = sorted(s,key=lambda x:x[0])
for i in s:
    print('%06d'%i[1][0]+'%06d'%i[1][1])

Submission status: Wrong Answer

Solution code:
import copy

n, m = input().strip().split(' ')
n, m = [int(n), int(m)]

p = []
y = []

for i in range(m):
    a, b = input().strip().split(' ')
    a, b = [int(a), int(b)]
    p.append(a)
    y.append(b)

z = copy.deepcopy(y)

for i in range(len(z)-1):
    for j in range(i, len(z)-2, 1):
        if z[j] > z[j + 1]:
            tmp = z[j]
            z[j] = z[j + 1]
            z[j + 1] = tmp

min = []
order = []

for i in range(n):
    min.append(0)
    
for i in range(m):
    order.append(0)
    
for i in range(m):
    for j in range(m):
        if z[i] == y[j]:
            min[p[j] - 1] += 1
            order[j] = min[p[j] - 1]

def addzero(a):
    str = ''
    for i in range(6 - len(a)):
        str += '0'
    return str

for i in range(m):
    print(addzero(str(p[i])) + str(p[i]) + addzero(str(order[i])) + str(order[i]))

Submission status: Wrong Answer

Solution code:
N, M = [int(i) for i in input().split()]
PY = []
for i in range(M):
    PY.append([int(j) for j in input().split()] + [i] + [str(0) * 12])

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

count = 1
pre = PY[0][0]
for i in PY:
    if pre != i[0]:
        count = 1
        pre = i[0]
        i[3] = str(pre).zfill(6) + str(count).zfill(6)
    else:
        i[3] = str(pre).zfill(6) + str(count).zfill(6)
        count += 1

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

Submission status: Wrong Answer

Solution code:
import sys

def solve(M,list_PY,list_Y):
    for i in range(M):
        ken = str(list_PY[i][0]).zfill(6)
        ban = str(list_Y[list_PY[i][0]-1].index(list_PY[i][1])+1).zfill(6)
        print(ken + ban)

def readQuestion():
    N,M = map(int, sys.stdin.readline().strip().split())
    list_PY = []#[[P1,Y1],[P2,Y2]...[Pn,Yn]]のリストを作る用
    list_Y = [[] for i in range(N)]#リストの中にN（県の数）個リストを作る
    
    for i in range(M):
        P,Y = map(int, sys.stdin.readline().strip().split())
        list_PY.append([P,Y])
        list_Y[P-1].append(Y)#「県の名前-1」を添え字にしてリストに入れる

    for i in range(N):
        if len(list_Y[i]) > 1:
            list_Y[i].sort()
            print("sort",list_Y)
    return (M, list_PY, list_Y)

def main():
    M, list_PY, list_Y = readQuestion()
    answer = solve(M, list_PY, list_Y)
    return answer

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

    sorted_P_Y_list = sorted(P_Y_list, key=lambda x:(int(x[0]), int(x[1])))
    correspond_sort_index_list = [P_Y_list.index(ele) for ele in sorted_P_Y_list]

    same_id = sorted_P_Y_list[0][0]
    counter = 1

    for element_list in sorted_P_Y_list:
        if same_id != element_list[0]:
            counter = 1
            same_id = element_list[0]

        element_list[1] = str(counter)
        counter += 1

    id_list = list(map(lambda sorted_P_Y_tuple: int(sorted_P_Y_tuple[0] + sorted_P_Y_tuple[1].zfill(6)), sorted_P_Y_list))
    for id in correspond_sort_index_list:
        print("%012d"%id_list[id])

if __name__ == "__main__":
    main()

Submission status: Wrong Answer

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

    sorted_P_Y_list = sorted(P_Y_list)
    correspond_sort_index_list = [P_Y_list.index(ele) for ele in sorted_P_Y_list]

    same_id = sorted_P_Y_list[0][0]
    counter = 1
    
    for element_list in sorted_P_Y_list:
        if same_id != element_list[0]:
            counter = 1
            same_id = element_list[0]

        element_list[1] = str(counter)
        counter += 1

    id_list = list(map(lambda sorted_P_Y_tuple: int(sorted_P_Y_tuple[0] + sorted_P_Y_tuple[1].zfill(6)), sorted_P_Y_list))
    for id in correspond_sort_index_list:
        print("%012d"%id_list[id])

if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
def main():
    n, m = map(int, input().split())
    P_Y_list = sorted([input().split() for i in range(m)])

    tmp = P_Y_list[0][0]
    counter = 1
    for element_list in P_Y_list:
        if tmp != element_list[0]:
            counter = 1
            tmp = element_list[0]
        element_list[1] = str(counter)
        counter += 1

    id_list = list(map(lambda P_Y_tuple: int(P_Y_tuple[0] + P_Y_tuple[1].zfill(6)), P_Y_list))
    for id in id_list:
        print("%012d"%id)

if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
# coding: utf-8
# N : 県の数, M: 市の数

N, M = map(int, input().split())
ps, ys = [], []

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

for i in range(M):
    p, y = map(int, input().split())
    ps += [p]; ys += [y];
    v[p].append(y)

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


print (ps)
print (ys)

print (v)

for i in range(M):
    print("{:06d}".format(ps[i]), end="")
    print("{:06d}".format(v[ps[i]].index(ys[i])+1))

Submission status: Wrong Answer

Solution code:
Data = list(map(int, input().split()))
N = Data[0]
M = Data[1]
del(Data)
Data = []
for i in range(M):
  Data.append(list(map(int, input().split())))
  Data[i].append(i)
Data.sort()
Cnt = 0
Num = 0
for i in range(M):
  if Num == Data[i][0]:
    Cnt += 1
  else:
    Cnt = 1
    Num = Data[i][0]
  Data[i].append(Cnt)
Data.sort(key=lambda x:x[2])

for i in range(M):
  print(format(Data[i][0], '06x') + format(Data[i][3], '06x'))

Submission status: Wrong Answer

Solution code:
Data = list(map(int, input().split()))
N = Data[0]
M = Data[1]
del(Data)
Data = []
for i in range(M):
  Data.append(list(map(int, input().split())))
Data.sort()
Cnt = 0
Num = 0
Str = ""
for i in range(M):
  if Num == Data[i][0]:
    Cnt += 1
  else:
    Cnt = 1
    Num = Data[i][0]
  Str = format(Num, '06x') + format(Cnt, '06x')
  print(Str)

Submission status: Wrong Answer

Solution code:
import sys
def solve(n,m,a,b):
    ans = ""
    #b = [[] for i in range(n)]
    #for s1,s2 in a:
    #    b[s1-1].append(s2)
    for i in range(len(b)):
        b[i].sort()
    for i in range(m):
        ans += str(a[i][0]).zfill(6) + str(b[a[i][0]-1].index(a[i][1])+1).zfill(6) + "\n"
    return ans

def readQuestion():
    ws = sys.stdin.readline().strip().split()
    N = int(ws[0])
    M = int(ws[1])
    ls_PY = []
    ls_b = [[] for i in range(N)]
    for i in range(M):
        p,y = map(int, sys.stdin.readline().strip().split())
        ls_PY.append([p,y])
        ls_b[p-1].append(y)
    #ls_PY = [list(map(int, sys.stdin.readline().strip().split())) for j in range(M)]
    return (N, M, ls_PY, ls_b)

def main():
    N, M, ls_PY, ls_b = readQuestion()
    answer = solve(N, M, ls_PY, ls_b)
    print(answer)

#if __name__ == '__main__':
#    main()

Submission status: Wrong Answer

Solution code:
ken_shi_list = input().split()
ken_num = int(ken_shi_list[0])
shi_num = int(ken_shi_list[1])

shi_list = []
nen_list = [[] for i in range(ken_num) ]


for i in range(shi_num):
    shi_list.append(input().split())
    nen_list[int(shi_list[i][0])-1].append( int(shi_list[i][1]) )


for i in range(ken_num):
   nen_list[i].sort()

for i in range(shi_num):
    ken = int(shi_list[i][0])
    nen = int(shi_list[i][1])
    for j in range( len(nen_list[ken-1]) ):
        if nen == nen_list[ken-1][j] :
            print( str(ken).zfill(6) + str(j+1).zfill(6) )
            nen_list[ken-1].pop(j)
            break

Submission status: Wrong Answer

Solution code:
import sys

def solve(N, T, ls_ct):
    radi={}
    radi2={}
    for line in ls_ct:
        if line[0] not in radi:
            radi[line[1]] = line[0]
        if line[0] not in radi2:
            radi2[line[0]] = [line[1]]
        else:
            radi2[line[0]].append(line[1])
    #print(radi)
    #print(radi2)
    
    re=[i for i in radi2.values()]
    for i in range(len(re)):
        re[i].sort()
    #print(re)
    redic={}
    for i in range(len(re)):
        rank = 1
        for ii in re[i]:
            redic[ii] = rank
            rank += 1
    #print(redic)
    ans = []
    cnt = 0
    for i in radi.keys():
        a = str(radi[i]).zfill(6)
        b = str(redic[i]).zfill(6)
        ans.append(a + b)
        cnt += 1
    #print(radi)
    return  '\n'.join(ans)+"\n"

def readQuestion():
    ws = sys.stdin.readline().strip().split()
    N = int(ws[0])
    T = int(ws[1])
    ls_ct = [list(map(int, sys.stdin.readline().strip().split())) for j in range(T)]
    return (N, T, ls_ct)

def main():
    N, M, ls_PY = readQuestion()
    answer = solve(N, M, ls_PY)
    print(answer)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import sys

def solve(N, T, ls_ct):
    radi={}
    radi2={}
    for line in ls_ct:
        if line[0] not in radi:
            radi[line[1]] = line[0]
        if line[0] not in radi2:
            radi2[line[0]] = [line[1]]
        else:
            radi2[line[0]].append(line[1])
    #print(radi)
    #print(radi2)
    
    re=[i for i in radi2.values()]
    for i in range(len(re)):
        re[i].sort()
    #print(re)
    redic={}
    for i in range(len(re)):
        rank = 1
        for ii in re[i]:
            redic[ii] = rank
            rank += 1
    #print(redic)
    ans = []
    cnt = 0
    for i in radi.keys():
        a = str(radi[i]).zfill(6)
        b = str(redic[i]).zfill(6)
        ans.append(a + b)
        cnt += 1
    #print(radi)
    return  '\n'.join(ans)

def readQuestion():
    ws = sys.stdin.readline().strip().split()
    N = int(ws[0])
    T = int(ws[1])
    ls_ct = [list(map(int, sys.stdin.readline().strip().split())) for j in range(T)]
    return (N, T, ls_ct)

def main():
    N, M, ls_PY = readQuestion()
    answer = solve(N, M, ls_PY)
    print(answer)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
N, M = [int(i) for i in input().split()]
pyList = [[int(i) for i in input().split()] for _ in range(M)]
pyList = sorted(pyList, key=lambda py: py[1])

cityMap = {}
for py in pyList:
    if py[0] in cityMap.keys():
        cityMap[py[0]] += 1
    else:
        cityMap[py[0]] = 1

    prefCd = str(py[0]).zfill(6)
    cityCd = str(cityMap[py[0]]).zfill(6)
    print(prefCd + cityCd)

Submission status: Wrong Answer

Solution code:
N, M = [int(i) for i in input().split()]
pyList = [[int(i) for i in input().split()] for _ in range(M)]
pyList = sorted(pyList, key=lambda py: py[1])

cityMap = {}
for py in pyList:
    if py[0] in cityMap.keys():
        cityMap[py[0]] += 1
    else:
        cityMap[py[0]] = 1

    prefCd = str(py[0]).zfill(6)
    cityCd = str(cityMap[py[0]]).zfill(3)
    print(prefCd + cityCd)

Submission status: Wrong Answer

Solution code:
import sys

def solve(N, T, ls_ct):
    radi={}
    radi2={}
    for line in ls_ct:
        if line[0] not in radi:
            radi[line[1]] = line[0]
        elif line[0] in radi:
            radi[line[1]] = line[0]
        if line[0] not in radi2:
            radi2[line[0]] = [line[1]]
        else:
            radi2[line[0]].append(line[1])
    re=[i for i in radi2.values()]
    for i in range(len(re)):
        re[i].sort()
    redic={}
    for i in range(len(re)):
        rank = 1
        for ii in re[i]:
            redic[ii] = rank
            rank += 1
    ans = []
    cnt = 0
    for i in radi.keys():
        a = str(radi[i]).zfill(6)
        b = str(redic[i]).zfill(6)
        ans.append(a + b)
        cnt += 1
    return  '\n'.join(ans)

def readQuestion():
    ws = sys.stdin.readline().strip().split()
    N = int(ws[0])
    T = int(ws[1])
    ls_ct = [list(map(int, sys.stdin.readline().strip().split())) for j in range(T)]
    return (N, T, ls_ct)

def main():
    print(solve(*readQuestion()))
main()