TnT/Multi_CodeNet4Repair huggingface dataset:
Problem: 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.

Submission attempts (in order):
# coding:utf-8

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

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

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

for _ in range(M):
    pi, yi = map(int, input().split())
    DIC[pi].append(yi)
    NUM_DIC[pi] += 1


for pi in range(1, N+1):
    DIC[pi].sort(reverse=True)

counter = 1
while True:
    flg = False
    for pi in range(1, N+1):
        if NUM_DIC[pi] >= counter:
            flg = True
            DIC[pi]
            id = gen_id(pi) + gen_id(counter)
            print(id)
    counter += 1
    if flg != True:
        break



# coding:utf-8

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

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

DIC = dict()
CITY = []

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

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


for pi in range(1, N+1):
    DIC[pi] = sorted(DIC[pi], key=lambda x: x["y"])


for pi in range(1, N+1):
    for index, city in enumerate(DIC[pi]):
        id = gen_id(city["p"]) + gen_id(index+1)
        city["id"] = id
        CITY.append(city)


x =sorted(CITY, key=lambda x: x["i"])

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



Verdicts: Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
N, M = map(int, input().split())

    
py = [list(map(int, input().split())) for i in range(M)]
py.sort()
cnt = 1
pre = py[0][0]
ans = '0' * (6 - len(str(py[0][0]))) + str(py[0][0]) + '0' * 5 + '1'
cnt += 1
print(ans)
for i in range(1, M):
    
    if py[i][0] != pre:
        cnt = 1
    pre = py[i][0]
    ans = '0' * (6 - len(str(py[i][0]))) + str(py[i][0])
    ans += '0' * (6 - len(str(cnt))) + str(cnt)
    cnt += 1
    print(ans)

N, M = map(int, input().split())
py = []
d = {}
for i in range(M):
    p, y = map(int, input().split())
    py.append([p, y])
    if p not in d:
        d[p] = [y]
    else:
        d[p].append(y)
for key in d.keys():
    d[key].sort()
from bisect import bisect_left
for i in range(M):
    p, y = py[i]
    a = bisect_left(d[p], y)
    ans = '0' * (6 - len(str(p))) + str(p)
    ans += '0' * (6 - len(str(a + 1))) + str(a + 1)
    print(ans)

Verdicts: Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
n,m=map(int,input().split())
li=[[] for i in range(n+1)]

for i in range(m):
	j,k=map(int,input().split())
	li[j].append(k)

for i in range(1,m):
	li[i].sort()
	for j in li[i]:
		print(str(i).zfill(6)+str(j).zfill(6))

def main():
    n, m = map(int, input().split())
    p, y = [0 for i in range(m)], [0 for i in range(m)]
    for i in range(m):
        p[i], y[i] = map(int, input().split())
    ans = solve(n, m, p, y)


def solve(n, m, p, y):
    kens = [[] for i in range(n + 1)]
    for i in range(m):
        kens[p[i]].append(y[i])
    for ken in kens:
        ken.sort()
    
    
    ids = [{} for i in range(n + 1)]
    for indken, ken in enumerate(kens):
        for indsi, yi in enumerate(ken, 1):
            ids[indken][yi] = str(indken).zfill(6) + str(indsi).zfill(6)
    
    
    for i in range(m):
        print(ids[p[i]][y[i]])

    return

if __name__ == '__main__':
    main()

Verdicts: Runtime Error

Accepted
Problem: 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.

Submission attempts (in order):
import numpy as np


def solve(string):
    n, m, *py = map(int, string.split())
    p = [[] for _ in range(n)]
    for _p, _y in py:
        p[_p - 1].append(_y)
    for i in range(n):
        p[i] = np.argsort(np.argsort(p[i]))
    counter = [0 for _ in range(n)]
    for _p, _y in py:
        t = "{:06}{:06}".format(_p, p[_p - 1][counter[_p - 1]] + 1)
        print(t)
        counter[_p - 1] += 1
        p[i] = np.argsort(np.argsort(p[i]))


if __name__ == '__main__':
    n, m = map(int, input().split())

    print(solve("{} {}\n".format(n, m) + "\n".join([input() for _ in range(m)])))


import numpy as np


n, m = map(int, input().split())
py = [list(map(int, input().split())) for _ in range(m)]
p = [[] for _ in range(n)]
start = time.time()
for _p, _y in py:
    p[_p - 1].append(_y)
