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

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

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

n, m = map(int, input().split())
P_Y_list = [list(map(int, input().split()))+[i] for i in range(m)]
sorted_P_Y_list = sorted(P_Y_list, key=lambda x:(x[0], x[1]))

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

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

for id in sorted_P_Y_list:
    print("%012d"%int(str(id[0]).zfill(6) + id[1].zfill(6)))

Verdicts: Wrong Answer

Wrong Answer

Wrong Answer

Accepted