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())
py = [list(map(int, input().split())) for _ in range(m)]
py.sort()

ans = []
b = py[0][0]
cnt = 0
for p,y in py:
  if b == p: cnt += 1
  else:
    b = p
    cnt = 1
  a = [str(p), str(cnt)]
  if len(str(p)) < 6: a[0] = "0"*(6-len(str(p))) + str(p)
  if len(str(cnt)) < 6: a[1] = "0"*(6-len(str(cnt))) + str(cnt)
  ans.append(a[0] + a[1])
for v in ans: print(v)

Submission status: Wrong Answer

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

PY.sort()
print(PY)

pnow = PY[0][0]
c = 1

ans = [-1 for i in range(M)]

for i in range(M):
    if pnow != PY[i][0]:
        c = 1
        pnow = PY[i][0]
    ans[PY[i][2]] = str(PY[i][0]).zfill(6) + str(c).zfill(6)
    c += 1

print('\n'.join(ans))

Submission status: Wrong Answer

Solution code:
import sys

sys.setrecursionlimit(10 ** 7)
f_inf = float('inf')
mod = 10 ** 9 + 7


def resolve():
    n, m = map(int, input().split())
    PY = []
    for i in range(m):
        p, y = map(int, input().split())
        PY.append([i, p, y])
    PY = sorted(PY, key=lambda x: x[2])
    PY = sorted(PY, key=lambda x: x[1])

    res = [] * m
    prev = PY[0][1]
    last = 0
    for i in range(m):
        idx, p, y = PY[i]
        if prev != p:
            last = 1
        else:
            last += 1

        id = str(p).zfill(6) + str(last).zfill(6)
        res.append([idx, id])

    res = sorted(res, key=lambda x: x[0])
    for i in res:
        print(i[1])


if __name__ == '__main__':
    resolve()

Submission status: Wrong Answer

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

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

lst = [list(map(int, input().split())) + [i] for i in range(M)]
print (lst)

lst.sort(key = lambda x: x[1]) #x番目が小さい順に並べる
lst.sort(key = lambda x: x[0])


ans = [0] * M

count = 0
tmp = 0 #１つ前の県の番号
for p, y, i in lst:
    if tmp == p:
        count += 1
    else:
        count = 1
        tmp = p
    tmp_ans = str(p).zfill(6) + str(count).zfill(6)
    ans[i] = tmp_ans

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

Submission status: Wrong Answer

Solution code:
from collections import Counter,defaultdict,deque
from heapq import heappop,heappush,heapify
import sys,bisect,math,itertools,fractions
sys.setrecursionlimit(10**8)
mod = 10**9+7
INF = float('inf')
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))

n,m = inpl()
d = dict()
z = []
res = [None] * m
for i in range(m):
    a,b = inpl()
    d[(a,b)] = i
    z.append([a,b])
z.sort(key=lambda x:x[1])
z.sort(key=lambda x:x[0])
cnt = 1
now = z[0][0]
for i,t in enumerate(z):
    ind = d[(t[0],t[1])]
    if now == t[0]:
        res[ind] = [now,cnt]
        cnt += 1
    else:
        cnt = 1
        now = t[0]
        res[ind] = [now,cnt]

for a,b in res:
    print(str(a).zfill(6) + str(b).zfill(6))

Submission status: Wrong Answer

Solution code:
N, M = map(int, input().split())
from bisect import bisect_right
dic = [[] for i in range(N)]

shi = {}
for i in range(M):
    p, y = map(int, input().split())
    dic[p-1].append(y)
    shi[i] = (p, y)

for j in range(M):
    p, y = shi[j]
    print('{:06}{:06}'.format(p, bisect_right(dic[p-1], y)))

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
#%% for atcoder uniittest use
import sys
input= lambda: sys.stdin.readline().rstrip()
def pin(type=int):return map(type,input().split())
def tupin(t=int):return tuple(pin(t))
def lispin(t=int):return list(pin(t))
#%%code
def resolve():
    N,M=pin()#NofKen,MofSi
    PY=[[]for i in range(N)]
    
    for m in range(M):
        p,y=pin()
        PY[p-1].append([y,m])
    #print(PY)
    ANS=[]
    for i in range(N):
        PY[i].sort(key=lambda x:x[0])
        for n,py in enumerate(PY[i]):
            py[0]=n+1
            ANS.append([i+1]+py)
    #print(ANS)
    ANS.sort(key=lambda x:x[2])
    
    
    #print(ANS)
    PY=ANS
    for k in range(M):
        x,y,z=PY[k]
        X,Y=str(x),str(y)
        t,s=6-len(X),6-len(Y)
        if t>0:
            X="0"*t+X
        if s>0:
            Y="0"*t+Y
        print(X+Y)