for i in range(n):
    p[i] = np.argsort(np.argsort(p[i]))

counter = [0 for _ in range(n)]
for _p, _y in py:
    t = "{:06}{:06}".format(_p, p[_p - 1][counter[_p - 1]] + 1)
    print(t)
    counter[_p - 1] += 1


import numpy as np


def solve(string):

    n, m, *py = map(int, string.split())
    py = [(_p, _y) for _p, _y in zip(py[0::2], py[1::2])]
    p = [[] for _ in range(n)]
    for _p, _y in py:
        p[_p - 1].append(_y)
    for i in range(n):
        p[i] = np.argsort(np.argsort(p[i]))

    counter = [0 for _ in range(n)]
    ans = []
    for _p, _y in py:
        ans.append("{:06}{:06}".format(_p, p[_p - 1][counter[_p - 1]] + 1))
        counter[_p - 1] += 1
    return "\n".join(ans)


if __name__ == '__main__':
    n, m = map(int, input().split())
    print(solve("{} {}\n".format(n, m) + "\n".join([input() for _ in range(m)])))


Verdicts: Runtime Error

Runtime Error

Accepted
Problem: 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.

Submission attempts (in order):
# -*-coding: utf-8 -*-

import sys

def main():
    input = sys.stdin.readline
    n, m = map(int, input().split())
    y_dict = {}
    ken_dict = {}
    for i in range(m):
        p_i, y_i = map(int, input().split())
        y_dict[y_i] = []
        y_dict[y_i].append(p_i)

        if not p_i in ken_dict:
            ken_dict[p_i] = []
            ken_dict[p_i].append(y_i)
        else:
            ken_dict[p_i].append(y_i)


    for key in ken_dict.keys():
        ken_dict[key].sort()
        print(ken_dict[key])
        for i,value in enumerate(ken_dict[key]):
            i += 1
            y_dict[value].append(i)
    
    for value in y_dict.values():
        print(str(value[0]).rjust(6, '0') + str(value[1]).rjust(6, '0'))
    
    return


if __name__ == '__main__':
    main()

# -*-coding: utf-8 -*-

import sys

def main():
    input = sys.stdin.readline
    n, m = map(int, input().split())
    y_dict = {}
    ken_dict = {}
    for i in range(m):
        p_i, y_i = map(int, input().split())
        y_dict[y_i] = []
        y_dict[y_i].append(p_i)

        if not p_i in ken_dict:
            ken_dict[p_i] = []
            ken_dict[p_i].append(y_i)
        else:
            ken_dict[p_i].append(y_i)


    for key in ken_dict.keys():
        ken_dict[key].sort()
        for i,value in enumerate(ken_dict[key]):
            i += 1
            y_dict[value].append(i)
    
    for value in y_dict.values():
        print(str(value[0]).rjust(6, '0') + str(value[1]).rjust(6, '0'))
    
    return

# -*-coding: utf-8 -*-

import sys

def main():
    input = sys.stdin.readline
    n, m = map(int, input().split())
    y_dict = {}
    ken_dict = {}
    for i in range(m):
        p_i, y_i = map(int, input().split())
        y_dict[y_i] = []
        y_dict[y_i].append(p_i)

        if not p_i in ken_dict:
            ken_dict[p_i] = []
            ken_dict[p_i].append(y_i)
        else:
            ken_dict[p_i].append(y_i)


    for key in ken_dict.keys():
        ken_dict[key].sort()
        for i,value in enumerate(ken_dict[key]):
            i += 1
            y_dict[value].append(i)
    
    for value in y_dict.values():
        print(str(value[0]).zfill(6) + str(value[1]).zfill(6))
    
    return


if __name__ == '__main__':
    main()

Verdicts: Wrong Answer

Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
N, M = map(int, input().split())
from bisect import bisect_right
dic = [[] for i in range(N)]

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

for j in range(M):
    p, y = shi[j]
    print('{:06}{:06}'.format(p, bisect_right(dic[p-1], y)))



N, M = map(int, input().split())
from bisect import bisect_right
dic = [[] for i in range(N)]

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

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

for j in range(M):
    p, y = shi[j]
    print('{:06}{:06}'.format(p, bisect_right(dic[p-1], y)))



