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:
N, M = map(int, input().split())
PYlist = [tuple(map(int, input().split())) for _ in range(M)]
from copy import deepcopy
PYsorted = sorted(deepcopy(PYlist), key=lambda x: x[0])


def zero_ume(num: int) -> str:
    return (6 - len(str(num))) * "0" + str(num)


now_ken = 0
ans_dict = {}
for p, y in PYsorted:
    if p != now_ken:
        now_num = 1
        now_ken = p
    else:
        now_num += 1
    ans_dict[(p, y)] = zero_ume(p) + zero_ume(now_num)

for py in PYlist:
    print(ans_dict[py])

Submission status: Wrong Answer

Solution code:
N, M = map(int, input().split())
PYlist = [tuple(map(int, input().split())) for _ in range(M)]
from copy import deepcopy
PYsorted = sorted(deepcopy(PYlist), key=lambda x: x[1])


def zero_ume(num: int) -> str:
    return (6 - len(str(num))) * "0" + str(num)


now_ken = 0
ans_dict = {}
for p, y in PYsorted:
    if p != now_ken:
        now_num = 1
        now_ken = p
    else:
        now_num += 1
    ans_dict[(p, y)] = zero_ume(p) + zero_ume(now_num)

for py in PYlist:
    print(ans_dict[py])

Submission status: Wrong Answer

Solution code:
N, M = map(int, input().split())
PYlist = [tuple(map(int, input().split())) for _ in range(M)]
from copy import deepcopy
PYsorted = sorted(deepcopy(PYlist), key=lambda x: x[1])
print(PYlist)
print(PYsorted)


def zero_ume(num: int) -> str:
    return (6 - len(str(num))) * "0" + str(num)


now_ken = 0
ans_dict = {}
for p, y in PYsorted:
    if p != now_ken:
        now_num = 1
        now_ken = p
    else:
        now_num += 1
    ans_dict[(p, y)] = zero_ume(p) + zero_ume(now_num)

for py in PYlist:
    print(ans_dict[py])

Submission status: Wrong Answer

Solution code:
import bisect
from collections import defaultdict
n,m = map(int,input().split())
p = [list(map(int, input().split())) for _ in range(m)]

a = defaultdict(list)
for x,y in sorted(p):
    a[x].append(y)
for x,y in p:
    z=bisect.bisect(a[x],y)
    print("{0:06d}{0:06d}".format(x,z))

Submission status: Wrong Answer

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

for i in range(M):
    p,y=[int(i) for i in input().split()]
    PY[p-1].append((y,i))

ans=[None]*M
for j,py in enumerate(PY): #jが県番号
    py.sort()
    for k,(y,i) in enumerate(py):
        print(k,y,i) #kが県内での順番、yが創立年、iが出力順
        ans[i]=str(j+1).zfill(6) + str(k+1).zfill(6)

print(*ans,sep="\n")

Submission status: Wrong Answer

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

for i in range(M):
    p,y=[int(i) for i in input().split()]
    py.append((p,y))
    PY[p-1].append(y)

for j in range(N):
    PY[j]=sorted(PY[j])

for i in range(M):
    p,y=py.pop(0)
    #print(PY[p].index(y))
    p_zero=6-len(str(p-1))
    y_zero=6-len(str(PY[p-1].index(y)))
    print("0"*p_zero + str(p) + "0"*y_zero + str(PY[p-1].index(y)+1))

Submission status: Wrong Answer

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

for i in range(M):
    p,y=[int(i) for i in input().split()]
    p-=1
    py.append((p,y))
    PY[p].append(y)

for i in range(N):
    PY[i].sort()

for i in range(M):
    p,y=py.pop(0)
    #print(PY[p].index(y))
    p_zero=6-len(str(p))
    y_zero=6-len(str(PY[p].index(y)))
    print("0"*p_zero + str(p+1) + "0"*y_zero + str(PY[p].index(y)+1))

Submission status: Wrong Answer

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

for i in range(M):
    p,y=[int(i) for i in input().split()]
    p-=1
    py.append((p,y))
    PY[p].append(y)

for i in range(N):
    PY[i]=sorted(PY[i])

for i in range(M):
    p,y=py.pop(0)
    #print(PY[p].index(y))
    p_zero=6-len(str(p))
    y_zero=6-len(str(PY[p].index(y)))
    print("0"*p_zero + str(p+1) + "0"*y_zero + str(PY[p].index(y)+1))

Submission status: Wrong Answer

Solution code:
import copy

n,m = map(int,input().split())
dic = {}