#%%submit!
resolve()

Submission status: Wrong Answer

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

pref_city=[[] for i in range(N)]

for r in PY:
    pref_city[r[0]-1].append(r[1])
pref_city_sorted=[]
for cities in pref_city:
    pref_city_sorted.append(sorted(cities))

for r in PY:
    order=pref_city_sorted[r[0]-1].index(r[1])+1
    print('{a:05}{b:05}'.format(a=r[0],b=order))

Submission status: Wrong Answer

Solution code:
n , m = map(int,input().split())
q = []
for i in range(m):
    p , y = map(int,input().split())
    q.append([p,y,i])
ans = [0 for i in range(m)]
q.sort()

now = q[0][0]
cou = 1
for a , b , c in q:
    if now != a:
        now = a
        cou = 1
        ans[c] = str(a).rjust(6,'0') + str(cou).rjust(6,'0')
    elif now == a:
        ans[c] = str(a).rjust(6,'0') + str(cou).rjust(6,'0')
        cou += 1
        
for i in ans:
    print(i)

Submission status: Wrong Answer

Solution code:
import numpy as np
n, m = map(int, input().split())

p = np.empty(m, dtype=int)
y = np.empty(m, dtype=int)
for i in range(m):
    p[i], y[i] = map(int, input().split())
max_y = max(y)
index = np.unique(p)
code = []
for i in index:  # i = 1
    y2 = y[p == i]
    for j in range(len(y2)):
        suf = np.argmin(y2)
        y2[suf] = max_y + 1
        #print(f"suf = {suf}  y2 = {y2}")
        code.append("{0:06d}{1:06d}".format(i, suf+1))
print(*sorted(code), sep="\n")

Submission status: Wrong Answer

Solution code:
import bisect
import sys


sys.setrecursionlimit(10 ** 6)
INF = float("inf")
MOD = 10 ** 9 + 7


def input():
    return sys.stdin.readline().strip()


def main():
    N, M = map(int, input().split())
    d = [[] for _ in range(N + 1)]
    PY = []
    for _ in range(M):
        p, y = map(int, input().split())
        d[p].append(y)
        PY.append((p, y))

    for i in range(N):
        if not d[i]:
            continue
        d[i] = sorted(set(d[i]))

    for p, y in PY:
        order = bisect.bisect_left(d[p], y)
        print(str(p).zfill(6) + str(order + 1).zfill(6))


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
n,m = map(int,input().split())
py = []
for i in range(m):
    num = i+1
    p,y = map(int,input().split())
    py.append([num,p,y])
py = sorted(py, key = lambda x:x[1]**10+x[2])
x = 0
cnt = 0
b = '000000'
ans = []
for pyi in py:
    if pyi[1] != x:
        x = pyi[1]
        cnt = 1
    else:
        cnt += 1
    ans.append([pyi[0], (b+str(pyi[1]))[-6:], (b+str(cnt))[-6:]])
ans = sorted(ans, key = lambda x: x[0])
for ansi in ans:
    print(ansi[1]+ansi[2])

Submission status: Wrong Answer

Solution code:
n,m = map(int,input().split())
py = []
for i in range(m):
    num = i+1
    p,y = map(int,input().split())
    py.append([num,p,y])
py = sorted(py, key = lambda x:x[1]**10+x[2])
x = 0
b = '000000'
ans = []
for pyi in py:
    if pyi[1] != x:
        x = pyi[1]
        cnt = 1
    else:
        cnt += 1
    ans.append([pyi[0], (b+str(pyi[1]))[-6:], (b+str(cnt))[-6:]])
ans = sorted(ans, key = lambda x: x[0])
for ansi in ans:
    print(ansi[1]+ansi[2])

