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
input = sys.stdin.readline

n, m = list(map(int, input().rstrip().split()))
ans = [""] * m
arr = []
cnt = 1
for i in range(m):
    p, y = map(int, input().split())
    arr += [(p, y, i)]
arr = sorted(arr)

ans[arr[0][2]] = "{:06}{:06}".format(arr[0][0], cnt)
for i in range(1, m):
    if arr[i - 1][0] == arr[i][0]:
        cnt += 1
    else:
        cnt = 1
    ans[arr[i][2]] = "{:06}{:06}".format(arr[i][0], cnt)

for i in asn:
    print(i)
print(*ans, sep="\n")

## ABC113C - ID
import sys
input = sys.stdin.readline

n, m = list(map(int, input().rstrip().split()))
arr = [list(map(int, input().rstrip().split())) for _ in range(m)]
pref = [[] for _ in range(n)]
for i in arr:
    pref[i[0] - 1] += [i]
print(pref)
pref = [sorted(i) for i in pref]
print(pref)
for i in arr:
    j = pref[i[0] - 1].index(i) + 1
    print("{:0>6}{:0>6}".format(i[0], j))

import sys
input = sys.stdin.readline

n, m = list(map(int, input().rstrip().split()))
ans = [""] * m
arr = []
cnt = 1
for i in range(m):
    p, y = map(int, input().split())
    arr += [(p, y, i)]
arr = sorted(arr)

ans[arr[0][2]] = "{:06}{:06}".format(arr[0][0], cnt)
for i in range(1, m):
    if arr[i - 1][0] == arr[i][0]:
        cnt += 1
    else:
        cnt = 1
    ans[arr[i][2]] = "{:06}{:06}".format(arr[i][0], cnt)

for i in asn:
    print(i)

## ABC113C - ID
import sys
input = sys.stdin.readline

def main():
    n, m = list(map(int, input().rstrip().split()))
    ans = [""] * m
    arr = []
    cnt = 1
    for i in range(m):
        p, y = list(map(int, input().split()))
        arr += [(p, y, i)]
    arr = sorted(arr)

    ans[arr[0][2]] = "{:06}{:06}".format(arr[0][0], cnt)
    for i in range(1, m):
        if arr[i - 1][0] == arr[i][0]:
            cnt += 1
        else:
            cnt = 1
        ans[arr[i][2]] = "{:06}{:06}".format(arr[i][0], cnt)

    for i in ans:
        print(i)
    print(ans)


if __name__ == "__main__":
    main()

# ABC113C - ID
import sys
input = sys.stdin.readline

def main():
    N, M = tuple(map(int, input().split()))
    P = [[] for _ in range(N + 1)]  
    for num in range(M):  # classify cities by prefectures
        pref, year = tuple(map(int, input().split()))
        P[pref] += [(year, num)]
    ans = [""] * M
    P = tuple(sorted(p) for p in P)  # sort by year
    for pref_idx, pref in enumerate(P):
        for city_idx, (_, num) in enumerate(pref, 1):
            x = "{:06}{:06}".format(pref_idx, city_idx)
            ans[num] = x
    print(*ans, sep="\n")
    print(type(P))

if __name__ == "__main__":
    main()

# ABC113C - ID
def main():
    N, M, *PY = map(int, open(0).read().split())
    P = [[] for _ in range(N + 1)]  
    # classify cities by prefectures
    for num, (pref, year) in enumerate(zip(*[iter(PY)] * 2)):
        P[pref] += [(year, num)]
    ans = [[] for _ in range(M)]
    P = [sorted(p) for p in P]  # sort by year
    for pref_idx, pref in enumerate(P):
        for city_idx, (_, num) in enumerate(pref, 1):
            x = "{:06}{:06}".format(pref_idx, city_idx)
            ans[num] = x
    print("\n".join(map(str, ans)))

    
if __name__ == "__main__":
    main()

Verdicts: Runtime Error

Wrong Answer

Runtime Error

Wrong Answer

Wrong Answer

Accepted