for i in range(m):
    p,y = map(int,input().split())
    dic[y] = p

sd = copy.deepcopy(dic)
#print(sd.items())
sd = sorted(sd.items(),key=lambda x:x[0])
sd = sorted(sd,key=lambda x:x[1])

ken = sd[0][1]
counter = 0
ans_dic = {}
#print(sd)
for y,k in sd:
    if ken == k:
        counter +=1
    else:
        counter = 1
        ken = k
    tmp = str(k).zfill(6) + str(counter).zfill(6)
    ans_dic[y] = tmp

for i in dic.keys():
    print(ans_dic[i])

Submission status: Wrong Answer

Solution code:
t=input()
N=int(t.split()[0])
M=int(t.split()[1])

city=[0]*M
for i in range(M):
  te=[int(x) for x in input().split()]
  city[i]={'i':i+1,'p':int(te[0]),'y':int(te[1])}

city_sorted = sorted(city,key = lambda x: (x['p'], x['y']))

x=0
temp_p=city_sorted[0]['p']
for c in city_sorted:
  if temp_p == c['p']:
    x+=1
  else:
    print("hoge")
    temp_p=c['p']
    x=1
  c['id']="{0:06d}{1:06d}".format(c['p'],x)
  
for ci in city:
  print(ci['id'])

Submission status: Wrong Answer

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

dic = {}
for i in range(m):
    c,y = map(int,input().split())
    dic[y] = c
#print(dic)

dic2 = copy.deepcopy(dic)
#print(dic)
dic2 = sorted(dic.items(),key=lambda x:x[1],reverse=True)
dic2 = sorted(dic.items(),key=lambda x:x[0])#,reverse=True)
#print(dic2)
#[(32, 1), (12, 1), (63, 2)]

ken = dic2[0][1]
counter = 0
ans = {}

for y,k in dic2:
    if ken == k:
        counter +=1
    else:
        counter = 1
    tmp = str(k).zfill(6) + str(counter).zfill(6)
    ans[y] = tmp

for i in dic.keys():
    print(ans[i])

Submission status: Wrong Answer

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

dic = {}
for i in range(m):
    c,y = map(int,input().split())
    dic[y] = c
#print(dic)

dic2 = copy.deepcopy(dic)
#print(dic)
dic2 = sorted(dic.items(),key=lambda x:x[0])#,reverse=True)
dic2 = sorted(dic.items(),key=lambda x:x[1])#,reverse=True)
#print(dic2)
#[(32, 1), (12, 1), (63, 2)]

ken = dic2[0][1]
counter = 0
ans = {}

for y,k in dic2:
    if ken == k:
        counter +=1
    else:
        counter = 1
    tmp = str(k).zfill(6) + str(counter).zfill(6)
    ans[y] = tmp

for i in dic.keys():
    print(ans[i])

Submission status: Wrong Answer

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

dic = {}
for i in range(m):
    c,y = map(int,input().split())
    dic[y] = c
#print(dic)

dic2 = copy.deepcopy(dic)
#print(dic)
dic2 = sorted(dic.items(),key=lambda x:x[0])#,reverse=True)
dic2 = sorted(dic.items(),key=lambda x:x[1])#,reverse=True)
print(dic2)
#[(32, 1), (12, 1), (63, 2)]

ken = dic2[0][1]
counter = 0
ans = {}

for y,k in dic2:
    if ken == k:
        counter +=1
    else:
        counter = 1
    tmp = str(k).zfill(6) + str(counter).zfill(6)
    ans[y] = tmp

for i in dic.keys():
    print(ans[i])

Submission status: Wrong Answer

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

dic = {}
for i in range(m):
    c,y = map(int,input().split())
    dic[y] = c
#print(dic)

dic2 = copy.deepcopy(dic)
#print(dic)
dic2 = sorted(dic.items(),key=lambda x:x[0])#,reverse=True)
dic2 = sorted(dic.items(),key=lambda x:x[1])#,reverse=True)
#print(dic2)
#[(32, 1), (12, 1), (63, 2)]

ken = dic2[0][1]
counter = 0
ans = {}

for y,k in dic2:
    if ken == k:
        counter +=1
    else:
        counter = 0
    k = str(ken).zfill(6) + str(counter).zfill(6)
    ans[y] = k

for i in dic.keys():
    print(ans[i])

Submission status: Wrong Answer

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

dic = {}
for i in range(m):
    c,y = map(int,input().split())
    dic[y] = c

dic2 = copy.deepcopy(dic)
dic2 = sorted(dic.items(),key=lambda x:x[0])#,reverse=True)
dic2 = sorted(dic.items(),key=lambda x:x[1])#,reverse=True)

