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 numpy import*
#from scipy import*
from collections import* #defaultdict Counter deque
from fractions import gcd
from functools import* #reduce
from itertools import* #permutations("AB",repeat=2) combinations("AB",2) product("AB",2)
from operator import mul
from bisect import* #bisect_left bisect_right
from heapq import* #heapify heappop heappushpop
from math import factorial
from copy import deepcopy
import sys
input=sys.stdin.readline
sys.setrecursionlimit(10**6)

#enumerate input

def main():
    n,m=map(int,input().split())
    py=[list(map(int,input().split()))+[i]for i in range(m)]
    py=sorted(sorted(py,key=lambda x:x[1]),key=lambda x:x[0])
    d=defaultdict(list)
    pre=py[0][0]
    num=1
    for p,_,i in py:
        if p==pre:
            d[i]=[p,num]
            num+=1
        else:
            num=2
            pre=p
            d[i]=[p,1]
#    print(d)
    for i in range(m):
        s,t=d[i]
        print(str(s).zfill(6),str(t).zfill(6))

    
if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
## 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))

Submission status: Wrong Answer

Solution code:
N, M = map(int, input().split())
city_list = []
for i in range(M):
    a,b = map(int,input().split())
    city_list.append([a,b,0,i])

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

city_id = 1
city_cnt = 1
i = 0

while True:
    if i + 1 > M:
        break

    elif city_id == city_list[i][0]:
        city_list[i][2] = city_cnt
        city_cnt += 1
        i += 1
    
    elif city_id <= M+1:
        city_cnt = 1
        city_id += 1

    else:
        break
            
city_list.sort(key=lambda city_list:city_list[3])

for city in city_list:
    print('{:0>6}{:0>6}'.format(city[0],city[2]))

Submission status: Wrong Answer

Solution code:
N, M = map(int, input().split())
city_list = []
for i in range(M):
    a,b = map(int,input().split())
    city_list.append([a,b,0,i])

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

city_id = 1
city_cnt = 1

for i in range(M):
    while True:
        if city_id == city_list[i][0]:
            city_list[i][2] = city_cnt
            city_cnt += 1
            break
        
        elif city_id <= M+1:
            city_cnt = 1
            city_id += 1
 
        else:
            break
            
city_list.sort(key=lambda city_list:city_list[3])

for city in city_list:
    print('{:0>6}{:0>6}'.format(city[0],city[2]))

Submission status: Wrong Answer

Solution code:
N, M = map(int, input().split())
city_list = []
for i in range(M):
    a,b = map(int,input().split())
    city_list.append([a,b,0,i])

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

city_id = 1
city_cnt = 1

for i in range(M):
    while True:
        if city_id == city_list[i][0]:
            city_list[i][2] = city_cnt
            city_cnt += 1
            break
        
        elif city_id <= M:
            city_cnt = 1
            city_id += 1
 
        else:
            break
            
city_list.sort(key=lambda city_list:city_list[3])

for city in city_list:
    print('{:0>6}{:0>6}'.format(city[0],city[2]))

Submission status: Wrong Answer

Solution code:
N, M = map(int, input().split())
city_list = []
for i in range(M):
    a,b = map(int,input().split())
    city_list.append([a,b,0,i])

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

city_id = 1
city_cnt = 1

for i in range(M):
    while True:
        if city_id == city_list[i][0]:
            city_list[i][2] = city_cnt
            city_cnt += 1
            break
        
        elif city_id <= M:
            city_cnt = 1
            city_id += 1
 
        else:
            city_cnt = 1
            city_id = 1
            break
            
city_list.sort(key=lambda city_list:city_list[3])

for city in city_list:
    print('{:0>6}{:0>6}'.format(city[0],city[2]))

Submission status: Wrong Answer

Solution code:
import copy

N, M = map(int, input().split())
city_list = []
for i in range(M):
    a,b = map(int,input().split())
    city_list.append([a,b,0,i])

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