Submission status: Wrong Answer

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

tmpsort = [[0]]*n
p_list = []
y_list = []

for i in range(m):
    p,y = map(int,input().split())
    tmpsort[p-1].append(y)
    p_list.append(p)
    y_list.append(y)

for i in range(n):
    tmpsort[i].sort()
for i in range(len(p_list)):
    idx = tmpsort[p_list[i]-1].index(y_list[i])
    print((str(p_list[i]).zfill(6) + str(idx).zfill(6)))

Submission status: Wrong Answer

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

tmp_list = [[0]for i in range(n)]
p_list = []
y_list = []

for i in range(m):
    p,y = map(int,input().split())
    tmp_list[p-1].append(y)
    p_list.append(p)
    y_list.append(y)

import copy
tmpsort = copy.deepcopy(tmp_list)
for i in range(len(tmp_list)):
    sorted(tmpsort[i])
for i in range(len(p_list)):
    idx = tmpsort[p_list[i]-1].index(y_list[i])
    print((str(p_list[i]).zfill(6) + str(idx).zfill(6)))

Submission status: Wrong Answer

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

m = {}
ans = []
for i in range(1, N + 1):
	m[i] = []
for i in range(M):
	p, y = map(int, input().split(" "))
	ans.append((p,y))
	m[p] = m[p] + [y]

l = {}
for k,v in m.items():
	for i, v in enumerate(sorted(v)):
		l[k, v]  = "{:0>6}{:0>6}".format(k, i)

for k in ans:
	print(l[k])

Submission status: Wrong Answer

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

m = {}
ans = []
for i in range(1, N + 1):
	m[i] = []
for i in range(M):
	p, y = map(int, input().split(" "))
	ans.append((p,y))
	m[p] = m[p] + [y]

l = {}
for k,v in m.items():
	for item in sorted(v):
		l[k, item]  = "{:0>6}{:0>6}".format(k, item)

for k in ans:
	print(l[k])

Submission status: Wrong Answer

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

year_map = {}
for i in range(M):
    [p, y] = [int(x) for x in  input().rstrip().split()]
    Ps.append(p)
    Ys.append(y)
    year_map[y] = i

# 1=<N<10^5
# 1=<M<10^5

aa_map = {}
junban_array = [0 for _ in range(M+1)]


for i in range(M):
    if Ps[i] in aa_map.keys():
        aa_map[Ps[i]].append(Ys[i])
    else:
        aa_map[Ps[i]] = [Ys[i]]

for pref in aa_map.keys():
    aa_map[pref].sort()
    for j in range(1,len(aa_map[pref])+1):
        city_num = year_map[aa_map[pref][j-1]]
        junban_array[city_num] = j

for i in range(M):
    pref_num = Ps[i]
    pref_str = ""
    for j in range(6-len(str(pref_num))):
        pref_str+="0"
    pref_str += str(pref_num)

    bangou = junban_array[i]
    bangou_str = ""
    for j in range(6-len(str())):
        bangou_str+="0"
    bangou_str += str(bangou)

    print(pref_str+bangou_str)

Submission status: Wrong Answer

Solution code:
from operator import itemgetter, attrgetter

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

pym = [None] * m
for i in range(m):
    pym[i] = [i] + list(map(int, input().split(' ')))

pyms = sorted(pym, key=itemgetter(1, 2))

x = 1
pyms[0].append(x)

for i in range(1, m):
    if pyms[i - 1][1] != pyms[i][1]:
        x = 1
    else:
        x += 1
    pyms[i].append(x)
    
pym = sorted(pyms, key=itemgetter(0, ))

for i in range(m):
    city_id = str(pym[i][1]).zfill(8) + str(pym[i][3]).zfill(8)
    print(city_id)

Submission status: Wrong Answer

Solution code:
import sys
def input(): return sys.stdin.readline().rstrip()
def main():
    n,m=map(int,input().split())
    A=[]
    for i in range(m):
        p,y=map(int,input().split())
        A.append((p,y,i))
    A.sort()
    cunt=0
    pre=0
    ans=[]
    for a in A:
        s1=str(a[0])
        if pre!=a[0]:
            cunt=1
            pre=a[0]
        s2=str(cunt)
        ans.append((i,s1.zfill(6)+s2.zfill(6)))
        cunt+=1
    ans.sort()
    for s in ans:
        print(s[1])