ken = int(dic2[0][1])
counter = 0
ans = {}

for y,k in dic2:
    if ken == k:
        counter +=1
    else:
        counter = 0
    k = str(ken).zfill(6) + str(counter).zfill(6)
    ans[y] = k

for i in dic.keys():
    print(ans[i])

Submission status: Wrong Answer

Solution code:
import collections
City = collections.namedtuple("City", ("number", "pref", "year"))

n, m = [int(i) for i in input().split()]
cities = []
for i in range(m):
    pref, year = input().split()
    city = City(i, int(pref), int(year))
    cities.append(city)
id_numbers = []
cities.sort(key=lambda x: x.year)
cities.sort(key=lambda x: x.pref)
prev_pref = None
for city in cities:
    if prev_pref is None or city.pref != prev_pref:
        rank = 1
    else:
        rank += 1
    id_numbers.append((city.number, city.pref, rank))
    prev_pref = city.pref
id_numbers.sort(key=lambda x: x[0])
for i in id_numbers:
    print("{:0>6}{:0>6}".format(i[1], i[0]))

Submission status: Wrong Answer

Solution code:
import collections
City = collections.namedtuple("City", ("number", "pref", "year"))

n, m = [int(i) for i in input().split()]
cities = []
for i in range(m):
    pref, year = input().split()
    city = City(i, int(pref), int(year))
    cities.append(city)
id_numbers = []
cities.sort(key=lambda x: x.year)
cities.sort(key=lambda x: x.pref)
prev_pref = None
for city in cities:
    if prev_pref is None or city.pref != prev_pref:
        rank = 1
    else:
        rank += 1
    id_numbers.append((city.number, city.pref, rank))
    prev_pref = city.pref
id_numbers.sort(key=lambda x: x[0])
for i in id_numbers:
    print("{:0>6}{:0>6}".format(i[0], i[1]))

Submission status: Wrong Answer

Solution code:
def two_int():
    N, K = map(int, input().split())
    return N,K

def one_int():
    return int(input())

def one_str():
    return input()

def many_int():
    return list(map(int, input().split()))

N,M = two_int()

dicts={}

for i in range(M):
    P,S = two_int()
    
    pref_str=str(P)
    city_str=""
    
    if P not in dicts:
        dicts[P]={}
    
    if S not in dicts[P]:
        dicts[P][S] = len(dicts[P])+1
    
    city_str=str(dicts[P][S])
    
    print(pref_str.zfill(6)+city_str.zfill(6))

Submission status: Wrong Answer

Solution code:

N, M = map(int, input().split())
cities = []
prefectures = [[] for _ in range(N+1)]

for i in range(M):
  p, y = map(int, input().split())
  cities.append((p, y))
  prefectures[p].append((y))

for i in range(N+1):
  prefectures[i] = sorted(prefectures[i])

for (p, y) in cities:
  x = prefectures[p].index(y) + 1
  pid = "00000" + str(p)
  xid = "00000" + str(x)
  print(pid[:6] + xid[:6])

Submission status: Wrong Answer

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

prefectures = [[] for i in range(N)]
#  print(prefectures)

for city in range(M):
    P, Y = map(int, input().split())
    prefectures[P-1].append(Y)
#  print(prefectures)

for prefecture, cities in enumerate(prefectures):
    if cities == []:
        continue
    else:
        cities.sort()
    #  print(prefecture)
    for x, city in enumerate(cities):
        temp = '{0:06d}'.format(prefecture+1)
        temp = temp + '{0:06d}'.format(x+1)
        print(temp)

Submission status: Wrong Answer

Solution code:
import bisect

n, m = map(int, input().split())
cities = [[] for _ in range(n)]
ans = []

for i in range(m):
    p, y = map(int, input().split())
    idx = bisect.bisect_left(cities[p-1], y)
    cities[p-1].insert(idx, y)
    ans.append(str(p).zfill(6) + str(idx+1).zfill(6))
    # py.append(list(map(int, input().split())))

# print(cities)
for i in range(len(ans)):
    print(ans[i])

Submission status: Wrong Answer

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

# for i in range(M):
#     P_num,Y_num = map(int,input().split(" "))
#     P.append(P_num)
#     Y.append(Y_num)

Py = [input().split(" ") for i in range(M)]
P = [int(Py[i][0]) for i in range(len(Py))]
Y = [int(Py[i][1]) for i in range(len(Py))]

#辞書を作成
city = []

for i in range(M):
    city.append({"prefecture":P[i], "year":Y[i]})

