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:
# -*- coding: utf-8 -*-
n,m = map(int, input().split())
i=0
lst = []
while i < m: 
    l = list(map(int, input().split()))
    l.append(i)
    lst.append(l)
    i+=1

ll=sorted(lst)
x=1
j=1
for k in ll:
    if x == k[0]:
        k[1]=x*1000000+j
    else:
        k[1]=(x+1)*1000000+1
        x=k[0]
        j=1
    j+=1
#ans
for ans in sorted(ll, key=lambda x:x[2]):
    print('{0:012d}'.format(ans[1]))

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
n,m = map(int, input().split())
i=0
lst = []
while i < m: 
    l = list(map(int, input().split()))
    l.append(i)
    lst.append(l)
    i+=1

ll=sorted(lst)
x=1
j=1
for k in ll:
    if x == k[0]:
        k[1]=str(x).rjust(6,'0') + str(j).rjust(6,'0')
    else:
        k[1]=str(x+1).rjust(6,'0') + str(1).rjust(6,'0')
        x=k[0]
        j=1
    j+=1
#ans
for ans in sorted(ll, key=lambda x:x[2]):
    print(ans[1])

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
n,m = map(int, input().split())
i=0
lst = []
while i < m: 
    l = list(map(int, input().split()))
    l.append(i)
    lst.append(l)
    i+=1

ll=sorted(lst)
i=1
j=1
for k in ll:
    if i == k[0]:
        k[1]=str(i).rjust(6,'0') + str(j).rjust(6,'0')
    else:
        k[1]=str(i+1).rjust(6,'0') + str(1).rjust(6,'0')
        i=k[0]
        j=1
    j+=1
#ans
sss= sorted(ll, key=lambda x:x[2])
for ans in sss:
    print(ans[1])

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
n,m = map(int, input().split())
i=0
lst = []
while i < m: 
    l = list(map(int, input().split()))
    l.append(i)
    lst.append(l)
    i+=1

ll=sorted(lst)
i=1
j=1
for k in ll:
    if i == k[0]:
        k.append(str(i).rjust(6,'0') + str(j).rjust(6,'0'))
    else:
        k.append(str(i+1).rjust(6,'0') + str(1).rjust(6,'0'))
        i=k[0]
        j=1
    j+=1
#ans
sss= sorted(ll, key=lambda x:x[2])
for ans in sss:
    print(ans[3])

Submission status: Wrong Answer

Solution code:
from collections import defaultdict
n_pref, m_city = list(map(int, input().split()))
import heapq
record = defaultdict(list)
cities = []
for i in range(m_city):
  pref, year = list(map(int, input().split()))
  cities.append({"pref": pref, "year": year})
  heapq.heappush(record[pref], year)
for city in cities:
  print(format(city["pref"], '06d'), format(record[city["pref"]].index(city["year"])+1, '06d'), sep="")

Submission status: Wrong Answer

Solution code:
ken_num, city_num = map(int,input().split())
city_list = [None for _ in range(city_num)]
ken_list = [1 for _ in range(ken_num+1)]
id_list = [None for _ in range(city_num)]
for index in range(city_num):
    city_list[index] = list(map(int,input().split()))
    city_list[index].append(index)
city_list = sorted(city_list, key=lambda x: x[1])

for index,city in enumerate(city_list):
    id_list[city[2]] = str(city[0]).zfill(6) + str(ken_list[city[0]]).zfill(6)
    ken_list[city[0]] += 1

print(id_list)

Submission status: Wrong Answer

Solution code:
N, M = list(map(int, input().split()))
PY = []
for i in range(M):
    p, y = list(map(int, input().split()))
    PY.append([p, y, i, 0])
PY.sort(key=lambda x: x[0])
PY.sort(key=lambda x: x[1])
city = PY[0][0]
city_start = 0
for i in range(len(PY)):
    if city == PY[i][0]:
        city_start += 1
    else:
        city = PY[i][0]
        city_start = 1
    PY[i][3] = str(city).zfill(6) + str(city_start).zfill(6)

PY.sort(key=lambda x: x[2])
for i in range(len(PY)):
    print(PY[i][3])

Submission status: Wrong Answer

Solution code:
#おそらくTLE
n, m = [int(_) for _ in input().split()]
city = []

for i in range(m):
    city.append(list(map(int, input().split())))

city2 = sorted(city)

tmp1 = city2[0][0]
tmp2 = 1
ID = {}