Verdicts: Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
N, M = map(int, input().split())
X = [list(map(int, input().split())) for _ in range(M)]
X.sort()

city = X[0][0]
num = 0
for v in X:
    if city == v[0]:
        num += 1
    else:
        city = v[0]
        num = 1
    print('{:06}{:06}'.format(v[0], num))

N, M = map(int, input().split())
X = [list(map(int, input().split())) for _ in range(M)]
ans = [''] * M
num = [1] * N

for i, v in sorted(enumerate(X), key=lambda x: (x[1][0], x[1][1])):
    ans[i] = '{:06}{:06}'.format(v[0], num[v[0] - 1])
    num[v[0] - 1] += 1
    
print('\n'.join(ans))

Verdicts: Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
N, M = map(int, input().split())
lst = [list(map(int, input().split())) for _ in range(M)]
lst_city = [[] for _ in range(N)]

for i, y in lst:
    i -= 1
    lst_city[i].append(y)
else:
    lst_city[i].sort()
print(lst_city)


for i, y in lst:
    id_u = str(i).zfill(6)
    id_l = str(lst_city[i-1].index(y) + 1).zfill(6)
    ans = id_u + id_l
    print(ans)


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


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


ans = [None] * M
for pi, cities in enumerate(lst_city):
    for order, (y, i) in enumerate(sorted(cities)):
        ans[i] = str(pi).zfill(6) + str(order + 1).zfill(6)
print(*ans, sep="\n")

Verdicts: Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
N, M = map(int, input().split())
city = [0]*M
for i in range(M):
    city[i] = [i] * 4
    prefecture, year = map(int, input().split())
    city[i][0], city[i][1] = year, prefecture

city = sorted(city)
print(city)

print(city)
ite = [1] * (N+1)
for k in range(M):
    city[k][3] = ite[city[k][1]]
    ite[city[k][1]] += 1
city = sorted(city, key=lambda x: x[2])
for j in range(M):
    print("{:0=12}".format(city[j][1]*1000000+city[j][3]))  


N, M = map(int, input().split())
city = [0]*M
for i in range(M):
    city[i] = [i] * 4
    prefecture, year = map(int, input().split())
    city[i][0], city[i][1] = year, prefecture

city = sorted(city)

ite = [1] * (N+1)
for k in range(M):
    city[k][3] = ite[city[k][1]]
    ite[city[k][1]] += 1
city = sorted(city, key=lambda x: x[2])
for j in range(M):
    print("{:0=12}".format(city[j][1]*1000000+city[j][3]))  


Verdicts: Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
import heapq

N, M = map(int, input().split())
S = ["" for m in range(M)]

D = {}
for m in range(M):
    P, Y = map(int, input().split())
    listP = D.setdefault(P, [])
    heapq.heappush(listP, (Y, m))

print(D)

for p, l in D.items():
    for i in range(len(l)):
        y, m = heapq.heappop(l)
        S[m] = format(p, "06") + format(i + 1, "06")

for s in S:
    print(s)


import heapq

N, M = map(int, input().split())
S = ["" for m in range(M)]

D = {}
for m in range(M):
    P, Y = map(int, input().split())
    listP = D.setdefault(P, [])
    heapq.heappush(listP, (Y, m))

for p, l in D.items():
    for i in range(len(l)):
        y, m = heapq.heappop(l)
        S[m] = format(p, "06") + format(i + 1, "06")

for s in S:
    print(s)


Verdicts: Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
from collections import defaultdict
import bisect

pre = defaultdict(list)
ori = []
n, m = map(int, input().split())
for _ in range(m):
    x, y = map(int, input().split())
    pre[x].append(y)
    ori.append([x, y])

for key, val in pre.items():
    val.sort()

print(pre)
for i in range(m):
    l = pre[ori[i][0]]
    idx = bisect.bisect(l, ori[i][1])
    print(f'{ori[i][0]:06}{idx:06}')



from collections import defaultdict
import bisect

pre = defaultdict(list)
ori = []
n, m = map(int, input().split())
for _ in range(m):
    x, y = map(int, input().split())
    pre[x].append(y)
    ori.append([x, y])

for key, val in pre.items():
    val.sort()

for i in range(m):
    l = pre[ori[i][0]]
    idx = bisect.bisect(l, ori[i][1])
    print(f'{ori[i][0]:06}{idx:06}')