#識別番号を作成

#県iのの市のデータのみを集める
order = []
calc_city_num = {}
for i in range(1,N+1):
    for j in range(len(city)):
        if city[j]["prefecture"] == i:
            calc_city_num.setdefault(j,city[j]["year"])


    #この中で創設時期が早い順に並べ替え、つまり、yearを並び替え
    order.append(sorted(calc_city_num.items(), key=lambda x:x[1]))
    calc_city_num.clear()


#県iの市の番号を作成する
for i in range(1,len(order)+1):
    for j in range(len(order[i-1])):
        result = str(str(i).zfill(6) + str(j+1).zfill(6))
        city[int(order[i-1][j][0])].setdefault("num",result)

for i in range(M):
    print(city[i])

Submission status: Wrong Answer

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

# for i in range(M):
#     P_num,Y_num = map(int,input().split(" "))
#     P.append(P_num)
#     Y.append(Y_num)

Py = [input().split(" ") for i in range(M)]
P = [int(Py[i][0]) for i in range(len(Py))]
Y = [int(Py[i][1]) for i in range(len(Py))]

#辞書を作成
city = []

for i in range(M):
    city.append({"prefecture":P[i], "year":Y[i]})

#識別番号を作成

#県iのの市のデータのみを集める
order = []
calc_city_num = {}
for i in range(1,N+1):
    for j in range(len(city)):
        if city[j]["prefecture"] == i:
            calc_city_num.setdefault(j,city[j]["year"])


    #この中で創設時期が早い順に並べ替え、つまり、yearを並び替え
    order.append(sorted(calc_city_num.items(), key=lambda x:x[1]))
    calc_city_num.clear()


#県iの市の番号を作成する
for i in range(1,len(order)+1):
    for j in range(len(order[i-1])):
        result = str(str(j+1).zfill(6) + str(i).zfill(6))
        city[int(order[i-1][j][0])-1].setdefault("num",result)

for i in range(M):
    print(city[i]["num"])

Submission status: Wrong Answer

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

# for i in range(M):
#     P_num,Y_num = map(int,input().split(" "))
#     P.append(P_num)
#     Y.append(Y_num)

Py = [input().split(" ") for i in range(M)]
P = [int(Py[i][0]) for i in range(len(Py))]
Y = [int(Py[i][1]) for i in range(len(Py))]

#辞書を作成
city = []

for i in range(M):
    city.append({"prefecture":P[i], "year":Y[i]})

#識別番号を作成

#県iのの市のデータのみを集める
order = []
calc_city_num = {}
for i in range(1,N+1):
    for j in range(len(city)):
        if city[j]["prefecture"] == i:
            calc_city_num.setdefault(j,city[j]["year"])


    #この中で創設時期が早い順に並べ替え、つまり、yearを並び替え
    order.append(sorted(calc_city_num.items(), key=lambda x:x[1]))
    calc_city_num.clear()


#県iの市の番号を作成する
for i in range(1,len(order)+1):
    for j in range(len(order[i-1])):
        result = str(str(i).zfill(6) + str(j+1).zfill(6))
        city[int(order[i-1][j][0])-1].setdefault("num",result)

for i in range(M):
    print(city[i]["num"])

Submission status: Wrong Answer

Solution code:
n,m=map(int,input().split())
l = [list(map(int,input().split())) for i in range(m)] 
for i in range(m):
    l[i].append(i)
    
l.sort(key=lambda x: x[1])

ken=""
for i in range(m):
    if ken != l[i][0]:
        x =1
        ken = l[i][0]
    else:
        x += 1
    l[i].append(str(ken).zfill(6)+str(x).zfill(6))

l.sort(key=lambda x: x[2])
#print(l)
for i in range(m):
  print(l[i][3])

Submission status: Wrong Answer

Solution code:
n,m = map(int,input().split())
s = []
for i in range(m):
    a =list(map(int,input().split()))
    a.append(i)
    s.append(a)
s.sort()
print(s)
ans = [0 for i in range(m)]
num = 0
ans_ = ""
for i in range(m):
    if num != s[i][0]:
        num = s[i][0]
        count = 1
    ans_ = str(s[i][0])
    ans__ = str(count)
    for j in range(5):
        if len(ans_) < 6:
            ans_ = "0"+ans_
        if len(ans__) < 6:
            ans__ = "0" + ans__
    ans[s[i][2]] = ans_+ans__
    count += 1
for i in range(m):
    print(ans[i])

Submission status: Wrong Answer

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