for k in range(m):
    if tmp1 == city2[k][0]:
        ID[city.index(city2[k])] = tmp2
        tmp2 += 1

    else:
        ID[city.index(city2[k])] = 1
        tmp2 = 2

for l in range(m):
    print("%06d%06d"%(city[l][0], ID[l]))

Submission status: Wrong Answer

Solution code:
n,m=map(int,input().split())
somelists=[]
for i in range(m):
    a,b=map(int,input().split())
    somelists.append([i,a,b])
    

somelists.sort(key=lambda x:(x[1],x[2]))

prefs=1
numbers=0
for x in somelists:
    
    if x[1]==prefs:
        numbers+=1
        
        x.append(numbers)
    if x[1]!=prefs:
        prefs+=1
        numbers=1
        x.append(numbers)

somelists.sort(key=lambda x:x[0])
for _ in range(m):
    print(str(somelists[_][1]).zfill(6)+str(somelists[_][3]).zfill(6))

Submission status: Wrong Answer

Solution code:
n,m=map(int,input().split())
somelists=[]
for i in range(m):
    a,b=map(int,input().split())
    somelists.append([i,a,b])

somelists.sort(key=lambda x:(x[1],x[2]))
numbers=0
prefs=1
for x in somelists:
    if x[1]==prefs:
        numbers+=1
        x.append(numbers)
    if x[1]!=prefs:
        numbers=1
        x.append(numbers)

somelists.sort(key=lambda x:x[0])
for _ in range(m):
    print(str(somelists[_][1]).zfill(6)+str(somelists[_][3]).zfill(6))

Submission status: Wrong Answer

Solution code:


import sys
input = sys.stdin.readline
sys.setrecursionlimit(2147483647)
INF=float("inf")
MOD=10**9+7
# A = [ int(input()) for _ in range(N) ]
##############################

N, M = map(int, input().split())
P = []
Y = []

from collections import defaultdict
pref = defaultdict(list)

for i in range(M):
    p, y = input().split()
    P.append(p)
    Y.append(y)

    pref[p].append(y)

#print(pref)

count = defaultdict(list)
for k, v in pref.items():
    v.sort()
    insert = {}
    for i in range(len(v)):
        insert[v[i]] = i+1

    count[k] = insert

#print(count)

for i in range(M):
    p = P[i]
    y = Y[i]
    idx = count[p][y]
    print('{:06}{:06}'.format(int(p), idx))

Submission status: Wrong Answer

Solution code:

import sys
input = sys.stdin.readline
sys.setrecursionlimit(2147483647)
INF=float("inf")
MOD=10**9+7
# A = [ int(input()) for _ in range(N) ]
##############################

N, M = map(int, input().split())
P = []
Y = []

from collections import defaultdict
pref = defaultdict(list)

for i in range(M):
    p, y = input().split()
    P.append(p)
    Y.append(y)

    pref[p].append(y)

count = defaultdict(list)
for k, v in pref.items():
    v.sort()
    insert = {}
    for i in range(len(v)):
        insert[int(v[i])] = i+1

    count[int(k)] = insert

# print(count)

for i in range(M):
    p = int(P[i])
    y = int(Y[i])
    idx = count[p][y]
    print('{pref:06}{id:06}'.format(pref=p, id=idx))

Submission status: Wrong Answer

Solution code:
# C - ID
from operator import itemgetter

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

for l in range(M):
    A[l].insert(0, l)

# print(A)
A.sort(key=itemgetter(2))
A.sort(key=itemgetter(1))
# print(A)

ID1 = [['0' for i in range(2)] for j in range(M)]
ID2 = [['0' for i in range(2)] for j in range(M)]
# print(ID1)

for i in range(M):
    ID1[i][0] = str(A[i][0])
    ID1[i][1] = str(A[i][1])
    while len(ID1[i][1]) < 6:
        ID1[i][1] = "0" + ID1[i][1]
ID1.sort(key=itemgetter(1))
# print(ID1)

count = 1
for j in range(1, M+1):
    if j <= M - 1:
        ID2[j - 1][0] = str(A[j - 1][0])
        if A[j - 1][1] == A[j][1]:
            ID2[j - 1][1] = str(count)
            count += 1
        else:
            ID2[j - 1][1] = str(count)
            count = 1
        while len(ID2[j - 1][1]) < 6:
            ID2[j - 1][1] = "0" + ID2[j - 1][1]
    else:
        ID2[M-1][0] = str(A[M-1][0])
        if A[M-1][1] == A[j - 2][1]:
            ID2[M-1][1] = str(count)
        else:
            ID2[M-1][1] = str(1)
        while len(ID2[M-1][1]) < 6:
            ID2[M-1][1] = "0" + ID2[M-1][1]