Verdicts: Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
from sys import stdin
def f(n,m):
    n,m=str(n),str(m)
    s1=["0"]*(6-len(n))
    s1.append(n)
    s2=["0"]*(6-len(m))
    s2.append(m)
    return "".join(s1)+"".join(s2)

def main():
    
    readline=stdin.readline
    N,M=map(int,readline().split())
    li=[0]*M
    for i in range(M):
        a=list(map(int,readline().split()))
        a.append(i)
        li[i]=a
    
    li.sort(key=lambda x:x[1])
    print(li)
    count=[1]*(N+1)
    for i in range(M):
        city_number=li[i][0]
        x=count[city_number]
        count[city_number]+=1
        li[i].append(f(city_number,x))

    li.sort(key=lambda x:x[2])
    for i in range(M):
        print(li[i][3])
        
if __name__=="__main__":
    main()

from sys import stdin
def f(n,m):
    n,m=str(n),str(m)
    s1=["0"]*(6-len(n))
    s1.append(n)
    s2=["0"]*(6-len(m))
    s2.append(m)
    return "".join(s1)+"".join(s2)

def main():
    
    readline=stdin.readline
    N,M=map(int,readline().split())
    li=[0]*M
    for i in range(M):
        a=list(map(int,readline().split()))
        a.append(i)
        li[i]=a
    
    li.sort(key=lambda x:x[1])
    count=[1]*(N+1)
    for i in range(M):
        city_number=li[i][0]
        x=count[city_number]
        count[city_number]+=1
        li[i].append(f(city_number,x))

    li.sort(key=lambda x:x[2])
    for i in range(M):
        print(li[i][3])
        
if __name__=="__main__":
    main()

Verdicts: Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
N,M=map(int,input().split())
L=[list(map(int,input().split())) for i in range(M)]
L.sort(key=lambda x:x[1])
L.sort(key=lambda x:x[0])
city_num=1#
#12 to 1
#32 to 2
inside_num=1
for i in range(M):
    if L[i][0]==city_num:
        L[i][1]=inside_num
        inside_num+=1
    else:
        city_num+=1
        inside_num=1
        L[i][1]=inside_num
        inside_num+=1
#print(L)
for l in L:
    print("{:0=6}{:0=6}".format(l[0],l[1]))#0 padding


N,M=map(int,input().split())
L=[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])
city_num=1#
#12 to 1
#32 to 2
inside_num=1
for i in range(M):
    while L[i][0]!=city_num:
        city_num+=1
        inside_num=1
    L[i][1]=inside_num
    inside_num+=1
#print(L)
L.sort(key=lambda x:x[2])
for l in L:
    print("{:0=6}{:0=6}".format(l[0],l[1]))#0 padding


Verdicts: Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
def main():
  n, m = map(int, input().split())
  def zs(num):
    k = 6 - len(str(num))
    return '0' * k + str(num)
  lst = [[-1] for i in range(n + 1)]
  cities = []
  for i in range(m):
    temp = tuple(map(int, input().split()))
    lst[temp[0]].append(temp[1])
    cities.append(temp)
  for l in lst:
    l.sort()
  print(lst)
  for tpl in cities:
    a = lst[tpl[0]].index(tpl[1])
    print(zs(tpl[0]) + zs(a))
if __name__ == '__main__':
  main()

n, m = map(int, input().split())
def zs(num):
    k = 6 - len(str(num))
    return '0' * k + str(num)
lst = []
for i in range(m):
  lst.append(tuple(map(int, input().split())))
slst = sorted(lst)
dic = {}
temp = 0
for i in range(m):
  if slst[i][0] == slst[i - 1][0]:
    temp += 1
  else:
    temp = 1
  dic[slst[i]] = zs(slst[i][0]) + zs(temp)
for i in lst:
  print(dic[i])

Verdicts: Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
n,m = map(int, input().split())
info = [[i] + list(map(int, input().split())) for i in range(1, m+1)]
city = sorted(set([info_i[0] for info_i in info]))



n,m = map(int, input().split())
info = [[i] + list(map(int, input().split())) for i in range(1, m+1)]
city = sorted(set([info_i[0] for info_i in info]))

sorted_info = sorted(info, key=lambda x:x[1])

print(sorted_info)

counter = 0

p = city.pop(0)