def main():
    n, m = map(int, input().split())
    ans_id = [None]*m
    p_count = [0]*(n+1)

    list_ipy = [None]*m
    for i in range(m):
        p, y = map(int, input().split())
        list_ipy[i] = (i, p, y)
    list_ipy.sort(key=lambda x: x[2])

    for ipy in list_ipy:
        i, p, _ = ipy
        p_count[p] += 1
        first = format(p, '06')
        second = format(p_count[p], '08')
        ans_id[i] = first + second

    for id in ans_id:
        print(id)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
n,m = map(int, input().split( ))
p = [[]]*(n+1)
Ip = [0]*(m+1)
Ix = [0]*(m+1)
for i in range(m):
    pi,yi = map(int, input().split( ))
    p[pi].append((yi,i))

for i in range(n+1):
    p[i].sort()

for i in range(n+1):
    for k,(yj,j) in enumerate(p[i]):
        Ip[j] = i
        Ix[j] = k+1

for i in range(m):
    if Ip[i]:
        print(str(Ip[i]).zfill(6)+str(Ix[i]).zfill(6))

Submission status: Wrong Answer

Solution code:
n,m = map(int, input().split( ))
p = [[]]*(n+1)
Ip = [0]*(m+1)
Ix = [0]*(m+1)
for i in range(m):
    pi,yi = map(int, input().split( ))
    p[pi].append((yi,i))

for i in range(n+1):
    p[i].sort()

for i in range(n+1):
    for k,(yj,j) in enumerate(p[i]):
        Ip[j] = i
        Ix[j] = k+1

for i in range(m):
    print(str(Ip[i]).zfill(6)+str(Ix[i]).zfill(6))

Submission status: Wrong Answer

Solution code:
N,M = map(int,input().split())
PY = []
for i in range(M):
    p,y = map(int,input().split())
    PY.append([p,y,i])
PY.sort()


ans = [0 for i in range(M)]
c = 1
d = 0
for i in range(M):
    
    if c == PY[i][0]:
        d += 1
    else:
        c = PY[i][0]
        d = 1
    ans[PY[i][2]] = '0'*(6-len(str(PY[i][0])))  + str(PY[i][0]) + '0'*(6-len(str(PY[i][1]))) + str(d)
for i in ans:
    print(i)

Submission status: Wrong Answer

Solution code:
N,M = map(int,input().split())
PY = []
for i in range(M):
    p,y = map(int,input().split())
    PY.append([p,y,i])
PY.sort()
print(PY)

ans = [0 for i in range(M)]
c = 1
d = 0
for i in range(M):
    
    if c == PY[i][0]:
        d += 1
    else:
        c = PY[i][0]
        d = 1
    ans[PY[i][2]] = '0'*(6-len(str(PY[i][0])))  + str(PY[i][0]) + '0'*(6-len(str(PY[i][1]))) + str(d)
for i in ans:
    print(i)

Submission status: Wrong Answer

Solution code:
N,M = map(int,input().split())
A = [[] for i in range(N+1)]
B = []
d = {}
for i in range(M):
    p,y = map(int,input().split())
    B.append((p,y))
    A[p].append(y)
for i in range(N+1):
    A[i].sort()
    n = len(A[i])
    for j in range(n):
        d[A[i][j]] = j+1
for i in range(M):
    p,y = B[i]
    q = d[y]
    m = 6 - len(str(p))
    n = 6 - len(str(q))
    ans = "0"*m + str(p) + "0"*m + str(q)
    print(ans)

Submission status: Wrong Answer

Solution code:
n, m = map(int, input().split())
py = []
s = '000000'
for i in range(m):
    p, y = map(int, input().split())
    py.append([p, y, i])
py.sort(key=lambda py:(py[0],py[1]))

py[0].append(1)
for i in range(m-1):
    a = 1
    if py[i][0] == py[i+1][0]:
        py[i+1].append(py[i][3]+1)
    else:
        py[i+1].append(1)
        
py.sort(key=lambda py:(py[2]))

for j in range(len(py)):
    print((s+str(py[j][0]))[-5:]+(s+str(py[j][3]))[-5:])

Submission status: Wrong Answer

Solution code:
N, M = (int(i) for i in input().split()) 
PY = [[int(i) for i in input().split()] for i in range(M)] 
d = {}

for p, y in PY:
  if p not in d:
    d[p] = [y]
  else:
    d[p] = (d[p] + [y])

for x in d:
  lis = d[x]
  
for p, y in PY:
  print('{}{}'.format(str(p).zfill(6), str(d[p].index(y) + 1).zfill(6)))