if __name__=='__main__':
    main()

Submission status: Wrong Answer

Solution code:
import sys
def input(): return sys.stdin.readline().rstrip()
def main():
    n,m=map(int,input().split())
    A=[]
    for i in range(m):
        p,y=map(int,input().split())
        A.append((p,y))
    A.sort()
    cunt=0
    pre=0
    ans=[]
    for a in A:
        s1=str(a[0])
        if pre!=a[0]:
            cunt=1
            pre=a[0]
        s2=str(cunt)
        ans.append(s1.zfill(6)+s2.zfill(6))
        cunt+=1
    ans.sort()
    for s in ans:
        print(s)

if __name__=='__main__':
    main()

Submission status: Wrong Answer

Solution code:
import sys
def input(): return sys.stdin.readline().rstrip()
def main():
    n,m=map(int,input().split())
    A=[]
    for i in range(m):
        p,y=map(int,input().split())
        A.append((p,y))
    A.sort()
    print(A)
    cunt=0
    pre=0
    ans=[]
    for a in A:
        s1=str(a[0])
        if pre!=a[0]:
            cunt=1
            pre=a[0]
        s2=str(cunt)
        ans.append(s1.zfill(6)+s2.zfill(6))
        cunt+=1
    ans.sort()
    for s in ans:
        print(s)

if __name__=='__main__':
    main()

Submission status: Wrong Answer

Solution code:
n,m=map(int,input().split())
py=[list(map(int,(str(_+1)+' '+input()).split())) for _ in range(m)]
py.sort(key=lambda x:str(x[1])+','+str(x[2]))
a=[]
pi=0
x=0
b='00000'
ans=[]
for pyi in py:
  if pyi[1]!=pi:
    x=1
    pi=pyi[1]
  else:
    x+=1
  ans.append([pyi[0],(b+str(pyi[1]))[-6:]+(b+str(x))[-6:]])
ans.sort(key=lambda x:x[0])
for ansi in ans:
  print(ansi[1])

Submission status: Wrong Answer

Solution code:
n,m=map(int,input().split())
py=[list(map(int,(str(_+1)+' '+input()).split())) for _ in range(m)]
py.sort(key=lambda x:str(x[1])+','+str(x[2]))
print(py)
a=[]
pi=0
x=0
b='00000'
ans=[]
for pyi in py:
  if pyi[1]!=pi:
    x=1
    pi=pyi[1]
  else:
    x+=1
  ans.append([pyi[0],(b+str(pyi[1]))[-6:]+(b+str(x))[-6:]])
ans.sort(key=lambda x:x[0])
for ansi in ans:
  print(ansi[1])

Submission status: Wrong Answer

Solution code:
n,m = list(map(int,input().split()))
py = [list(map(int,input().split())) + [i] for i in range(m)]

from operator import itemgetter
py = sorted(py,key=itemgetter(1),reverse = False)
py = sorted(py,key=itemgetter(0),reverse = False)
#print(py)

B = []
pref = 0
city = 0
for i in range(m):
    if py[i][0] != pref:
        pref += 1
        city = 1
        B.append([str(py[i][0]).rjust(6,'0') + str(city).rjust(6,'0') , py[i][2]])
    else:
        city += 1
        B.append([str(py[i][0]).rjust(6,'0') + str(city).rjust(6,'0') , py[i][2]])
B = sorted(B,key=itemgetter(1),reverse = False)

for i in range(m):
    print(B[i][0])

Submission status: Wrong Answer

Solution code:
n,m = list(map(int,input().split()))
py = [list(map(int,input().split())) + [i] for i in range(m)]

from operator import itemgetter
py = sorted(py,key=itemgetter(1),reverse = False)
py = sorted(py,key=itemgetter(0),reverse = False)
#print(py)

B = []
pref = 0
city = 0
for i in range(m):
    if py[i][0] != pref:
        pref += 1
        city = 1
        B.append(['0000' + str(py[i][0]) + '0000' + str(city) , py[i][2]])
    else:
        city += 1
        B.append(['0000' + str(py[i][0]) + '0000' + str(city) , py[i][2]])