for i in range(m):
  if sorted_info[i][1] == p:
    counter += 1
    sorted_info[i].append(counter)
  else:
    p =  city.pop(0)
    counter = 1
    sorted_info[i].append(counter)

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

for res_i in result:
  print(str(res_i[1]).zfill(6) + str(res_i[3]).zfill(6))


from collections import defaultdict
from bisect import bisect

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

a = defaultdict(list)

for p_i in sorted(p):
  a[p_i[0]].append(p_i[1])
  
for p_i in p:
  x = p_i[0]
  y = bisect(a[x], p_i[1])
  
  print(str(x).zfill(6), str(y).zfill(6), sep='')

Verdicts: Wrong Answer

Runtime Error

Accepted
Problem: 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.

Submission attempts (in order):
n,m=map(int,input().split())

ans=[[] for i in range(m)]
p_list=[[] for i in range(n)]

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

 ans[i]=str(p).zfill(6)
 p_list[p].append([i,y])

for pp in p_list:
 pp=sorted(pp,key=lambda x:x[1])
 num=0
 for ppp in pp:
  num+=1
  ans[ppp[0]]+=str(num).zfill(6)
 num=0

for i in ans:
 print(i)

from sys import stdin
nii=lambda:map(int,stdin.readline().split())
lnii=lambda:list(map(int,stdin.readline()).split())

n,m=nii()

list=[[] for i in range(n+1)]

for i in range(m):
  p,y=nii()
  list[p].append([y,i])

ans=[]
for i in range(1,n+1):
  tl=list[i]
  s_tl=sorted(tl,key=lambda x:x[0])
  for j in range(len(tl)):
    town=s_tl[j][1]
    s1=str(i).zfill(6)
    s2=str(j+1).zfill(6)
    s=s1+s2
    ans.append([town,s])

ans.sort(key=lambda x:x[0])
for i,j in ans:
  print(j)

Verdicts: Runtime Error

Accepted
Problem: 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.

Submission attempts (in order):
def ABC113C():
    
    N, M = map(int, input().split())
    PY = [list(map(int, input().split())) for i in range(M)]
    P = [[] for i in range(10 ** 5)]

    from operator import itemgetter
    PY.sort(key = itemgetter(1))
    for k in range(len(PY)):
        i = PY[k][0]
        j = PY[k][1]
        P[i - 1].append([j, k])
    anslist = []
    for i in range(len(P)):
        for j in range(len(P[i])):
            anslist.append([i + 1, j + 1, P[i][j][1] + 1])
    anslist.sort(key = itemgetter(2))
    for i, j, k in anslist:
        i = str(i)
        j = str(j)
        while len(i) != 6:
            i = "0" + i
        while len(j) != 6:
            j = "0" + j
        print(i + j)
ABC113C()


def ABC113C():

    N, M = map(int, input().split())
    PY = [list(map(int, input().split())) for i in range(M)]
    P = [[] for i in range(10 ** 5)]

    from operator import itemgetter
    #PY.sort(key = itemgetter(1))
    for k in range(len(PY)):
        i = PY[k][0]
        j = PY[k][1]
        P[i - 1].append([j, k])

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

    anslist = []
    for i in range(len(P)):
        for j in range(len(P[i])):
            anslist.append([i + 1, j + 1, P[i][j][1] + 1])
    anslist.sort(key = itemgetter(2))
    for i, j, k in anslist:
        i = str(i)
        j = str(j)
        while len(i) != 6:
            i = "0" + i
        while len(j) != 6:
            j = "0" + j
        print(i + j)
ABC113C()

Verdicts: Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
n,m = map(int, input().split())
a = [list(map(int, input().split())) for i in range(m)]
c = [0]*n
for i in a:
  p,y = i[0],i[1]
  c[p-1] += 1
  num = c[p-1]
  print("0"*(6-len(p))+"0"*(6-len(num))+num)
  

import math
n,m = map(int, input().split())
a = []
for i in range(m):
  pk,yk = map(int,input().split())
  b = [pk,yk,i]
  a.append(b)
a.sort(key=lambda x:(x[0],x[1]))
b = a[0][0]
c = 0
for i in range(len(a)):
  if a[i][0] != b:
    b = a[i][0]
    c = 1
  else:
    c += 1
  a[i].append(c)