Submission status: Wrong Answer

Solution code:
n, m = map(int, input().split())
queue = []
for i in range(m):
    c, y= map(int, input().split())
    queue.append([c, y, i])

queue = sorted(queue)

index = 0
keep = queue[0][0]
for i in range(m):
    if keep != queue[i][0]:
        index = 0
    index += 1
    queue[i][0] = str(queue[i][0]).zfill(6)
    queue[i][1] = str(index).zfill(6)

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

for data in queue:
    cn, yn, i = data
    print(cn + yn)

Submission status: Wrong Answer

Solution code:
N,M=map(int,input().split())
PY=[list(map(int,input().split())) for _ in range(M)]
PY.sort(key=lambda x:x[1])
flag=[1]*N
ans=[]
for P,Y in PY:
  ans.append(str(P).zfill(6)+str(flag[P-1]).zfill(6))
  flag[P-1]+=1
  
ans.sort
for a in ans:
  print(a)

Submission status: Wrong Answer

Solution code:
n, m = map(int, input().split())
memo = dict()
for i in range(n) :
    memo[i + 1] = []
for i in range(m) :
    pi, yi = map(int, input().split())
    citynum = i + 1
    memo[pi] += [["ans", "x", yi, citynum]]
for i in range(n) :
    memo[i + 1] = sorted(memo[i + 1], key = lambda x : x[2])
for i in range(n) :
    if len(memo[i + 1]) == 0 :
        continue
    else :
        for j in range(len(memo[i + 1])) :
            memo[i + 1][j][1] = j + 1
            ans05 = ("000000" + str(i + 1))[-6:]
            ans611 = ("000000" + str(memo[i + 1][j][1]))[-6:]
            memo[i + 1][j][0] = ans05 + ans611
for i in range(n) :
    if memo[i + 1] == [] :
        del memo[i + 1]
memo = sorted(list(memo.values())[0], key = lambda x : x[3])
for i in memo :
    print(i[0])

Submission status: Wrong Answer

Solution code:
N,M = map(int,input().split())
X=[]
for i in range(M):
  p,y = map(int,input().split())
  X +=[[i,p,y,0]]
X=sorted(X,key=lambda x:x[2])
R=[0]*(N+1)
for i in range(M):
  X[i][3]=R[X[i][1]]+1
  R[X[i][1]] += 1
X=sorted(X,key=lambda x:x[0])
for i in range(M):
  id_A='0'*(6-len(str(X[i][1])))+str(X[i][1])
  id_B='0'*(6-len(str(X[i][1])))+str(X[i][3])
  print(id_A+id_B)

Submission status: Wrong Answer

Solution code:
import bisect
N,M = map(int,input().split())
PtoY = [[] for n in range(N)]
check = []
for m in range(M):
    P,Y = map(int,input().split())
    PtoY[P-1].append(Y)
    check.append([P,Y])
print(check)
for n in range(N):
    PtoY[n].sort()
print(PtoY)
for m in range(M):
    p,y = check[m][0],check[m][1]
    a = bisect.bisect_left(PtoY[p-1],y)+1
    string = str(p).zfill(6) + str(a).zfill(6)
    print(string)

Submission status: Wrong Answer

Solution code:
N,M = map(int,input().split())
array=[]
for i in range(M):
    P,Y = list(map(int,input().split()))
    array.append([P,Y])
array2 = sorted(array)
arraysorted1 = []
j = 1
k = 0
while j != N+1:
    array3=[]
    while k <= M-1:
        if array2[k][0] == j:
            array3.append(array2[k][1])
        k += 1
    array3= sorted(array3)
    arraysorted1.append(array3)
    k = len(arraysorted1[j-1])
    j += 1
for n in range(M):
    for m in range(len(arraysorted1[array[n][0]-1])):
        if array[n] == [array[n][0], arraysorted1[array[n][0]-1][m]]:
            lenf = 6-len(str(array[n][0]))
            lenl = 6-len(str(array[n][1]))
            
            print('0'*lenf +str(array[n][0])+'0'*lenl + str(m+1))

Submission status: Wrong Answer

Solution code:
n,m=map(int,input().split())
li=[]
ans=[]
cnt=0
for i in range(m):
    p,y=map(int,input().split())
    li.append([p,y,i])
li=sorted(li,key=lambda x:x[1])
li=sorted(li,key=lambda x:x[0])
pre=li[0][0]
print(li)
for j in range(m):
    if li[j][0]==pre:
        cnt+=1
        ans.append([str(pre).zfill(6)+str(cnt).zfill(6),li[j][2]])
        
    else:
        pre=li[j][0]
        cnt=1
        ans.append([str(pre).zfill(6)+str(cnt).zfill(6),li[j][2]])