# print(ID2)

ID1.sort(key=itemgetter(0))
ID2.sort(key=itemgetter(0))

for n in range(M):
    ans = str(ID1[n][1])+str(ID2[n][1])
    print(ans)

Submission status: Wrong Answer

Solution code:
# C - ID
from operator import itemgetter

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

for l in range(M):
    A[l].insert(0, l)

A.sort(key=itemgetter(2))
A.sort(key=itemgetter(1))

ID1 = [['0' for i in range(2)] for j in range(M)]
ID2 = [['0' for i in range(2)] for j in range(M)]

for i in range(M):
    ID1[i][0] = str(A[i][0])
    ID1[i][1] = str(A[i][1])
    while len(ID1[i][1]) <= 6:
        ID1[i][1] = "0" + ID1[i][1]
ID1.sort(key=itemgetter(1))

count = 1
for j in range(1, M+1):
    if j <= M - 1:
        ID2[j - 1][0] = str(A[j - 1][0])
        if A[j - 1][1] == A[j][1]:
            ID2[j - 1][1] = str(count)
            count += 1
        else:
            ID2[j - 1][1] = str(count)
            count = 1
        while len(ID2[j - 1][1]) <= 6:
            ID2[j - 1][1] = "0" + ID2[j - 1][1]
    else:
        ID2[M-1][0] = str(A[M-1][0])
        if A[M-1][1] == A[j - 2][1]:
            ID2[M-1][1] = str(count)
        else:
            ID2[M-1][1] = str(1)
        while len(ID2[M-1][1]) <= 6:
            ID2[M-1][1] = "0" + ID2[M-1][1]

ID1.sort(key=itemgetter(0))
ID2.sort(key=itemgetter(0))

for n in range(M):
    ans = str(ID1[n][1])+str(ID2[n][1])
    print(ans)

Submission status: Wrong Answer

Solution code:
# C - ID
from operator import itemgetter

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

for l in range(M):
    A[l].insert(0, l)

# print(A)
A.sort(key=itemgetter(2))
A.sort(key=itemgetter(1))
# print(A)

ID1 = [['0' for i in range(2)] for j in range(M)]
ID2 = [['0' for i in range(2)] for j in range(M)]
# print(ID1)

for i in range(M):
    ID1[i][0] = str(A[i][0])
    ID1[i][1] = str(A[i][1])
    while len(ID1[i][1]) <= 6:
        ID1[i][1] = "0" + ID1[i][1]
ID1.sort(key=itemgetter(1))
# print(ID1)

count = 1
for j in range(1, M+1):
    if j <= M - 1:
        ID2[j - 1][0] = str(A[j - 1][0])
        if A[j - 1][1] == A[j][1]:
            ID2[j - 1][1] = str(count)
            count += 1
        else:
            ID2[j - 1][1] = str(count)
            count = 1
        while len(ID2[j - 1][1]) <= 6:
            ID2[j - 1][1] = "0" + ID2[j - 1][1]
    else:
        ID2[M-1][0] = str(A[M-1][0])
        if A[M-1][1] == A[j - 2][1]:
            ID2[M-1][1] = str(count)
        else:
            ID2[M-1][1] = str(1)
        while len(ID2[M-1][1]) <= 6:
            ID2[M-1][1] = "0" + ID2[M-1][1]

# print(ID2)

ID1.sort(key=itemgetter(0))
ID2.sort(key=itemgetter(0))

for n in range(M):
    ans = str(ID1[n][1])+str(ID2[n][1])
    print(ans)

Submission status: Wrong Answer

Solution code:
N,M=map(int,input().split())
PY=[[0,0] for i in range(M)] 
for i in range(M):
  P,Y=map(int,input().split())
  PY[i]=[P,Y,i]
PY.sort(key=lambda x:x[0])
PY.sort(key=lambda x:x[1])
prev=0
for i in range(M):
  if PY[i][0] != prev:
    count = 1
  else:
    count+=1
  prev=PY[i][0]
  ans=["0" for i in range(6 - len(str(prev)))]
  temp=["0" for i in range(6 - len(str(count)))]
  ans+=list(str(prev))+temp+list(str(count))
  PY[i][0]="".join(ans)
PY.sort(key=lambda x:x[2])
for i in range(M):
  print(PY[i][0])

Submission status: Wrong Answer

Solution code:
import math