B = sorted(B,key=itemgetter(1),reverse = False)

for i in range(m):
    print(B[i][0])

Submission status: Wrong Answer

Solution code:
n , m = map(int, input().split())
id =[]
ch = 1
for i in range(m):
    p , y = input().split()
    p = p.zfill(6)
    id.append([p,y,i])
id.sort(key = lambda x:(x[0],x[1]))
id.append(['X','X','X'])
for i in range(m):
    id[i][1]=str(ch).zfill(6)
    if id[i][0]==id[i+1][0]:
        ch+=1
    else:
        ch=1
id.pop()
id.sort(key = lambda x:x[2])
for i in range(m):
    s = id[i][0]+id[i][1]
    print(s)

Submission status: Wrong Answer

Solution code:
n , m = map(int, input().split())
id =[]
ch = 1
for i in range(m):
    p , y = input().split()
    p = p.zfill(6)
    id.append([p,y,i])
id.sort(key = lambda x:x[1])
id.sort(key = lambda x:x[0])
id.append(['X','X','X'])
for i in range(m):
    id[i][1]=str(ch).zfill(6)
    if id[i][0]==id[i+1][0]:
        ch+=1
    else:
        ch=1
id.pop()
id.sort(key = lambda x:x[2])
for i in range(m):
    s = id[i][0]+id[i][1]
    print(s)

Submission status: Wrong Answer

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

for _ in range(M):
    p,y=map(int,input().split())
    P[p-1].append(y)
code=[]
for i in range(N):
    temp=sorted(P[i][1:])
    for j in range(len(temp)):
        code.append(str(i+1).zfill(6)+str(j+1).zfill(6))

code.sort()
for c in code:
    print(c)

Submission status: Wrong Answer

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

foo = {} 
for PYi in PY:
    if foo.get(PYi[0]) is None:
        foo[PYi[0]] = []

    foo[PYi[0]].append(PYi[1])
for i in range(M):
    foo[PYi[0]].sort()
# print(foo)
    
for PYi in PY:
    first_6_digits = str(PYi[0]).zfill(6)
    # x = foo.get(PYi[0]).index(PYi[1]) + 1
    x = 1
    last_6_digits = str(x).zfill(6)
    identification_number = first_6_digits + last_6_digits
    print(identification_number)

Submission status: Wrong Answer

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

foo = {} 
for PYi in PY:
    if foo.get(PYi[0]) is None:
        foo[PYi[0]] = []

    foo[PYi[0]].append(PYi[1])
for i in range(M):
    foo[PYi[0]].sort()
# print(foo)
    
for PYi in PY:
    first_6_digits = str(PYi[0]).zfill(6)
    last_6_digits = str(foo.get(PYi[0]).index(PYi[1]) + 1).zfill(6)
    identification_number = first_6_digits + last_6_digits
    print(identification_number)

Submission status: Wrong Answer

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

foo = {} 
for PYi in PY:
    if foo.get(PYi[0]) is None:
        foo[PYi[0]] = []

    foo[PYi[0]].append(PYi[1])
for i in range(M):
    foo[PYi[0]].sort()
# print(foo)
    
for PYi in PY:
    print(foo.get(PYi[0]).index(PYi[1]))

Submission status: Wrong Answer

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

foo = {} 
for PYi in PY:
    if foo.get(PYi[0]) is None:
        foo[PYi[0]] = []

    foo[PYi[0]].append(PYi[1])
# print(foo)


for PYi in PY:
    print(PYi)

Submission status: Wrong Answer

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

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

ans = [None]*M

for i, d in enumerate(D): 
  d.sort()
  print(d)
  for k, (y, j) in enumerate(d): 
    ans[j] = str(i+1).zfill(6) + str(k+1).zfill(6)
print(*ans, sep = '\n')

Submission status: Wrong Answer

Solution code:
N, M = map(int, input().split())
#for i in range(M):
    #p, y = map(int, input().split())
py = [list(map(int, input().split())) for i in range(M)]
py.sort()
cnt = 1
pre = py[0][0]
ans = '0' * (6 - len(str(py[0][0]))) + str(py[0][0]) + '0' * 5 + '1'
cnt += 1
print(ans)
for i in range(1, M):
    #ans = ''
    if py[i][0] != pre:
        cnt = 1
    pre = py[i][0]
    ans = '0' * (6 - len(str(py[i][0]))) + str(py[i][0])
    ans += '0' * (6 - len(str(cnt))) + str(cnt)
    cnt += 1
    print(ans)