a.sort(key=lambda x:x[2])
for i in range(len(a)):
  a[i].append(math.floor(math.log10(a[i][0])+1.0))
  a[i].append(math.floor(math.log10(a[i][3])+1.0))
  print(str("0"*(6-a[i][4]))+str(a[i][0])+str("0"*(6-a[i][5]))+str(a[i][3]))

  



Verdicts: Runtime Error

Accepted
Problem: 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.

Submission attempts (in order):
def resolve():
    (N, M) = list(map(int,input().split(" ")))
    cities = [list(map(int, input().split(" "))) + [i] for i in range(M)]
    sorted_cities = sorted(cities, key=lambda x: (x[0], x[1]))

    pref = 0
    cnt = 0
    for city in sorted_cities:
        if pref != city[0]:
            pref = city[0]
            cnt = 0
        cnt = cnt + 1
        city.append("{:06d}{:06d}".format(pref, cnt))
    
    
    for city in sorted_cities:
        print(city[3])

if '__main__' == __name__:
    resolve()

def resolve():
    (N, M) = list(map(int,input().split(" ")))
    cities = [list(map(int, input().split(" "))) + [i] for i in range(M)]
    sorted_cities = sorted(cities, key=lambda x: (x[0], x[1]))

    pref = 0
    cnt = 0
    for city in sorted_cities:
        if pref != city[0]:
            pref = city[0]
            cnt = 0
        cnt = cnt + 1
        city.append("{:06d}{:06d}".format(pref, cnt))
    
    
    # for city in sorted_cities:
    #     print(city[3])

    for city in cities:
        print(city[3])

if '__main__' == __name__:
    resolve()

Verdicts: Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
N, M = (int(i) for i in input().split(' '))
py=[]
p =[]

for i in range(M):
    p = [i]
    p.extend([int(j) for j in input().split(' ')])
    py.append(p)

Npy = []
for i in range(1,N+1):
    
    pyi = [j for j in py if j[1] == i] 
    pyi.sort(key=lambda x: x[2]) 
    l = len(pyi)
    cnt = 0
    for k in range(1,l+1):
        pyi[k-1][2] = k
    Npy.extend(pyi)

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

for t in Npy:
    print('{0:0>6}{1:0>6}'.format(t[1],t[2]))
    

from operator import itemgetter
N, M = (int(i) for i in input().split(' '))
py=[]
p =[]


for i in range(M):
    p = [i]
    p.extend([int(j) for j in input().split(' ')])
    py.append(p)


Npy = []
for i in range(1,N+1):
    
    pyi = [j for j in py if j[1] == i] の市リスト
    pyi.sort(key=itemgetter(2)) の市を生まれた年でソート
    l = len(pyi)
    cnt = 0
    for k in range(1,l+1):
        pyi[k-1][2] = k
    Npy.extend(pyi)

Npy.sort(key=itemgetter(0))

for t in Npy:
    print('{0:0>6}{1:0>6}'.format(t[1],t[2]))
    

N, M = (int(i) for i in input().split(' '))
py=[]
p =[]


for i in range(M):
    p = [i]
    p.extend([int(j) for j in input().split(' ')])
    py.append(p)


Npy = []
for i in range(1,N+1):
    
    pyi = [j for j in py if j[1] == i] の市リスト
    pyi.sort(key=lambda x: x[2]) の市を生まれた年でソート
    l = len(pyi)
    cnt = 0
    for k in range(1,l+1):
        pyi[k-1][2] = k
    Npy.extend(pyi)

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

for t in Npy:
    print('{0:0>8}{1:0>8'.format(t[1],t[2]))
    

N, M = (int(i) for i in input().split(' '))
py=[]
p =[]


for i in range(M):
    p = [i]
    p.extend([int(j) for j in input().split(' ')])
    py.append(p)


Npy = []
for i in range(1,N+1):
    
    pyi = [j for j in py if j[1] == i] の市リスト
    pyi.sort(key=lambda x: x[2]) の市を生まれた年でソート
    l = len(pyi)
    cnt = 0
    for k in range(1,l+1):
        pyi[k-1][2] = k
    Npy.extend(pyi)

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

for t in Npy:
    print('{0:0>6}{1:0>6}'.format(t[1],t[2]))
    

N, M = (int(i) for i in input().split(' '))
py=[]
p =[]