N, M = map(int, input().split())
py = [list(map(int, input().split())) for _ in range(M)]
pyi = []
for i, x in enumerate(py):
    x.append(i)
    pyi.append(x)
pyi.sort()

dic = {}
number_list = []
for p, y, i in pyi:
    w = ''
    digit = math.floor(p // 10)
    w = "0" * (5 - digit) + str(p)

    if p in dic:
        dic[p] += 1
    else:
        dic[p] = 1
    digit2 = math.floor(dic[p] // 10)
    w += "0" * (5 - digit2) + str(dic[p])
    number_list.append([i, w])
number_list.sort()
for i in range(len(number_list)):
    print(number_list[i][1])

Submission status: Wrong Answer

Solution code:
N, M = map(int, input().split())
py = [list(map(int, input().split())) for _ in range(M)]
pyi = []
for i, x in enumerate(py):
    x.append(i)
    pyi.append(x)
pyi.sort()

dic = {}
number_list = []
for p, y, i in pyi:
    w = ''
    digit = round(p // 10)
    w = "0" * (5 - digit) + str(p)

    counter = 0
    if p in dic:
        dic[p] += 1
    else:
        dic[p] = 1
    digit2 = round(dic[p] // 10)
    w += "0" * (5 - digit2) + str(dic[p])
    number_list.append([i, w])
number_list.sort()
for i in range(len(number_list)):
    print(number_list[i][1])

Submission status: Wrong Answer

Solution code:
# coding: utf-8
# Your code here!
# coding: utf-8
# Your code here!
from operator import itemgetter

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

l=[[-1]*3 for i in range(M)]

for i in range(M):
    p,y=map(int,input().split())
    l[i]=[i,10**10*p+y]
#10**9なのわすれてた
l.sort(key=itemgetter(1))

pre_n=l[0][1]//10**10
count=0
for i in range(M):
    n=int(l[i][1]//(10**10))
    print(n,pre_n)
    if n==pre_n:
        count+=1
        l[i][1]=n*10**6+count
        
    else:
        pre_n=n
        count=1
        l[i][1]=n*10**6+count
l.sort()

for i in range(M):
    s=str(l[i][1])
    print("0"*(12-len(s))+s)

Submission status: Wrong Answer

Solution code:
# coding: utf-8
# Your code here!
from operator import itemgetter

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

l=[[-1]*3 for i in range(M)]

for i in range(M):
    p,y=map(int,input().split())
    l[i]=[i,10**10*p+y]
#10**9なのわすれてた
l.sort(key=itemgetter(1))

pre_n=l[0][1]//10**10
count=1
for i in range(M):
    n=l[i][1]//10**10
    if n==pre_n:
        l[i][1]=n*10**6+count
        count+=1
    else:
        pre_n=n
        count=1
        l[i][1]=n*10**6+count
l.sort()

for i in range(M):
    s=str(l[i][1])
    print("0"*(12-len(s))+s)

Submission status: Wrong Answer

Solution code:
# coding: utf-8
# Your code here!
from operator import itemgetter

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

l=[[-1]*3 for i in range(M)]

for i in range(M):
    p,y=map(int,input().split())
    l[i]=[i,10**10*p+y]
#10**9なのわすれてた
l.sort(key=itemgetter(1))

pre_n=l[0][1]//10**6
count=1
for i in range(M):
    n=l[i][1]//10**6
    if n==pre_n:
        l[i][1]=n*10**6+count
        count+=1
    else:
        pre_n=n
        count=1
        l[i][1]=n*10**6+count
l.sort()

for i in range(M):
    s=str(l[i][1])
    print("0"*(12-len(s))+s)

Submission status: Wrong Answer

Solution code:
# coding: utf-8
# Your code here!
from operator import itemgetter

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

l=[[-1]*3 for i in range(M)]

for i in range(M):
    p,y=map(int,input().split())
    l[i]=[i,10**6*p+y]
#10~5倍して足せばいいのでは
l.sort(key=itemgetter(1))

pre_n=l[0][1]//10**6
count=1
for i in range(M):
    n=l[i][1]//10**6
    if n==pre_n:
        l[i][1]=n*10**6+count
        count+=1
    else:
        pre_n=n
        count=1
        l[i][1]=n*10**6+count
l.sort()

for i in range(M):
    s=str(l[i][1])
    print("0"*(12-len(s))+s)

Submission status: Wrong Answer

Solution code:
import bisect
import collections

N, M = map(int, input().split())
PM = [[int(j) for j in input().split()] for i in range(M)]
A = collections.defaultdict(list)
for x, y in sorted(PM):
    A[x] += [y]
for x, y in PM:
    z = bisect.bisect(A[x], y)
    print('%06d%06d'%(x,y))

Submission status: Wrong Answer

Solution code:
from operator import itemgetter
N,M =[int(x) for x in input().split()]
ans = []
for i in range(M):
  p,y = [int(x) for x in input().split()]
  ans1 = [p,y,i]
  ans += [ans1]
ans = sorted(ans,key=itemgetter(1))
ans = sorted(ans,key=itemgetter(0))
cnt = 0
pcnt = 1
for i in range(M):
  if ans[i][0] == pcnt:
    cnt += 1
    ans[i][0] = "{:06d}".format(ans[i][0])+ "{:06d}".format(cnt)
  elif ans[i][0] == pcnt+1:
    pcnt +=1
    cnt = 1
    ans[i][0] = "{:06d}".format(ans[i][0])+ "{:06d}".format(cnt)
ans = sorted(ans,key=itemgetter(2))
for i in range(M):
	print(ans[i][0])

Submission status: Wrong Answer

Solution code:

from operator import itemgetter
N,M =[int(x) for x in input().split()]
ans = []
for i in range(M):
  p,y = [int(x) for x in input().split()]
  ans1 = [p,y,i]
  ans += [ans1]
ans = sorted(ans,key=itemgetter(1))
ans = sorted(ans,key=itemgetter(0))
cnt = 0
pcnt = 1
for i in range(M):
  if ans[i][0] == pcnt:
    cnt += 1
    ans[i][0] = "{:06d}".format(ans[i][0])+ "{:06d}".format(cnt)
  else:
    pcnt +=1
    cnt = 1
    ans[i][0] = "{:06d}".format(ans[i][0])+ "{:06d}".format(cnt)
ans = sorted(ans,key=itemgetter(2))
for i in range(M):
	print(ans[i][0])

Submission status: Wrong Answer

Solution code:
n, m = map(int, input().split())

city = []
for i in range(m):
    city.append(list(map(int,input().split())))
    city[i] = [i+1, city[i][0], city[i][1]]

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

ans = []
i = city[0][1]
k = 1
for m in city:
    if i == m[1]:
        ans.append([m[0],m[1],k])
        k += 1
    else:
        i = m[1]
        k = 1
        ans.append([m[0],m[1],k])

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

for n in ans:
    print("{0:06d}".format(n[1])+"{0:06d}".format(n[2]))

Submission status: Wrong Answer

Solution code:
n, m = map(int, input().split())

city = []
for i in range(m):
    city.append(list(map(int,input().split())))
    city[i] = [i+1, city[i][0], city[i][1]]

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

ans = []
i = city[0][1]
k = 1
for m in city:
    if i == m[1]:
        ans.append([m[0],m[1],k])
        k += 1
    else:
        i = m[1]
        ans.append([m[0],m[1],1])

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

for n in ans:
    #print(n[1],n[2])
    print("{0:06d}".format(n[1])+"{0:06d}".format(n[2]))

Submission status: Wrong Answer

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

n, m = map(int, input().split())

py_list = [list(map(int, input().split()))+[i] for i, m in enumerate(range(m))]
py_list.sort(key=lambda x: x[1])

cursor_p = 1
current = 0
city = None
addresses = []
for py in py_list:
    p = py[0]
    y = py[1]
    idx = py[2]

    if p == cursor_p:
        current += 1
    elif p > cursor_p:
        current = 1
        cursor_p = p
    city = str(current).zfill(6)
    pref = str(cursor_p).zfill(6)

    addresses.append((idx, pref+city))

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

for address in addresses:
    print(address[1])

Submission status: Wrong Answer

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

n, m = map(int, input().split())

py_list = [tuple(map(int, input().split())) for m in range(m)]
py_list.sort(key=lambda x: x[1])

cursor_p = 1
current = 0
city = None
for py in py_list:
    p = py[0]
    y = py[1]

    if p == cursor_p:
        current += 1
    elif p > cursor_p:
        current = 1
        cursor_p = p
    city = str(current).zfill(6)
    pref = str(cursor_p).zfill(6)

    print(pref+city)

Submission status: Wrong Answer

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

n, m = map(int, input().split())

py_list = [tuple(map(int, input().split())) for m in range(m)]
py_list.sort(key=lambda x: x[1])

print(py_list)

cursor_p = 1
current = 0
city = None
for py in py_list:
    p = py[0]
    y = py[1]

    if p == cursor_p:
        current += 1
    elif p > cursor_p:
        current = 1
        cursor_p = p
    city = str(current).zfill(6)
    pref = str(cursor_p).zfill(6)

    print(pref+city)

Submission status: Wrong Answer

Solution code:
from collections import deque

a,b = map(int,input().split())

c = [[] for i in range(a)]
d = [deque() for i in range(a)]
z = []
for _ in range(b):
  f,g = map(int,input().split())
  c[f - 1].append(g)
  d[f - 1].append(0)
  for num in range(len(c[f-1])):
      if c[f - 1][num] >= g:
          d[f-1][num] += 1
  z.append([f,g])

x =''
y = ''
for j in range(b):                    
    x = str(z[j][0])
    x = '0' * (6 - len(x)) + x
    y = str(d[z[j][0] - 1].popleft())
    y = '0' * (6 - len(y)) + y
    print(x + y)

Submission status: Wrong Answer

Solution code:
from collections import deque

a,b = map(int,input().split())

c = [[] for i in range(a)]
d = [deque() for i in range(a)]
z = []
for _ in range(b):
  f,g = map(int,input().split())
  c[f - 1].append(g)
  d[f - 1].append(0)
  for num in range(len(c[f-1])):
      if c[f - 1][num] >= g:
          d[f-1][num] += 1
  z.append([f,g])

print(c,d)
x =''
y = ''
for j in range(b):                    
    x = str(z[j][0])
    x = '0' * (6 - len(x)) + x
    y = str(d[z[j][0] - 1].popleft())
    y = '0' * (6 - len(y)) + y
    print(x + y)

Submission status: Wrong Answer

Solution code:
a,b = map(int,input().split())

c = [[] for i in range(a)]
for _ in range(b):
  f,g = map(int,input().split())
  c[f - 1].append(g)

d = c.copy()


for i in range(a):
    if c[i] != []:
        c[i].sort()

#print(c)
h = []
x =''
y = ''
for j in range(a):                    
    x = str(j + 1)
    while len(x) <= 5:
        x = '0' + x
    if c[j] != []:
        for k in range(len(c[j])):
            for l in range(len(c[j])):
                if c[j][k] == d[j][l]:
                    y = str(k + 1)
                    while len(y) <= 5:
                        y = '0' + y
                    print(x+y)

Submission status: Wrong Answer

Solution code:
from collections import defaultdict
n,m = list(map(int, input().split()))
cities = defaultdict(list)
cities = [ list(map(int, input().split())) for _ in range(m)]
sorted = sorted(
  cities,
  key = lambda x: (x[0], x[1])
)
hoge = 0
first_code = 0
fuga = 0
second_code = 0
for city in sorted:
  if(hoge < city[0]):
    hoge = city[0]
    first_code += 1
    fuga = 0
    second_code = 0
  if(fuga < city[1]):
    fuga = city[1]
    second_code += 1    
  print(format(first_code, '06'), format(second_code, '06'),sep="")

Submission status: Wrong Answer

Solution code:
from collections import defaultdict
n,m = list(map(int, input().split()))
cities = defaultdict(list)
cities = [ list(map(int, input().split())) for _ in range(m)]
sorted = sorted(
  cities,
  key = lambda x: (x[0], x[1])
)
hoge = 0
first_code = 0
fuga = 0
second_code = 0
for city in sorted:
  if(hoge < city[0]):
    hoge = city[0]
    first_code += 1
    fuga = 0
    seconde_code = 0
  if(fuga < city[1]):
    fuga = city[1]
    seconde_code += 1    
  print(format(first_code, '06'), format(second_code, '06'),sep="")

Submission status: Wrong Answer

Solution code:
import sys
input=sys.stdin.readline
 
N,M = map(int, input().split())
 
pref = [[0] for i in range(N+1)]
import collections
q = collections.deque()
 
for i in range(M):
    p,y = map(int, input().split())
    pref[p].append(y)
    q.append((p,y))
for p in pref:
    p.sort()
 
print(q)
import bisect
for p,y in q:
    print(p,y)
    print("%06d%06d" %(p, bisect.bisect_left(pref[p], y)))

Submission status: Wrong Answer

Solution code:
dic_pref = {}

def add_city(pno,year):
    if pno not in dic_pref:
        dic_pref[pno] = 1
    else:
        dic_pref[pno] += 1

N,M = map(int,input().split())
for _ in range(M):
    P,Y = map(int,input().split())
    add_city(P,Y)

alist = sorted(dic_pref.items(),key=lambda x:x[0])

for p in alist:
    for num in range(p[1]):
        print("{0:06}{1:06}".format(p[0],num+1))

Submission status: Wrong Answer

Solution code:
dic_pref = {}

def add_city(pno,year):
    if pno not in dic_pref:
        dic_pref[pno] = 1
    else:
        dic_pref[pno] += 1

N,M = map(int,input().split())
for _ in range(M):
    P,Y = map(int,input().split())
    add_city(P,Y)

alist = sorted(dic_pref.items(),key=lambda x:-x[0])

for p in alist:
    for num in range(p[1]):
        print("{0:06}{1:06}".format(p[0],num+1))

Submission status: Wrong Answer

Solution code:
from operator import itemgetter

N, M = map(int, input().split())
P = [0] * M
Y = [0] * M
for i in range(M):
    P[i], Y[i] = map(str, input().split())
n = [i for i in range(M)]

P, Y, n = zip(*sorted(zip(P, Y, n), key=itemgetter(0, 1)))

count = 1
ans = []
ans.append(P[0].zfill(6) + str(count).zfill(6))

for i in range(M - 1):
    if P[i + 1] == P[i]:
        count += 1
    else:
        count = 1
    ans.append(P[i + 1].zfill(6) + str(count).zfill(6))

n, ans = zip(*sorted(zip(n, ans), key=itemgetter(0)))

for i in ans:
    print(i)

Submission status: Wrong Answer

Solution code:
from operator import itemgetter

N, M = map(int, input().split())
P = [0] * M
Y = [0] * M
for i in range(M):
    P[i], Y[i] = input().split()
n = [i for i in range(M)]

P, Y, n = zip(*sorted(zip(P, Y, n), key=itemgetter(0, 1)))

count = 1
ans = []
ans.append(P[0].zfill(6) + str(count).zfill(6))

for i in range(M - 1):
    if P[i + 1] == P[i]:
        count += 1
    else:
        count = 1
    ans.append(P[i + 1].zfill(6) + str(count).zfill(6))

n, ans = zip(*sorted(zip(n, ans), key=itemgetter(0)))

for i in ans:
    print(i)

Submission status: Wrong Answer

Solution code:
N, M = map(int, input().split())
P = [0] * M
Y = [0] * M
for i in range(M):
    P[i], Y[i] = input().split()
n = [i for i in range(M)]

P, Y, n = zip(*sorted(list(zip(P, Y, n)), key=lambda x:(x[0], x[1])))

count = 1
ans = []
ans.append(P[0].zfill(6) + str(count).zfill(6))

for i in range(M - 1):
    if P[i + 1] == P[i]:
        count += 1
    else:
        count = 1
    ans.append(P[i + 1].zfill(6) + str(count).zfill(6))

n, ans = zip(*sorted(zip(n, ans)))

for i in ans:
    print(i)

Submission status: Wrong Answer

Solution code:
N, M = map(int, input().split())
P = [0] * M
Y = [0] * M
for i in range(M):
    P[i], Y[i] = input().split()
n = [i for i in range(M)]

P, Y, n = zip(*sorted(zip(P, Y, n), key=lambda x:(x[0], x[1])))

count = 1
ans = []
ans.append(P[0].zfill(6) + str(count).zfill(6))

for i in range(M - 1):
    int(count)
    if P[i + 1] == P[i]:
        count += 1
    else:
        count = 1
    ans.append(P[i + 1].zfill(6) + str(count).zfill(6))

n, ans = zip(*sorted(zip(n, ans)))

for i in ans:
    print(i)

Submission status: Wrong Answer

Solution code:
N, M = map(int, input().split())
P = [0] * M
Y = [0] * M
for i in range(M):
    P[i], Y[i] = input().split()
n = [i for i in range(M)]

P, Y, n = zip(*sorted(zip(P, Y, n), key=lambda x:(x[0], x[1])))

count = 1
ans = []
ans.append(P[0].zfill(6) + str(count).zfill(6))

for i in range(M - 1):
    if P[i + 1] == P[i]:
        count += 1
    else:
        count = 1
    ans.append(P[i + 1].zfill(6) + str(count).zfill(6))

n, ans = zip(*sorted(zip(n, ans)))

for i in ans:
    print(i)

Submission status: Wrong Answer

Solution code:
def main():
    import sys
    import bisect
    input = sys.stdin.readline

    n, m = map(int, input().split())
    query = []
    result =  [[] for i in range(n)]
    for _ in range(m):
        p, y = map(int, input().split())
        query.append((p, y))
        result[p-1].append(y)

    result = [sorted(i) for i in result]
 
    for city in query:
        rank = bisect.bisect_left(result[city[0]-1], city[1])
        ans = "%06d%06d"%(city[0],rank)
        print(ans)

main()

Submission status: Wrong Answer

Solution code:
def main():
    import sys
    import bisect
    input = sys.stdin.readline

    n, m = map(int, input().split())
    query = []
    result =  [[] for i in range(n)]
    for _ in range(m):
        p, y = map(int, input().split())
        query.append((p, y))
        result[p-1].append(y)

    result = [sorted(i) for i in result]
 
    for city in query:
        rank = bisect.bisect_left(result[city[0]-1], city[1])
        resultStr = "{}{}".format(str(city[0]).zfill(6), str(rank).zfill(6))
        print(resultStr)

main()

Submission status: Wrong Answer

Solution code:
n, m = map(int, input().split())
query = []
for i in range(m):
    query.append(list(map(int, input().split())))
result =  [[]]*n

for city in query:
    result[city[0]-1].append(city[1])

for i in result:
    i.sort()

for city in query:
    rank = result[city[0]-1].index(city[1])+1
    resultStr = "{}{}".format(str(city[0]).zfill(6), str(rank).zfill(6))
    print(resultStr)

Submission status: Wrong Answer

Solution code:
n, m = map(int, input().split())
query = []
for i in range(m):
    qList = list(map(int, input().split()))
    query.append(qList)
result =  [[]]*n
for city in query:
    result[city[0]-1].append(city[1])
for i in result:
    i.sort()
for city in query:
    rank = result[city[0]-1].index(city[1])+1
    resultStr = "{}{}".format(str(city[0]).zfill(6), str(rank).zfill(6))
    print(resultStr)

Submission status: Wrong Answer

Solution code:
N, M = map(int, input().split())
P = [0] * M
Y = [0] * M
for i in range(M):
    P[i], Y[i] = input().split()
n = [i for i in range(M)]

P, Y, n = zip(*sorted(zip(P, Y, n)))

count = 1
ans = []
ans.append(P[0].zfill(6) + str(count).zfill(6))

for i in range(M - 1):
    if P[i + 1] == P[i]:
        count += 1
    else:
        count = 1
    ans.append(P[i + 1].zfill(6) + str(count).zfill(6))

n, ans = zip(*sorted(zip(n, ans)))

for i in ans:
    print(i)

Submission status: Wrong Answer

Solution code:
n, m = map(int, input().split())

cities = {}

def to_id(x):
  return '0' * (6 - len(str(x))) + str(x)

for i in range(m):
  p, y = map(int, input().split())
  if p in cities.keys():
    cities[p] += 1
  else:
    cities[p] = 1
  
for p in range(1, n+1):
  if p in cities.keys():
    p_id = to_id(p)
    for i in range(cities[p]):
      print(p_id + to_id(i+1))

Submission status: Wrong Answer

Solution code:
N, M = map(int, input().split())
P = [0] * M
Y = [0] * M
for i in range(M):
    P[i], Y[i] = input().split()
n = [i for i in range(M)]

P, Y, n = zip(*sorted(zip(P, Y, n)))

count = 1
ans = [0] * M
ans[0] = P[0].zfill(6) + str(count).zfill(6)

for i in range(M - 1):
    if P[i + 1] == P[i]:
        count += 1
    else:
        count = 1
    ans[i + 1] = P[i + 1].zfill(6) + str(count).zfill(6)

n, ans = zip(*sorted(zip(n, ans)))

for i in ans:
    print(i)

Submission status: Wrong Answer

Solution code:
N, M = map(int, input().split())
P = [0] * M
Y = [0] * M
for i in range(M):
    P[i], Y[i] = input().split()
n = [i for i in range(M)]

P, Y, n = zip(*sorted(zip(P, Y, n)))

count = 1
ans = []
ans.append('0' * (6 - len(P[0])) + P[0] + '0' * (6 - len(str(count))) + str(count))

for i in range(M - 1):
    if P[i + 1] == P[i]:
        count += 1
    else:
        count = 1
    ans.append('0' * (6 - len(P[i + 1])) + P[i + 1] + '0' * (6 - len(str(count))) + str(count))

n, ans = zip(*sorted(zip(n, ans)))

for i in ans:
    print(i)