Submission status: Wrong Answer

Solution code:
import itertools
from collections import Counter
N, M = list(map(int,input().split()))
city_list = [list(map(int,input().split())) +[i+1]  for i in range(M)]
city_list_sorted = sorted(city_list,key=lambda x: (x[0],x[1]) )
city_list_grouped = itertools.groupby(city_list_sorted,key=lambda x:x[0])
ans = [None for i in range(M)]
m =0
for k, v in city_list_grouped:
  print(k)
  counter1 = 1
  for x1 in v:
    ans[m] = [x1[2],format(k,'0>6')+format(counter1,'0>6')]
    counter1 += 1 
    m+=1

for x in sorted(ans):
  print(x[1])

Submission status: Wrong Answer

Solution code:
import itertools
from collections import Counter
N, M = list(map(int,input().split()))
city_list = [list(map(int,input().split())) +[i+1]  for i in range(M)]
city_list_sorted = sorted(city_list,key=lambda x: (x[0],x[1]) )
city_list_grouped = itertools.groupby(city_list_sorted,key=lambda x:x[0])
ans = [None for i in range(M)]
m =0
for k, v in city_list_grouped:
  print(k)
  counter1 = 1
  for x1 in v:
    ans[m] = [x1[2],format(k,'0>6')+format(counter1,'0>6')]
    counter1 += 1 
    m+=1

print(ans)
for x in sorted(ans):
  print(x[1])

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-

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

    before = 0
    num = 1
    for p, y in cities:
        if before == p:
            num +=1
        else:
            num = 1
            before = p

        print(str(p).zfill(6) + str(num).zfill(6))



if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
# int(input()) # 入力が1つ
n, m = map(int, input().split()) # 入力が複数
# [int(i) for i in input().split()] # 配列で数字

cities = []
for i in range(m):
    p, y = map(int, input().split())
    cities.append((i, p, y))
cities.sort(key=lambda x: x[2]) # year sort
cities.sort(key=lambda x: x[1]) # p sort

ans = [0] * m
pre = cities[0][1]
num = 1
for i in range(m):
    index, p, y = cities[i]
    if pre == p:
        ans[index] = '0' * (6 - len(str(p))) + str(p) + '0' * (6 - len(str(num))) + str(num)
        num += 1
    else:
        pre = p
        num = 1
        ans[index] = '0' * (6 - len(str(p))) + str(p) + '0' * (6 - len(str(num))) + str(num)

for i in range(m):
    print(ans[i])

Submission status: Wrong Answer

Solution code:
# int(input()) # 入力が1つ
n, m = map(int, input().split()) # 入力が複数
# [int(i) for i in input().split()] # 配列で数字

cities = []
for i in range(m):
    p, y = map(int, input().split())
    cities.append((i, p, y))
cities.sort(key=lambda x: x[2]) # year sort
cities.sort(key=lambda x: x[1]) # p sort

ans = [0] * m
pre = cities[0][1]
num = 1
for i in range(m):
    index, p, y = cities[i]
    if pre == p:
        ans[index] = '0' * (6 - len(str(p))) + str(p) + '0' * (6 - len(str(num))) + str(num)
        num += 1
    else:
        pre = 0
        num = 1
        ans[index] = '0' * (6 - len(str(p))) + str(p) + '0' * (6 - len(str(num))) + str(num)

for i in range(m):
    print(ans[i])

Submission status: Wrong Answer

Solution code:
n,m = map(int,input().split())
pref_ls = [[0] for _ in range(n+1)]
keys_ls = [0] * m
for i in range(m):
    p, y = map(int,input().split())
    pref_ls[p].append(y)
    keys_ls[i] = [p,y]
for i in range(n):
    pref_ls[i].sort()

# 含まれてるならそのインデックス 、含まれてないなら-1を返す
def binary_search(l, item):
    left = 0
    right = len(l) - 1
    while left <= right:
        mid  = (left + right) // 2
        if l[mid] == item:
            return mid
        elif l[mid] < item:
            left = mid + 1
        else:
            right = mid - 1
    return -1