for i in range(M):
    p = [i]
    p.extend([int(j) for j in input().split(' ')])
    py.append(p)


py.sort(key = lambda x: x[2])
pcid = [1] * N 

for i in range(M):
    p = py[i][1] 
    py[i][2] = pcid[p-1]
    pcid[p-1] += 1

py.sort(key=lambda x:x[0])
for t in py:
    print('{0:0>6}{1:0>6}'.format(t[1],t[2]))
    

Verdicts: Wrong Answer

Time Limit Exceeded

Runtime Error

Time Limit Exceeded

Accepted
Problem: 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.

Submission attempts (in order):
n,m = map(int,input().split())
pref = [[] for _ in range(n)]
cityrecord = []
for i in range(m):
  p,y = map(int,input().split())
  pref[p-1].append([y,i])
  cityrecord.append(p-1)
for ni in range(n):
  pref[ni].sort()
print(pref)
for i in range(m):
  now = cityrecord[i]
  for j in range(len(pref[now])):
    if pref[now][j][1] == i:
      ans = (now + 1) * 10 ** 6 + j + 1
      ANS = str(ans)
      out = '0' * (12 - len(ANS)) + ANS
      print(out)

P,C = map(int,input().split())
pref = [[] for _ in range(P)]
city = []
for ci in range(C):
  p,y = map(int,input().split())
  city.append([p-1])
  pref[p-1].append([y,ci])
cinp = []
for pi in range(P):
  pref[pi].sort()
  for j in range(len(pref[pi])):
    citycode = pref[pi][j][1]
    city[citycode].append(j)
for ci in range(C):
  pnow = city[ci][0]
  inow = city[ci][1]
  try:
    ans = (pnow+1) * 10 ** 6 + (inow+1)
  except:
    print(pnow,inow,p,cinp)
  ANS = str(ans)
  print( '0' * (12 - len(ANS)) + ANS)

Verdicts: Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
def nyu():
    N, M = map(int, input().split())
    S = [list(input().split()) for i in range(M)]
    return N,M,S

def kansu(N,M,S):

    S_tmp=[]
    for i in range(M):
        tmp = [int(S[i][0]),int(S[i][1]),0]
        S_tmp.append(tmp) 
    S_tmp.sort()
    tmp = S_tmp[0][0]
    cnt = 1

    for i in range(M):
        if tmp == int(S_tmp[i][0]):
            S_tmp[i][2] = cnt
            cnt += 1
        else :
            tmp = S_tmp[i][0]
            S_tmp[i][2] = 1
            cnt = 2
    print(S_tmp)
    for i in range(M):
        for n in range(M):
        #    print("S[i][1]=",S[i][1],"S_tmp[n][1]=",S_tmp[n][1])
            if int(S[i][1]) == int(S_tmp[n][1]):
                print(str(S[i][0]).zfill(6),str(S_tmp[n][2]).zfill(6),sep='')
                break



    # for m1 in range(M):
    #     cnt = 1
    #     tmp_m1 = S[m1][0]
    #     tmp_m2 = S[m1][1]
    #     for m2 in range(M):
    #         if S[m2][0] == tmp_m1 and S[m2][1] < tmp_m2:
    #             cnt = cnt + 1
    #     print(str(S[m1][0]).zfill(6),str(cnt).zfill(6),sep='')


N,M,S = nyu()
kansu(N,M,S)
#print(S)



def nyu():
    N, M = map(int, input().split())
    S = [list(input().split()) for i in range(M)]
    return N,M,S

def kansu(N,M,S):

    S_tmp=[]
    for i in range(M):
        tmp = [int(S[i][0]),int(S[i][1]),0,i]
        S_tmp.append(tmp) 
    S_tmp.sort()
    tmp = S_tmp[0][0]
    cnt = 1

    for i in range(M):
        if tmp == int(S_tmp[i][0]):
            S_tmp[i][2] = cnt
            cnt += 1
        else :
            tmp = S_tmp[i][0]
            S_tmp[i][2] = 1
            cnt = 2
#    print(S_tmp)
    S_tmp = sorted(S_tmp, key=lambda x: x[3])
