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 sys

s2nn = lambda s: [int(c) for c in s.split(' ')]

ss2nn = lambda ss: [int(s) for s in list(ss)]
ss2nnn = lambda ss: [s2nn(s) for s in list(ss)]

i2s = lambda: sys.stdin.readline().rstrip()
i2n = lambda: int(i2s())
i2nn = lambda: s2nn(i2s())

ii2ss = lambda n: [sys.stdin.readline() for _ in range(n)]

def main(N, M, PYm):
    
    
    dic = {}
    
    
    
    #dic2 = {}
    dic2tmp = {}
    for p in range(N+1):
        dic[p] = {}
        #dic2[p] = []
        dic2tmp[p] = []
    for p, y in PYm:
        dic2tmp[p].append(y)
    for p in range(N+1):
        dic2tmp[p].sort()
        nby = [(i+1, y) for i, y in enumerate(dic2tmp[p])]
        #dic2[p] = nby
        for nb, y in nby:
            dic[p][y] = nb
    
    for p, y in PYm:
        nb = dic[p][y]
        print('%06d%06d' % (p, nb))
N, M = i2nn()
PYs = ss2nnn(ii2ss())
main(N, M, PYs)


import sys

def i2nn():
    return sp2nn(sys.stdin.readline())

def ii2ss(n):
    return [sys.stdin.readline() for _ in range(n)]

def sp2nn(sp, sep=' '):
    return [int(s) for s in sp.split(sep)]

def ss2nn(ss):
    return [int(s) for s in list(ss)]

def main(N, ss):
    nn = [[] for _ in range(N+1)]
    for s in ss:
        p, y = sp2nn(s)
        nn[p].append(y)
    for n2 in nn:
        n2.sort()
    for i, n2 in enumerate(nn):
        for n in n2:
            print('%06d%06d' % (i, n))

N, M = i2nn()
main(N, ii2ss(M))


import sys

def i2nn():
    return sp2nn(sys.stdin.readline())

def ii2ss(n):
    return [sys.stdin.readline() for _ in range(n)]

def sp2nn(sp, sep=' '):
    return [int(s) for s in sp.split(sep)]

def ss2nn(ss):
    return [int(s) for s in list(ss)]

def main(N, ss):
    nn = [[] for _ in range(N+1)]
    for s in ss:
        p, y = sp2nn(s)
        nn[p].append(y)
    for n2 in nn:
        n2.sort()
    for i, n2 in enumerate(nn):
        for j, n in enumerate(n2):
            print('%06d%06d' % (i, j+1))

N, M = i2nn()
main(N, ii2ss(M))


import sys
 
s2nn = lambda s: [int(c) for c in s.split(' ')]
 
ss2nn = lambda ss: [int(s) for s in list(ss)]
ss2nnn = lambda ss: [s2nn(s) for s in list(ss)]
 
i2s = lambda: sys.stdin.readline().rstrip()
i2n = lambda: int(i2s())
i2nn = lambda: s2nn(i2s())
 
ii2ss = lambda n: [sys.stdin.readline() for _ in range(n)]
 
def main(N, M, PYm):
    
    
    dic = {}
    
    
    
    #dic2 = {}
    dic2tmp = {}
    for p in range(N+1):
        dic[p] = {}
        #dic2[p] = []
        dic2tmp[p] = []
    for p, y in PYm:
        dic2tmp[p].append(y)
    for p in range(N+1):
        dic2tmp[p].sort()
        nby = [(i+1, y) for i, y in enumerate(dic2tmp[p])]
        #dic2[p] = nby
        for nb, y in nby:
            dic[p][y] = nb
    
    for p, y in PYm:
        nb = dic[p][y]
        print('%06d%06d' % (p, nb))

N, M = i2nn()
PYs = ss2nnn(ii2ss(M))
main(N, M, PYs)


Verdicts: Runtime Error

Wrong Answer

Wrong Answer

Accepted