for i in range(m):
    p,y = keys_ls[i]
    rank = binary_search(pref_ls[p], y)
    ans = str(p).zfill(6) + str(rank).zfill(6)
    print(ans)

Submission status: Wrong Answer

Solution code:
n,m=map(int,input().split())
pyi=[[] for i in range(n)]
for i in range(m):
    p,y=map(int,input().split())
    pyi[p-1].append([str(y),i])
ans=[]
for i in range(n):
    pyi[i].sort()
    for j in range(len(pyi[i])):
        ans.append([(6-len(str(i+1)))*"0"+str(i+1)+(6-len(str(j+1)))*"0"+str(j+1),pyi[i][j][1]])
ans.sort(key=lambda x:x[1])
for i in range(m):
    print(ans[i][0])

Submission status: Wrong Answer

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

A = []
for i in range(M):
  A.append([0,1000000000000])

for i in range(M):
  PY[i].extend(A[i])

PY.sort

P = 0


for i in range(M):
  if P != PY[i][0]:
    P = PY[i][0]
    S = 1

  else:
    S += 1

  PY[i][3] += PY[i][0]*1000000+S

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

for i in range(M):
  ans = str(PY[i][3])
  print(ans[1:])

Submission status: Wrong Answer

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

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

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

p = cities[0][0]
cnt = 1
for i in range(M):

    if (cities[i][0] == p):
        cities[i].append(str(p).zfill(6) + str(cnt).zfill(6))
        cnt += 1
    else:
        p = cities[i][0]
        cnt = 1
        cities[i].append(str(p).zfill(6) + str(cnt).zfill(6))
        cnt += 1

sorted(cities, key=lambda x: x[2])

for i in range(M):
    print(cities[i][3])

Submission status: Wrong Answer

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

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

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

p = cities[0][0]
cnt = 1
for i in range(M):

    if (cities[i][0] == p):
        cities[i].append(str(p).zfill(6) + str(cnt).zfill(6))
        cnt += 1
    else:
        p = cities[i][0]
        cnt = 1
        cities[i].append(str(p).zfill(6) + str(cnt).zfill(6))
        cnt += 1

sorted(cities, key=lambda x: x[2])

for i in range(M):
    print(cities[i][3])

Submission status: Wrong Answer

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

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

from bisect import bisect_left, bisect_right, bisect, insort_left, insort_right, insort

def solve(P,Y,pref):
    ans = []
    for p, y in zip(P,Y):
        ind = bisect_left(Y,y)+1
        num = '0'*(6-len(str(p)))+str(p)+'0'*(6-len(str(ind)))+str(ind)
        ans.append(num)
    return ans
print(*solve(P,Y,pref),sep='\n')

Submission status: Wrong Answer

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

class City:
    uid = 0

    def __init__(self, P, Y):
        self.P = P
        self.Y = Y
        self.uid = City.uid
        City.uid = City.uid + 1
        self.year_number = 1

    def print_id(self):
        ID = '0' * (6-len(str(self.P))) + str(self.P)\
        + '0' * (6-len(str(self.year_number))) + str(self.year_number)
        print(ID)

    def print_debug(self):
        print(self.uid, self.P, self.Y, self.year_number)

cities = list()

for i in range(M):
    Pi, Yi = map(int, input().split())
    city = City(Pi, Yi)
    cities.append(city)

for i in range(N):
    tmp_cities = list()
    tmp_years = list()
    for city in cities:
        if i == city.P:
            tmp_cities.append(city)
            tmp_years.append(city.Y)
    tmp_years.sort()
    for j, year in enumerate(tmp_years):
        for city in cities:
            if year == city.Y:
                city.year_number = j+1

for city in cities:
    city.print_id()

Submission status: Wrong Answer

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

class City:
    uid = 0

    def __init__(self, P, Y):
        self.P = P
        self.Y = Y
        self.uid = City.uid
        City.uid = City.uid + 1
        self.year_number = 1

    def print_id(self):
        ID = '0' * (6-len(str(self.P))) + str(self.P)\
        + '0' * (6-len(str(self.year_number))) + str(self.year_number)
        print(ID)

    def print_debug(self):
        print(self.uid, self.P, self.Y, self.year_number)