#    print(S_tmp)
    for i in range(M):
        print(str(S_tmp[i][0]).zfill(6),str(S_tmp[i][2]).zfill(6),sep='')
    



    # for m1 in range(M):
    #     cnt = 1
    #     tmp_m1 = S[m1][0]
    #     tmp_m2 = S[m1][1]
    #     for m2 in range(M):
    #         if S[m2][0] == tmp_m1 and S[m2][1] < tmp_m2:
    #             cnt = cnt + 1
    #     print(str(S[m1][0]).zfill(6),str(cnt).zfill(6),sep='')


N,M,S = nyu()
kansu(N,M,S)
#print(S)



Verdicts: Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
n,m=map(int,input().split())
li=[]
ans=[]
cnt=0
for i in range(m):
    p,y=map(int,input().split())
    li.append([p,y,i])
li=sorted(li,key=lambda x:x[1])
li=sorted(li,key=lambda x:x[0])
pre=li[0][0]
print(li)
for j in range(m):
    if li[j][0]==pre:
        cnt+=1
        ans.append([str(pre).zfill(6)+str(cnt).zfill(6),li[j][2]])
        
    else:
        pre=li[j][0]
        cnt=1
        ans.append([str(pre).zfill(6)+str(cnt).zfill(6),li[j][2]])

ans=sorted(ans,key=lambda x:x[1])
for k in range(m):
    print(ans[k][0])

n,m=map(int,input().split())
li=[]
ans=[]
cnt=0
for i in range(m):
    p,y=map(int,input().split())
    li.append([p,y,i])
li=sorted(li,key=lambda x:x[1])
li=sorted(li,key=lambda x:x[0])
pre=li[0][0]
for j in range(m):
    if li[j][0]==pre:
        cnt+=1
        ans.append([str(pre).zfill(6)+str(cnt).zfill(6),li[j][2]])
        
    else:
        pre=li[j][0]
        cnt=1
        ans.append([str(pre).zfill(6)+str(cnt).zfill(6),li[j][2]])

ans=sorted(ans,key=lambda x:x[1])
for k in range(m):
    print(ans[k][0])

Verdicts: Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
from bisect import bisect,bisect_left


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

d1 = {}
d2 = {}
for i in range(M):
    PY = list(map(int,input().split()))
    tmp = d1.get(PY[0],[])
    ins_pos = bisect(tmp,PY[1])
    tmp.insert(ins_pos,PY[1])
    d1[PY[0]] = tmp

for py in PY:
    s1 = str(py[0])
    s1 = ("0"*(6-len(s1)))+s1
    s2 = str(bisect_left(d[py[0]],py[1])+1)
    s2 = ("0"*(6-len(s2)))+s2

    print(s1+s2)


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

num = [0]*N
ans = [""]*M

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

for p,y,i in PY:
    num[p-1] += 1
    ans[i] = str(p).zfill(6) + str(num[p-1]).zfill(6)

for a in ans:
    print(a)


Verdicts: Runtime Error

Accepted
Problem: 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.

Submission attempts (in order):
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))

ans = [None]*M

for i, d in enumerate(D):
    print(d)
    d.sort()
    for k, (y, j) in enumerate(d):
        ans[j] = "%06d%06d" % (i+1, k+1)
    
print(*ans, sep='\n')

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

ans = [None]*M

for i, d in enumerate(D):
    d.sort()
    for k, (y, j) in enumerate(d):
        ans[j] = "%06d%06d" % (i+1, k+1)
    
print(*ans, sep='\n')

Verdicts: Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
pre_n, city_n = map(int, input().split())
cities = [list(map(int, input().split())) for x in range(city_n)]

history = {}

A = {}

print(sorted(cities))

for x in sorted(cities):
    pref = str(x[0])
    if pref not in history:
        history[pref] = '1'

    A.setdefault(str(x), '0'*(6-len(pref)) + pref + '0'*(6-len(history[pref])) + history[pref])

    history[pref] = str(int(history[pref]) + 1)

for x in cities:
    print(A[str(x)])


pre_n, city_n = map(int, input().split())
cities = [list(map(int, input().split())) for x in range(city_n)]

history = {}

A = {}

for x in sorted(cities):
    pref = str(x[0])
    if pref not in history:
        history[pref] = '1'

    A.setdefault(str(x), '0'*(6-len(pref)) + pref + '0'*(6-len(history[pref])) + history[pref])

    history[pref] = str(int(history[pref]) + 1)

for x in cities:
    print(A[str(x)])


Verdicts: Wrong Answer

Accepted