ans=sorted(ans,key=lambda x:x[1])
for k in range(m):
    print(ans[k][0])

Submission status: Wrong Answer

Solution code:
n,m=map(int,input().split())
li=[]
ans=[]
cnt=1
for i in range(m):
    p,y=map(int,input().split())
    li.append([p,y,i])
li=sorted(li,key=lambda x:x[0])
li=sorted(li,key=lambda x:x[1])
pre=li[0][0]
for j in range(m):
    if li[j][0]==pre:
        ans.append([str(pre).zfill(6)+str(cnt).zfill(6),li[j][2]])
        cnt+=1
        
    else:
        pre=li[j][0]
        cnt=1
        ans.append([str(pre).zfill(6)+str(cnt).zfill(6),li[j][2]])

ans=sorted(ans,key=lambda x:x[1])
for k in range(m):
    print(ans[k][0])

Submission status: Wrong Answer

Solution code:
n,m=map(int,input().split())
li=[]
ans=[]
pre=1
cnt=1
for i in range(m):
    p,y=map(int,input().split())
    li.append([p,y,i])
li=sorted(li,key=lambda x:x[0])
li=sorted(li,key=lambda x:x[1])
for j in range(m):
    if li[j][0]==pre:
        ans.append([str(pre).zfill(6)+str(cnt).zfill(6),li[j][2]])
        cnt+=1
        
    else:
        pre+=1
        cnt=1
        ans.append([str(pre).zfill(6)+str(cnt).zfill(6),li[j][2]])

ans=sorted(ans,key=lambda x:x[1])
for k in range(m):
    print(ans[k][0])

Submission status: Wrong Answer

Solution code:
from copy import deepcopy as dp
from operator import itemgetter as ig
n,m = map(int,input().split())
#[input番号,県番号,年,県における順番]
list1 = []
for i in range(m):
    list1.append([i] + list(map(int,input().split())))

list2 = dp(list1)
list2.sort(key=ig(1,2))
city_number = 0
list2[0].append(city_number)
city_number += 1
for i in range(1,m):
    if list2[i][1] == list2[i-1][1]:
        list2[i].append(city_number)
        city_number += 1
    else:
        city_number = 0
        list2[i].append(city_number)
list2.sort(key=ig(0))
for i in range(m):
    print("{0:06d}".format(list2[i][1])+"{0:06d}".format(list2[i][3]+1))

Submission status: Wrong Answer

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

DEBUG = False

dbgp = print if DEBUG else lambda *x:x

data = dict([i, []] for i in range(1, N + 1))
[data[p].append(y) for p, y in PY]
dbgp('data : ', data)

rank = dict()
for k in data.keys():
    if len(data[k]):
        rank[k] = sorted(list(range(1, len(data[k]) + 1)), key=lambda x:data[k][x - 1])

dbgp('rank : ', rank)

counter = dict([i, 0] for i in rank.keys())
dbgp('counter : ', counter)

for p, y in PY:
    print('{0:06}{1:06}'.format(p, rank[p][counter[p]]))
    counter[p] += 1

Submission status: Wrong Answer

Solution code:
import numpy as np

n, m = map(int, input().split())
city = []

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

city = np.array(city)

# print(city)

# 県でソート
city = city[np.argsort(city[:, 0])]

# print(city)

# 県1の中で市の誕生順でソート
pref1 = city[city[:, 0] == 1]
pref1 = pref1[np.argsort(pref1[:, 1])]
pref1[:, 3] = range(len(pref1))
# print(pref1)

# 県2の中で市の誕生順でソート
pref2 = city[city[:, 0] == 2]
pref2 = pref2[np.argsort(pref2[:, 1])]
pref2[:, 3] = range(len(pref2))
# print(pref2)

pref = np.concatenate([pref1, pref2])
pref = pref[np.argsort(pref[:, 2])]

# print(pref)

for i in range(len(pref)):
    print("{0:06d}{1:06d}".format(pref[i, 0], pref[i, 3] + 1), sep="")

Submission status: Wrong Answer

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

p_y = []
for _ in range(m):
    p_y.append(list(map(int, input().split())))

sorted_p_y = sorted(p_y, key=lambda x: (x[0], x[1]))

for row in p_y:
    count = 0
    for sorted_row in sorted_p_y:
        if row[0] == sorted_row[0] and row[1] == sorted_row[1]:
            print(str(row[0]).zfill(6), str(count).zfill(6), sep="")
            count += 1
            continue
        
        if row[0] == sorted_row[0]:
            count += 1