cities = list()

for i in range(M):
    Pi, Yi = map(int, input().split())
    city = City(Pi, Yi)
    cities.append(city)

for i in range(N):
    tmp_cities = list()
    tmp_years = list()
    for city in cities:
        if i == city.P:
            tmp_cities.append(city)
            tmp_years.append(city.Y)
    tmp_years.sort()
    for j, year in enumerate(tmp_years):
        for city in cities:
            if year == city.Y:
                city.year_number = j+1
                print(j)

for city in cities:
    city.print_id()

Submission status: Wrong Answer

Solution code:
from collections import defaultdict
n, m = map(int, input().split())
l = []
dic = defaultdict(list)
for i in range(m):
    p, y = map(int, input().split())
    dic[p].append(y)
    l.append([p, y])
for key, value in dic.items():
    dic[key] = sorted(value)
for p, y in l:
    print(str(p).zfill(6)+str(dic[p].index(y)+1).zfill(8))

Submission status: Wrong Answer

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

for i in range(m):
  p,y = map(int,input().split())
  array.append((p,y,i))
  
array.sort()


ans = []
last_p = array[0][0]
index = 1
for i in range(m):
  p,y,j = array[i]
  
  if p != last_p:
    index = 1
    
  number = str(p).zfill(6) + str(index).zfill(6)
  ans.append((j,number))
  
  index += 1
  
for t in sorted(ans):
  print(t[1])

Submission status: Wrong Answer

Solution code:
N,M=map(int,input().split())
shi=[[] for i in range(N+1)]
py=[]
for i in range(M):
    p,y=map(int,input().split())
    shi[p].append(y)
    py.append([p,y])
for i in range(N):
    shi[i].sort()
shidic=[{} for i in range(N+1)]
for i in range(N+1):
    for j in range(len(shi[i])):
        shidic[i][shi[i][j]]=j+1
for P,Y in py:
    print(str(P).zfill(6)+str(shidic[P][Y]).zfill(6))

Submission status: Wrong Answer

Solution code:
N,M = map(int,input().split())
City = dict()
for i in range(N):
    City[i+1] = []
for i in range(M):
    Ken,Year = map(int,input().split())
    City[Ken].append(Year)
for i in range(N):
    City[i+1].sort()
for i in range(1,N+1):
    for el in City[i]:
        el = City[i].index(el)
def Zip_code(Ken,rank):
    Ken = str(Ken)
    rank = str(rank)
    Add = (6-len(Ken)) * '0'
    Ken = Add + Ken
    Add = (6-len(rank)) * '0'
    rank = Add + rank
    return Ken+rank
for i in range(1,N+1):
    if City[i] != []:
        for el in City[i]:
            print(Zip_code(i,City[i].index(el)+1))

Submission status: Wrong Answer

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

def kansu(N,M,S):

    S_tmp=[]
    for i in range(M):
        tmp = [int(S[i][0]),int(S[i][1]),0]
        S_tmp.append(tmp) 
    S_tmp.sort()
    tmp = S_tmp[0][0]
    cnt = 1

    for i in range(M):
        if tmp == int(S_tmp[i][0]):
            S_tmp[i][2] = cnt
            cnt += 1
        else :
            tmp = S_tmp[i][0]
            S_tmp[i][2] = 1
            cnt = 2
    print(S_tmp)
    for i in range(M):
        for n in range(M):
        #    print("S[i][1]=",S[i][1],"S_tmp[n][1]=",S_tmp[n][1])
            if int(S[i][1]) == int(S_tmp[n][1]):
                print(str(S[i][0]).zfill(6),str(S_tmp[n][2]).zfill(6),sep='')
                break



    # for m1 in range(M):
    #     cnt = 1
    #     tmp_m1 = S[m1][0]
    #     tmp_m2 = S[m1][1]
    #     for m2 in range(M):
    #         if S[m2][0] == tmp_m1 and S[m2][1] < tmp_m2:
    #             cnt = cnt + 1
    #     print(str(S[m1][0]).zfill(6),str(cnt).zfill(6),sep='')


N,M,S = nyu()
kansu(N,M,S)
#print(S)