city_id = 1
city_cnt = 1

for i in range(M):
    while True:
        if city_id == city_list[i][0]:
            city_list[i][2] = city_cnt
            city_cnt += 1
            break
        
        elif city_id > M:
            city_cnt = 1
            city_id = 1
            break
            
        else:
            city_cnt = 1
            city_id += 1
 
city_list.sort(key=lambda city_list:city_list[3])

for city in city_list:
    print('{:0>6}{:0>6}'.format(city[0],city[2]))

Submission status: Wrong Answer

Solution code:
import copy

N, M = map(int, input().split())
city_list = []
for i in range(M):
    a,b = map(int,input().split())
    city_list.append([a,b,0,i])

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

city_id = 1
city_cnt = 1

for i in range(M):
    while True:
        if city_id == city_list[i][0]:
            city_list[i][2] = city_cnt
            city_cnt += 1
            break
        
        elif city_id > M:
            break
            
        else:
            city_cnt = 1
            city_id += 1
 
city_list.sort(key=lambda city_list:city_list[3])

for city in city_list:
    print('{:0>6}{:0>6}'.format(city[0],city[2]))

Submission status: Wrong Answer

Solution code:
import copy

N, M = map(int, input().split())
city_list = []
for i in range(M):
    a,b = map(int,input().split())
    city_list.append([a,b,0,i])

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

city_id = 1
city_cnt = 1

for i in range(M):
    if city_id == city_list[i][0]:
        city_list[i][2] = city_cnt
        city_cnt += 1
    else:
        city_cnt = 1
        city_list[i][2] = city_cnt
        city_id += 1
        city_cnt += 1

city_list.sort(key=lambda city_list:city_list[3])

for city in city_list:
    print('{:0>6}{:0>6}'.format(city[0],city[2]))

Submission status: Wrong Answer

Solution code:
import heapq

n, m = [ int(v) for v in input().split() ]
city_list = [ [] for i in range(n+1) ]
city_list2 = []
for i in range(m):
	p, y = [ int(v) for v in input().split() ]
	heapq.heappush(city_list[p], y)
	city_list2.append([p,y])


for i in range(m):
	a, b = city_list2[i][0], city_list[city_list2[i][0]].index(city_list2[i][1])+1
	print(str(a).zfill(6)+str(b).zfill(6))

Submission status: Wrong Answer

Solution code:
N,M = map(int,input().split())
data = []
for i in range(M):
  PY=list(input().split())
  data.append(PY)
for i in range(M):
  a = data[i][0]
  b = data[i][1]
  s_a = a.zfill(6)
  s_b = b.zfill(6)
  print(s_a+s_b)

Submission status: Wrong Answer

Solution code:
N, M = map(int, input().split())
PY = [[i,0] + list(map(int, input().split())) for i in range(M)]
# [index, nth city, pref num, birth year]

PY.sort(key=lambda x:(x[2],x[3]))

p = -1
for i,py in enumerate(PY):
  if p != py[3]:
    p = py[3]
    num = 1
    PY[i][1] = num
  else:
    num += 1
    PY[i][1] = num

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

for py in PY:
  print('{:0=6}{:0=6}'.format(py[2], py[1]))

Submission status: Wrong Answer