Submission status: Wrong Answer

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

p_y = []
for _ in range(m):
    p_y.append(list(map(int, input().split())))

print("n : {}, m : {}".format(n, m))
print(p_y)

p_y_tmp = sorted(p_y, key=lambda x: x[0])
sorted_p_y = sorted(p_y_tmp, key=lambda x: x[1])
print(sorted_p_y)

for row in p_y:
    count = 0
    for sorted_row in sorted_p_y:
        if row[0] == sorted_row[0]:
            count += 1

        if row[0] == sorted_row[0] and row[1] == sorted_row[1]:
            print(str(row[0]).zfill(6), str(count).zfill(6), sep="")

Submission status: Wrong Answer

Solution code:
 #!/usr/bin/env python3

from collections import namedtuple
from operator import attrgetter

City = namedtuple("City", "ID, pref, year")

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

Cities = []
for ID in range(M):
    pref, year = map(int, input().split())
    Cities.append(City(ID, pref, year))

def get_sID(Cities):
    temp = Cities.copy()

    temp.sort(key=attrgetter("year"))
    temp.sort(key=attrgetter("pref"))

    lid = 1
    currentPref = None
    for City in temp:
        if currentPref is None:
            currentPref = City.pref

        if currentPref != City.pref:
            curerntPref = City.pref
            lid = 1

        yield City.ID, "{0:0>6}{1:0>6}".format(City.pref, lid)
        lid += 1

for _, sID in sorted(get_sID(Cities)):
    print(sID)

Submission status: Wrong Answer

Solution code:
n,m=map(int,input().split())
d=[]
for i in range(m):
  d.append(list(map(int,input().split())))
  d[i].append(1)
s=sorted(d)
k=1
if m>1:
  for i in range(m-1):
    if s[i][0]==s[i+1][0]:
      s[i][2]=k
      s[i+1][2]=k+1
      k=k+1
    else:
      k=1
      s[i+1][2]=k
      
  for i in range(m):
    ans=1000000000000+d[i][0]*1000000+d[i][2]
    print(str(ans)[1:])

else:
  print("000001000001")

Submission status: Wrong Answer

Solution code:
n,m=map(int,input().split())
d=[]
for i in range(m):
  d.append(list(map(int,input().split())))
  d[i].append(0)
s=sorted(d)
k=1
if m>1:
  for i in range(m-1):
    if s[i][0]==s[i+1][0]:
      s[i][2]=k
      s[i+1][2]=k+1
      k=k+1
    else:
      k=1
      s[i+1][2]=k
      s[i][2]=k
      
  for i in range(m):
    ans=1000000000000+d[i][0]*1000000+d[i][2]
    print(str(ans)[1:])

else:
  print("000001000001")

Submission status: Wrong Answer

Solution code:
n,m=map(int,input().split())
d=[]
for i in range(m):
  d.append(list(map(int,input().split())))
  d[i].append(1)
s=sorted(d)
k=0
if m>1:
  for i in range(m-1):
    if s[i][0]==s[i+1][0]:
      s[i][2]=k
      s[i+1][2]=k+1
      k=k+1
    else:
      k=1
      s[i+1][2]=k
      
  for i in range(m):
    ans=1000000000000+d[i][0]*1000000+d[i][2]
    print(str(ans)[1:])
else:
  print("000001000001")

Submission status: Wrong Answer

Solution code:
n,m=map(int,input().split())
d=[]
for i in range(m):
  d.append(list(map(int,input().split())))
  d[i].append(0)
s=sorted(d)
k=1
if m>1:
  for i in range(m-1):
    if s[i][0]==s[i+1][0]:
      s[i][2]=k
      s[i+1][2]=k+1
      k=k+1
    else:
      k=1
      s[i+1][2]=k
      
  for i in range(m):
    ans=1000000000000+d[i][0]*1000000+d[i][2]
    print(str(ans)[1:])

else:
  print("000001000001")

Submission status: Wrong Answer

Solution code:
n,m=map(int,input().split())
d=[]
for i in range(m):
  d.append(list(map(int,input().split())))
  d[i].append(0)
s=sorted(d)
k=1
for i in range(m-1):
  if s[i][0]==s[i+1][0]:
    s[i][2]=k
    s[i+1][2]=k+1
    k=k+1
  else:
    k=1
    s[i+1][2]=k
    
for i in range(m):
  ans=1000000000000+d[i][0]*1000000+d[i][2]
  print(str(ans)[1:])