Solution code:
n,m=map(int,input().split())
l=[]
for i in range(m):
	x,y=map(int,input().split())
	l=list(map(lambda i: i+1 if not (i//1000000)-x else i,l))
	l.append(x*10**6+1)
l=list(map(lambda x: str(x).zfill(12), l))
print('\n'.join(l))

Submission status: Wrong Answer

Solution code:
N, M = map(int, input().split())
birth_list = []
for i in range(M):
    Pi, Yi = map(int, input().split())
    birth_list.append([Pi, Yi])

counter = -1
prev_pref = -1
for city in sorted(birth_list, key=lambda x: (x[0], x[1])):
    print(city)
    if city[0] != prev_pref:
        counter = 1
    else:
        counter += 1
    identity_number = str(city[0]).zfill(6) + str(counter).zfill(6)
    city.append(identity_number)
    prev_pref = city[0]

for city in birth_list:
    print(city[2])

Submission status: Wrong Answer

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

def sort_by_place(place_and_year_set_lst):
    if len(place_and_year_set_lst) < 2:
        return place_and_year_set_lst
    pivot_place = place_and_year_set_lst[0][1]
    right = [place_and_year_set_lst[i] for i in range(len(place_and_year_set_lst)) if place_and_year_set_lst[i][1] > pivot_place]
    left = [place_and_year_set_lst[i] for i in range(len(place_and_year_set_lst)) if place_and_year_set_lst[i][1] < pivot_place]
    same = [place_and_year_set_lst[i] for i in range(len(place_and_year_set_lst)) if place_and_year_set_lst[i][1] == pivot_place]

    return sort_by_place(left) + same + sort_by_place(right)

def sort_by_year(place_and_year_set_lst):
    if len(place_and_year_set_lst) < 2:
        return place_and_year_set_lst
    pivot_year = place_and_year_set_lst[0][2]
    older = [place_and_year_set_lst[i] for i in range(len(place_and_year_set_lst)) if place_and_year_set_lst[i][2] > pivot_year]
    yunger = [place_and_year_set_lst[i] for i in range(len(place_and_year_set_lst)) if place_and_year_set_lst[i][2] < pivot_year]
    same = [place_and_year_set_lst[i] for i in range(len(place_and_year_set_lst)) if place_and_year_set_lst[i][2] == pivot_year]

    return sort_by_year(yunger) + same + sort_by_year(older)

def make_1_str_city_num(place_and_year_strSet_lst, place, cities_num, count_in_1_city):
    x = str(count_in_1_city)
    zeros = ""
    for _ in range(6-len(x)):
        zeros += "0"
    x = zeros + x

    zeros = ""
    for _ in range(6-len(place)):
        zeros += "0"
    place = zeros + place

    place_and_year_strSet_lst.append((cities_num, place + x))

def make_1_cities_output(place_and_year_strSet_lst, place_and_year_set_lst, i, count_in_1_city):
    place = str(place_and_year_set_lst[i][1])
    cities_num = str(place_and_year_set_lst[i][0])

    if place_and_year_set_lst[i][1] == place_and_year_set_lst[i-1][1] and i != 0:
        count_in_1_city += 1
        make_1_str_city_num(place_and_year_strSet_lst, place, cities_num, count_in_1_city)
    else:
        count_in_1_city = 1
        make_1_str_city_num(place_and_year_strSet_lst, place, cities_num, count_in_1_city)

    return count_in_1_city


place_and_year_set_lst = []
for i in range(M):
    Pi, Yi = map(int, input().split())
    place_and_year_set_lst.append((i, Pi, Yi))


place_and_year_set_lst = sort_by_year(place_and_year_set_lst)
place_and_year_set_lst = sort_by_place(place_and_year_set_lst)

place_and_year_strSet_lst = []
count_in_1_city = 1

make_1_cities_output(place_and_year_strSet_lst, place_and_year_set_lst, i=0, count_in_1_city=1)

for i in range(1, M):
    count_in_1_city = make_1_cities_output(place_and_year_strSet_lst, place_and_year_set_lst, i, count_in_1_city)

place_and_year_strSet_lst.sort()

for i in range(M):
    print(place_and_year_strSet_lst[i][1])

Submission status: Wrong Answer

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

def sort_by_place(place_and_year_set_lst):
    if len(place_and_year_set_lst) < 2:
        return place_and_year_set_lst
    pivot_place = place_and_year_set_lst[0][1]
    right = [place_and_year_set_lst[i] for i in range(len(place_and_year_set_lst)) if place_and_year_set_lst[i][1] > pivot_place]
    left = [place_and_year_set_lst[i] for i in range(len(place_and_year_set_lst)) if place_and_year_set_lst[i][1] < pivot_place]
    same = [place_and_year_set_lst[i] for i in range(len(place_and_year_set_lst)) if place_and_year_set_lst[i][1] == pivot_place]

    return sort_by_place(left) + same + sort_by_place(right)

def sort_by_year(place_and_year_set_lst):
    if len(place_and_year_set_lst) < 2:
        return place_and_year_set_lst
    pivot_year = place_and_year_set_lst[0][2]
    older = [place_and_year_set_lst[i] for i in range(len(place_and_year_set_lst)) if place_and_year_set_lst[i][2] > pivot_year]
    yunger = [place_and_year_set_lst[i] for i in range(len(place_and_year_set_lst)) if place_and_year_set_lst[i][2] < pivot_year]
    same = [place_and_year_set_lst[i] for i in range(len(place_and_year_set_lst)) if place_and_year_set_lst[i][2] == pivot_year]

    return sort_by_year(yunger) + same + sort_by_year(older)

def make_1_str_city_num(place_and_year_strSet_lst, place, cities_num, count_in_1_city):
    x = str(count_in_1_city)
    zeros = ""
    for j in range(6-len(x)):
        zeros += "0"
    x = zeros + x

    zeros = ""
    for j in range(6-len(place)):
        zeros += "0"
    place = zeros + place

    place_and_year_strSet_lst.append((cities_num, place + x))

def make_1_cities_output(place_and_year_strSet_lst, place_and_year_set_lst, i, count_in_1_city):
    place = str(place_and_year_set_lst[i][1])
    cities_num = str(place_and_year_set_lst[i][0])

    if place_and_year_set_lst[i][1] == place_and_year_set_lst[i-1][1] and i != 0:
        count_in_1_city += 1
        make_1_str_city_num(place_and_year_strSet_lst, place, cities_num, count_in_1_city)
    else:
        count_in_1_city = 1
        make_1_str_city_num(place_and_year_strSet_lst, place, cities_num, count_in_1_city)

    return count_in_1_city


place_and_year_set_lst = []
for i in range(M):
    Pi, Yi = map(int, input().split())
    place_and_year_set_lst.append((i, Pi, Yi))


place_and_year_set_lst = sort_by_year(place_and_year_set_lst)
place_and_year_set_lst = sort_by_place(place_and_year_set_lst)

place_and_year_strSet_lst = []
count_in_1_city = 1

make_1_cities_output(place_and_year_strSet_lst, place_and_year_set_lst, i=0, count_in_1_city=1)

for i in range(1, M):
    count_in_1_city = make_1_cities_output(place_and_year_strSet_lst, place_and_year_set_lst, i, count_in_1_city)

place_and_year_strSet_lst.sort()

for i in range(M):
    print(place_and_year_strSet_lst[i][1])

Submission status: Wrong Answer

Solution code:
"""



"""

N, M = map(int, input().split())
#cityの番号を付与して、格納
city = [list(map(int, input().split())) + [i] + [0] for i in range(M)]

city.sort(key=lambda x: (x[0], x[1]))
print(city)
for m in range(M):
    if m == 0:
        city[m][3] = 1
    elif city[m][0] != city[m - 1][0]:
        city[m][3] = 1
    else:
        city[m][3] = city[m - 1][3] + 1

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

for m in range(M):
    print(str(city[m][0]).zfill(6) + str(city[m][3]).zfill(6))

Submission status: Wrong Answer

Solution code:
N, M = map(int, input().split())
PY = [list(map(int, input().split())) for _ in range(M)]

PY = sorted(PY)

keyP = -1
for P, Y in PY:
  if keyP != P:
    keyP = P
    keyNo = 1

  print("{:0>6}{:0>6}".format(keyP, keyNo))
  keyNo += 1

Submission status: Wrong Answer

Solution code:
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))

Submission status: Wrong Answer

Solution code:
from __future__ import print_function
import numpy as np
import sys
import math,string,itertools,fractions,heapq,collections,re,array,bisect,copy,functools
import heapq
from heapq import heappush
from heapq import heappop
import random


def eprint(*args, **kwargs):
    print(*args, file=sys.stderr, **kwargs)

n,m = map(int, input().split())
p=np.zeros(m+1,dtype=int)
y=np.zeros(m+1,dtype=int)
for i in range(1,m+1):
    p[i],y[i] = map(int, input().split())


l_pref=[[] for _ in range(n+1)]    # 県の数(==n)だけ空リストを用意
for i in range(1,m+1):
    heappush(l_pref[p[i]],(y[i],i))



for i in range(1,m+1):
    temp =  l_pref[p[i]].index((y[i],i))  + 1
    print("0"*(6-len(str(p[i])))  +  str(p[i])  +  "0"*(6-len(str(temp))) + str(temp) )

Submission status: Wrong Answer

Solution code:
from __future__ import print_function
import numpy as np
import sys
import math,string,itertools,fractions,heapq,collections,re,array,bisect,copy,functools
import heapq
from heapq import heappush
from heapq import heappop
import random


def eprint(*args, **kwargs):
    print(*args, file=sys.stderr, **kwargs)

n,m = map(int, input().split())
p=np.zeros(m+1,dtype=int)
y=np.zeros(m+1,dtype=int)
for i in range(1,m+1):
    p[i],y[i] = map(int, input().split())


l_pref=[[] for _ in range(n+1)]    # 県の数(==n)だけ空リストを用意
for i in range(1,m+1):
    heappush(l_pref[p[i]],(y[i],i))



for i in range(1,m+1):
    print("0"*(6-len(str(p[i])))  +  str(p[i])  +  "0"*(6-len(str( l_pref[p[i]].index((y[i],i))  + 1 ))) + str(l_pref[p[i]].index((y[i],i))  + 1) )

Submission status: Wrong Answer

Solution code:
n,m = map(int, input().split())
Y = [[] for _ in range(n)]
L = []
for i in range(m):
    p,yi = map(int, input().split())
    Y[p-1].append(yi)
    L.append(yi)
for i in range(n):
    Y[i].sort()
    for k in range(len(Y[i])):
        print(0)

Submission status: Wrong Answer

Solution code:
n,m = map(int, input().split())
Y = [[] for _ in range(n)]
L = []
for i in range(m):
    p,yi = map(int, input().split())
    Y[p-1].append(yi)
    L.append(yi)
for i in range(n):
    Y[i].sort()
    for k in range(len(Y[i])):
        L[L.index(Y[i][k])] = str(i+1).rjust(6,"0") + str(k+1).rjust(6,"0")

Submission status: Wrong Answer

Solution code:
N, M = [int(nm) for nm in input().split()]
PY = []
for m in range(M):
  PY.append([int(py) for py in input().split()])
PY.sort()
i = 1
print("0"*(6-len(str(PY[0][0]))) + str(PY[0][0]) + "0"*(6-len(str(i))) + str(i))
for m in range(1, M):
  if PY[m-1][0] == PY[m][0]:
    print("0"*(6-len(str(PY[m][0]))) + str(PY[m][0]) + "0"*(6-len(str(i+1))) + str(i+1))
  else:
    i = 1
    print("0"*(6-len(str(PY[m][0]))) + str(PY[m][0]) + "0"*(6-len(str(i))) + str(i))

Submission status: Wrong Answer

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

P, Y = [], []

Px = [0] * (N+1)
for _ in range(M):
    p, y = [int(x) for x in input().split()]
    Px[p]+=1
    print("%06d%06d" % (p, Px[p]))

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
import sys
import itertools


def solve(N: int, M: int, P: "List[int]", Y: "List[int]"):

    L = []
    R = [""] * M
    for p,y,i in zip(P,Y,range(M)):
        L.append((i,p,y))
    L.sort(key=lambda x: x[1]*10**8+x[2])

    for k,g in itertools.groupby(L,key=lambda x: x[1]):
        for i,gg in enumerate(g):
            R[gg[0]] = str(gg[1]).zfill(6) + str(i+1).zfill(6)

    for r in R:
        print(r)




# Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    M = int(next(tokens))  # type: int
    P = [int()] * (M)  # type: "List[int]" 
    Y = [int()] * (M)  # type: "List[int]" 
    for i in range(M):
        P[i] = int(next(tokens))
        Y[i] = int(next(tokens))
    solve(N, M, P, Y)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
import sys
import itertools


def solve(N: int, M: int, P: "List[int]", Y: "List[int]"):

    L = []
    R = [""] * M
    for p,y,i in zip(P,Y,range(M)):
        L.append((i,p,y))
    L.sort(key=lambda x: x[1]*10**6+x[2])

    for k,g in itertools.groupby(L,key=lambda x: x[1]):
        for i,gg in enumerate(g):
            R[gg[0]] = str(gg[1]).zfill(6) + str(i+1).zfill(6)

    for r in R:
        print(r)




# Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    M = int(next(tokens))  # type: int
    P = [int()] * (M)  # type: "List[int]" 
    Y = [int()] * (M)  # type: "List[int]" 
    for i in range(M):
        P[i] = int(next(tokens))
        Y[i] = int(next(tokens))
    solve(N, M, P, Y)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
import sys
import itertools


def solve(N: int, M: int, P: "List[int]", Y: "List[int]"):

    L = []
    R = [""] * M
    for p,y,i in zip(P,Y,range(M)):
        L.append((i,p,y))
    L.sort(key=lambda x: x[1]*10**5+x[2])

    for k,g in itertools.groupby(L,key=lambda x: x[1]):
        for i,gg in enumerate(g):
            R[gg[0]] = str(gg[1]).zfill(6) + str(i+1).zfill(6)

    for r in R:
        print(r)




# Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    M = int(next(tokens))  # type: int
    P = [int()] * (M)  # type: "List[int]" 
    Y = [int()] * (M)  # type: "List[int]" 
    for i in range(M):
        P[i] = int(next(tokens))
        Y[i] = int(next(tokens))
    solve(N, M, P, Y)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline

import collections, bisect

n, m = map(int, input().split())
p = [[int(j) for j in input().split()] for i in range(m)]
a = collections.defaultdict(list)
for x, y in sorted(p):
  a[x] += [y]
for x, y in sorted(p):
  z = bisect.bisect(a[x], y)
  print("%06d%06d"%(x,z))

Submission status: Wrong Answer

Solution code:
N, M = map(int, input().split())
PY = [list(map(int, input().split())) for _ in range(M)]

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

for py in PY:
    l[py[0]].append(py[1])

for py in PY:
    l[py[0]].sort()

for py in PY:
    print('{:0>7}'.format(py[0]) + '{:0>7}'.format(l[py[0]].index(py[1]) + 1))

Submission status: Wrong Answer

Solution code:
N, M = map(int, input().split())
PY = [list(map(int, input().split())) for _ in range(M)]

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

for py in PY:
    l[py[0]].append(py[1])

for py in PY:
    l[py[0]].sort()

for py in PY:
    print('{:0>7}'.format(py[0]), '{:0>7}'.format(l[py[0]].index(py[1]) + 1))

Submission status: Wrong Answer

Solution code:
N, M = map(int, input().split())
PY = [list(map(int, input().split())) for _ in range(M)]

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

for py in PY:
    l[py[0]].append(py[1])

for py in PY:
    l[py[0]].sort()

for py in PY:
    print('{:0>6}'.format(py[0]), '{:0>6}'.format(l[py[0]].index(py[1]) + 1))

Submission status: Wrong Answer

Solution code:
n,m=map(int,input().split())
d={}
for i in range(m):
  c,y=map(int,input().split())
  if c not in d.keys():
    d[c]=1
  else:
    d[c]+=1
  print('%06d%06d'%(c,d[c]))

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
"""
Created on Thu May 16 10:21:56 2019

@author: avina
"""

n,m = map(int, input().split())
l = []
for i in range(m):
  a,b = map(int, input().split())
  l.append((a,b))
d = {}
for i in range(1,n+1):
    d[i] =1
for i in range(m):
  a ,b = l[i]
  b = str(d[a]);a = str(a);
  e = len(a);e1 = len(b)
  r = '0'*(6 - e) + a + '0'*(6 - e1) + b
  print(r)
  d[l[i][0]] +=1

Submission status: Wrong Answer

Solution code:
N, M = map(int,input().split())
all_city = [list(map(int,input().split())) for i in range(M)]

city = {}
for i in all_city:
    if i[0] in city:
        city[i[0]].append(i[1])
    else:
        city[i[0]] = [i[1]]

under6 = {}
for i,k in city.items():
    city[i] = sorted(k)
    for j in range(len(k)):
        under6[k[j]] = j + 1

def change_Prefecture_code(prefecture):
    return str(prefecture).zfill(6)

def change_birth_code(birth_num):
    return str(birth_num).zfill(6)

for i in all_city:
    print(change_Prefecture_code(i[0]) + change_birth_code(under6[i[1]]))

Submission status: Wrong Answer

Solution code:
N, M = map(int,input().split())
all_city = [list(map(int,input().split())) for i in range(M)]

city = {}
for i in all_city:
    if i[0] in city:
        city[i[0]][city[i[0]].index(0)] = i[1]
    else:
        city[i[0]] = [0] * M
        city[i[0]][0] = i[1]


for i,k in city.items():
    city[i] = sorted(k)


for i, k in city.items():
    for j in range(len(k)):
        if k[j] == 0:
            continue
        else:
            break


def change_Prefecture_code(prefecture):
    return str(prefecture).zfill(6)

def change_birth_code(birth_num):
    return str(birth_num).zfill(6)

for i in all_city:
    print(change_Prefecture_code(i[0]) + change_birth_code(city[i[0]].index(i[1]) + 1))

Submission status: Wrong Answer

Solution code:
N, M = map(int,input().split())
all_city = [list(map(int,input().split())) for i in range(M)]

city = {}
for i in all_city:
    if i[0] in city:
        city[i[0]][city[i[0]].index(0)] = i[1]
    else:
        city[i[0]] = [0] * M
        city[i[0]][0] = i[1]


for i,k in city.items():
    city[i] = sorted(k)


for i, k in city.items():
    for j in range(len(k)):
        if k[j] == 0:
            continue
        else:
            break


def change_Prefecture_code(prefecture):
    return str(prefecture).zfill(6)

def change_birth_code(birth_num):
    return str(birth_num).zfill(6)
print(city)

for i in all_city:
    print(change_Prefecture_code(i[0]) + change_birth_code(city[i[0]].index(i[1]) + 1))

Submission status: Wrong Answer

Solution code:
N, M = map(int,input().split())
all_city = [list(map(int,input().split())) for i in range(M)]

city = {}
for i in all_city:
    if i[0] in city:
        city[i[0]][city[i[0]].index(0)] = i[1]
    else:
        city[i[0]] = [0] * M
        city[i[0]][0] = i[1]

print(city)

for i,k in city.items():
    city[i] = sorted(k)


for i, k in city.items():
    for j in range(len(k)):
        if k[j] == 0:
            continue
        else:
            break


def change_Prefecture_code(prefecture):
    return str(prefecture).zfill(6)

def change_birth_code(birth_num):
    return str(birth_num).zfill(6)
print(city)

for i in all_city:
    print(change_Prefecture_code(i[0]) + change_birth_code(city[i[0]].index(i[1]) + 1))

Submission status: Wrong Answer

Solution code:
N, M = map(int,input().split())
all_city = [list(map(int,input().split())) for i in range(M)]

city = {}
for i in all_city:
    if i[0] in city:
        city[i[0]][city[i[0]].index(100001)] = i[1]
    else:
        city[i[0]] = [100001] * M
        city[i[0]][0] = i[1]
        

for i,k in city.items():
    city[i] = sorted(k)

def change_Prefecture_code(prefecture):
    return str(prefecture).zfill(6)

def change_birth_code(birth_num):
    return str(birth_num).zfill(6)

for i in all_city:
    print(change_Prefecture_code(i[0]) + change_birth_code(city[i[0]].index(i[1]) + 1))

Submission status: Wrong Answer

Solution code:
n,m = map(int, input().split())
A = [[i] + input().split()+[''] for i in range(m)]
A.sort(key=lambda x:x[2])
A.sort(key=lambda x:x[1])

pref = -1
order = 1

for city in A:
    if pref == city[1]:
        order+=1
        city[2] = str(city[1]).rjust(6,'0') +str(order).rjust(6,'0')
    else:
        order = 1
        city[2] = str(city[1]).rjust(6,'0') +str(order).rjust(6,'0')
        pref = city[1]
A.sort(key=lambda x:x[0])
for city in A:
    print(city[2])

Submission status: Wrong Answer

Solution code:
n,m = map(int, input().split())
A = [[i] + input().split()+[''] for i in range(m)]
A.sort(key=lambda x:x[2])
A.sort(key=lambda x:x[1])

pref = -1
order = 1

for city in A:
    if pref == city[1]:
        order+=1
        city[2] = str(city[1]).rjust(8,'0') +str(order).rjust(8,'0')
    else:
        order = 1
        city[2] = str(city[1]).rjust(8,'0') +str(order).rjust(8,'0')
        pref = city[1]
A.sort(key=lambda x:x[0])
for city in A:
    print(city[2])

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
from operator import itemgetter

N, M = list(map(int, input().split()))
A = [[0] * 4 for i in range(M)]
for i in range(M):
    A[i][0], A[i][1] = list(map(int, input().split()))
    A[i][2] = i

sorted_A = sorted(A, key=itemgetter(1))
print(sorted_A)

P_num = [1]*N
for a in sorted_A:
    y = a[0]
    a[3] = P_num[y-1]
    P_num[y-1] += 1

print(sorted_A)
B = sorted(sorted_A, key=itemgetter(2))
for b in B:
    print("%06d%06d" % (b[0], b[3]))

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
from operator import itemgetter

N, M = list(map(int, input().split()))
A = [[0] * 4 for i in range(M)]
P = []
for i, a in enumerate(A):
    a[0], a[1] = list(map(int, input().split()))
    a[2] = i
    if not a[0] in P:
        P.append(a[0])

P_counts = [0]*len(P)
sorted_A = sorted(A, key=itemgetter(1))

for a in sorted_A:
    idx = P.index(a[0])
    P_counts[idx] += 1
    print(str(a[0]).zfill(6) + str(P_counts[idx]).zfill(6))

Submission status: Wrong Answer

Solution code:
def mks(num):
  s=str(num)
  if len(s)<6:
    s='0'*(6-len(s))+s
  return s

n,m=map(int,input().split())
arr=[]
for i in range(m):
  p,y=map(int,input().split())
  arr.append([p,y,i])
ans=[0]*m
arr=sorted(arr,key=lambda x:x[1])
arr=sorted(arr,key=lambda x:x[0])
tmp=arr[0][0]
cnt=1
for i in range(m):
  if arr[i][0]==tmp:
    s1,s2=mks(tmp),mks(cnt)
    ans[arr[i][2]]=s1+s2
    cnt+=1
  else:
    cnt=1
    tmp=arr[i][0]
    s1,s2=mks(tmp),mks(cnt)
    ans[arr[i][2]]=s1+s2
for i in range(m):
  print(ans[i])