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=[int(i) for i in input().split()]
py=sorted([[int(i) for i in input().split()]+[_] for _ in range(m)],key=lambda x:x[0])
py.sort(key=lambda x:x[1])
res=1
py[0][1]=1
for i in range(1,m):
    if py[i][0]==py[i-1][0]:
        res+=1
    else:
        res=1
    py[i][1]=res

py.sort(key=lambda x:x[2])
for i in range(m):
    print(str(py[i][0]).zfill(6)+str(py[i][1]).zfill(6))

Submission status: Wrong Answer

Solution code:
from operator import itemgetter
n,m=map(int,input().split())
L=[]
for i in range(m):
    l=[i]+list(map(int,input().split()))+[0]
    L.append(l)
LS=sorted(L,key=itemgetter(2,3))
LS[0][3]=1
for i in range(m-1):
    if LS[i+1][1]==LS[i][1]:
        LS[i+1][3]=LS[i][3]+1
    else:
        LS[i+1][3]=1
LSS=sorted(LS,key=itemgetter(0))
for i in range(m):
    print(str(LSS[i][1]).zfill(6)+str(LSS[i][3]).zfill(6))

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([i,p,y,0])
cities.sort(key=lambda x: (x[2], x[1]))

pref = cities[0][1]
cnt = 1
for c in cities:
    if c[1] != pref:
        pref = c[1]
        cnt = 1
    c[3] = cnt
    cnt += 1

cities.sort(key=lambda x: x[0])
for c in cities:
    print(str(c[1]).zfill(6)+str(c[3]).zfill(6))

Submission status: Wrong Answer

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

pyl = []
pyl2 = [[] for i in range(n)]    
for _ in range(m):
    p,y = map(int,input().split())
    pyl.append((p,y))
    pyl2[p-1].append(y)
    
argsortpyl = []
for p in pyl2:
    argsortpyl.append(list(np.argsort(np.array(p))))
    
for p,y in pyl:
    x = argsortpyl[p-1].pop(0)
    print(str(p).zfill(6) + str(x+1).zfill(6))

Submission status: Wrong Answer

Solution code:
n,m=[int(i) for i in input().split()]
dic={}
all_list=[]
for i in range(m):
    lst=[int(i) for i in input().split()]
    all_list.append(lst)
    if(lst[0] in dic.keys()):
        dic[lst[0]].append(lst[1])
        dic[lst[0]].sort()
    else:
        dic[lst[0]]=[lst[1]]
print(dic)

for i in all_list:
    s=str(i[0])
    ind=str(dic[i[0]].index(i[1])+1)
    print(s.zfill(6)+ind.zfill(6))

Submission status: Wrong Answer

Solution code:
n,m=map(int,input().split())
A=[[] for i in range(n+1)]
I=[]
for i in range(m):
    p,y=map(int,input().split())
    A[p].append([i,y])

print(A)

for i in range(n+1):
    if A[i] != []:
        for j in range(len(A[i])):
            I.append([A[i][j][0] ,str(i).zfill(6) ,str(j+1).zfill(6)])
I.sort(key=lambda x: x[0])
for i in range(len(I)):print(I[i][1],I[i][2],sep="")

Submission status: Wrong Answer

Solution code:
n,m=map(int,input().split())
A=[[] for i in range(n+1)]
I=[]
for i in range(m):
    p,y=map(int,input().split())
    A[p].append([i,y])
for i in range(n+1):
    if A[i] != []:
        for j in range(len(A[i])):
            I.append([A[i][j] ,str(i).zfill(6) ,str(j+1).zfill(6)])
I.sort(key=lambda x: x[0])
for i in range(len(I)):print(I[i][1],I[i][2],sep="")

Submission status: Wrong Answer

Solution code:
n,m=map(int,input().split())
A=[[] for i in range(n+1)]
I=[]
for i in range(m):
    p,y=map(int,input().split())
    A[p].append(y)
print(A)
for i in range(n+1):
    if A[i] != []:
        for j in range(len(A[i])):
            I.append([str(i).zfill(6) ,str(j+1).zfill(6)])
I.sort(key=lambda x: x[1])
for i in range(len(I)):print("".join(I[i]))

Submission status: Wrong Answer

Solution code:
N , M = map(int,input().split())
birth = []
for i in range(M):
    a , b = map(int,input().split())
    birth.append([a,b,i])
print(birth)
work_list = sorted(birth,key=lambda x: x[1])
work_list.sort()
#print(birth)
upper = 1
lower = 1
ans = []
for i in range(1,len(birth)):
    ans.append([work_list[i-1][2],str(work_list[i-1][0]).zfill(6) + str(lower).zfill(6)])
    if work_list[i][0] == work_list[i-1][0]:
        lower += 1
    else:
        lower = 1
        upper += 1
ans.append([work_list[M - 1][2],str(work_list[M-1][0]).zfill(6) + str(lower).zfill(6)])
ans.sort()
for val in ans:
    print(val[1])

Submission status: Wrong Answer

Solution code:
n,m = map(int,input().split())
Atc = [list(map(int,input().split()))+[i+1] for i in range(m)]
Atc.sort(key=lambda Atc:(Atc[0],Atc[1]))
Ans = [['',0]]*m
cnt = Atc[0][0]
cnty = 1
for i in range(m):
    if cnt == Atc[i][0]:
        Ans[i]=['0'*(6-len(str(Atc[i][0])))+str(Atc[i][0])+'0'*(6-len(str(cnty)))+str(cnty),Atc[i][2]]
        cnty += 1
    else:
        cnty = 1
        Ans[i]=['0'*(6-len(str(Atc[i][0])))+str(Atc[i][0])+'0'*(6-len(str(cnty)))+str(cnty),Atc[i][2]]
        cnt = Atc[i][0]
Ans.sort(key=lambda Ans:(Ans[1]))
for i in Ans:
    print(i[0])

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
n,m= map(int, input().split())
x=[0]*m
for i in range(m):
    p,y= map(int, input().split())
    x[i]=[p,y,i]
x.sort(key=lambda x:x[1])
x.sort()
y=[0]*m
t=1
cnt=1
for i in range(m):
    if x[i][0]==t:
        j=str(x[i][0])
        k=str(cnt)
        y[x[i][2]]="".join(["".join(["0"*(6-len(j)),j]),"".join(["0"*(6-len(k)),k])])
        cnt+=1
    else:
        t+=1
        cnt=1
        j=str(x[i][0])
        k=str(cnt)
        y[x[i][2]]="".join(["".join(["0"*(6-len(j)),j]),"".join(["0"*(6-len(k)),k])])
        cnt+=1
for i in range(m):
    print(y[i])

Submission status: Wrong Answer

Solution code:
n,m= map(int, input().split())
x=[0]*m
for i in range(m):
    p,ye= map(int, input().split())
    x[i]=[p,ye,i]
x.sort(key=lambda x:x[1])
x.sort()
y=[0]*m
t=1
for i in range(m):
    if str(x[i][1])==t:
        j=str(x[i][0])
        k=str(t)
        y[x[i][2]]="".join(["".join(["0"*(6-len(j)),j]),"".join(["0"*(6-len(k)),k])])
    else:
        t+=1
        j=str(x[i][0])
        k=str(t)
        y[x[i][2]]="".join(["".join(["0"*(6-len(j)),j]),"".join(["0"*(6-len(k)),k])])
for i in range(m):
    print(y[i])

Submission status: Wrong Answer

Solution code:
n,m= map(int, input().split())
x=[0]*m
for i in range(m):
    p,y= map(int, input().split())
    x[i]=[p,y,i]
x.sort(key=lambda x:x[1])
x.sort()
y=[0]*m
t=1
cnt=1
for i in range(m):
    if x[i][0]==t:
        j=str(x[i][0])
        k=str(cnt)
        y[x[i][2]]="".join(["".join(["0"*(6-len(j)),j]),"".join(["0"*(6-len(k)),k])])
        cnt+=1
    else:
        t+=1
        cnt=1
        j=str(x[i][0])
        k=str(cnt)
        y[x[i][2]]="".join(["".join(["0"*(6-len(j)),j]),"".join(["0"*(6-len(k)),k])])
        cnt+=1
for i in range(m):
    print(y[i])

Submission status: Wrong Answer

Solution code:
from operator import itemgetter

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

x = [0] * n
pn = [i for i in range(1, m+1)]
idn = [''] * m
yp = list(zip(y, p, pn, idn))
yp.sort()

for i in range(m):
    p_ = p[i] - 1
    x[p_] += 1
    idn[i] = format(p[i], '0>6') + format(x[p_], '0>6')

yp.sort(key=itemgetter(2))
for i in range(m):
    print(idn[i])

Submission status: Wrong Answer

Solution code:
n,m = map(int,input().split())
s = [[] for _ in range(n+1)]
for i in range(m):
    p,y = map(int,input().split())
    s[p].append((y,i))
s[p].sort()
ans = [0]*m
for p in range(1,n+1):
    cnt = 1
    for y in s[p]:
        ans[y[1]] = '{:06}{:06}'.format(p,cnt)
        cnt += 1
for i in range(len(ans)):
    print(ans[i])

Submission status: Wrong Answer

Solution code:
n,m = map(int,input().split())
s = [[] for _ in range(n+1)]
for i in range(m):
    p,y = map(int,input().split())
    s[p].append([y,i])
s[p].sort()
ans = ['']*m
for p in range(1,n+1):
    cnt = 1
    for (y,i) in s[p]:
        ans[i] = '{:06}{:06}'.format(p,cnt)
        cnt += 1
for i in range(len(ans)):
    print(ans[i])

Submission status: Wrong Answer

Solution code:
n,m = map(int,input().split())
s = [[] for _ in range(n+1)]
for i in range(m):
    p,y = map(int,input().split())
    s[p].append([y,i])
s[p].sort()
ans = ['']*m
for p in range(1,n+1):
    cnt = 1
    for (y,i) in s[p]:
        ans[i] = '{:06}{:06}'.format(p,cnt)
        cnt += 1
print(' '.join(ans))

Submission status: Wrong Answer

Solution code:
import sys


def solve():
    sys.setrecursionlimit(2000)
    input = sys.stdin.readline
    mod = 10 ** 9 + 7
    n, m = list(map(int, input().rstrip('\n').split()))
    ls = [1] * n
    py = []
    for i in range(m):
        p, y = list(map(int, input().rstrip('\n').split()))
        py.append([p, y, i, -1])
    py.sort()
    for i in range(m):
        py[i][3] = ls[py[i][0]-1]
        ls[py[i][0] - 1] += 1
    py.sort(key=lambda x: x[2])
    for i in range(m):
        a = ["0"] * 6
        a.append(str(py[i][0]))
        a = a[-6:]
        b = ["0"] * 6
        b.append(str(py[i][3]))
        b = b[-6:]
        print("".join(a + b))


if __name__ == '__main__':
    solve()

Submission status: Wrong Answer

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

count =1
pre = e[0][0]
for i in e:
  if pre != i[0]:
    count = 1
  i.append(format(str(i[0]), '0>6')+format(str(count), '0>6'))
  count += 1
  
e.sort(key = lambda x:x[2])

for i in e:
  print(i[3])

Submission status: Wrong Answer

Solution code:
n, m = map(int, input().split())
PY = [[0]] * (n+1)
IMP = [[]] * m
for i in range(m):
  p, y = map(int, input().split())
  PY[p].append(y)
  IMP[i] = [p, y]
#print(PY)
for i in range(len(PY)):
  PY[i] = sorted(PY[i])
for imp in IMP:
  print("{:0=6}".format(imp[0]), end="")
  pos = PY[imp[0]].index(imp[1])
  print("{:0=6}".format(pos))

Submission status: Wrong Answer

Solution code:
n, m = map(int, input().split())
from bisect import insort
PY = [[0]] * (n+1)
IMP = [[]] * m
for i in range(m):
  p, y = map(int, input().split())
  insort(PY[p], y)
  IMP[i] = [p, y]
#print(PY)
#for key in PY.keys():
#  PY[key] = sorted(PY[key])
for imp in IMP:
  print("{:0=6}".format(imp[0]), end="")
  pos = PY[imp[0]].index(imp[1])
  print("{:0=6}".format(pos))

Submission status: Wrong Answer

Solution code:
n,m = map(int, input().split())
info = [[i] + list(map(int, input().split())) for i in range(1, m+1)]
city = sorted(set([info_i[0] for info_i in info]))
'''
sorted_info = sorted(info, key=lambda x: [x[1], x[2]])
counter = 0

p = city.pop(0)

for i in range(m):
  if sorted_info[i][1] == p:
    counter += 1
    sorted_info[i].append(counter)
  else:
    p =  city.pop(0)
    counter = 1
    sorted_info[i].append(counter)

result = sorted(sorted_info, key=lambda x:x[0])

for res_i in result:
  print(str(res_i[1]).zfill(6) + str(res_i[3]).zfill(6))
'''

Submission status: Wrong Answer

Solution code:
n, m = (int(x) for x in input().split())
l = []
for _ in range(m):
    l.append([int(x) for x in input().split()])
d = {}
for i in range(m):
    k = str(l[i][0])
    if k not in d.keys():
        d[k] = 1
    else:
        d[k] += 1
    print(k.zfill(6) + str(d[k]).zfill(6))

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 + 1)

sortL = sorted(L)

nums = "000000"

ID = ""

order = 1

for i in range(0,len(L)):
  pref = str(sortL[i][0])
  ID = "0" *  (6 - len(pref))
  ID += pref
  ID += "0" * (6 - len(str(order)))
  ID += str(order)
  sortL[i].append(ID)
  order += 1
  if L[i][0] > L[i-1][0]:
    order = 1

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

for i in range(0,len(L)):
  print(sortL[i][-1])

Submission status: Wrong Answer

Solution code:
n,m = map(int, input().split())
info = [[i] + list(map(int, input().split())) for i in range(1, m+1)]
sorted_info = sorted(info, key=lambda x: [x[1], x[2]])

p =  info[0][1]
counter = 0

for i in range(m):
  if sorted_info[i][1] == p:
    counter += 1
    sorted_info[i].append(counter)
  else:
    counter = 1
    sorted_info[i].append(counter)

result = sorted(sorted_info, key=lambda x:x[0])

for res_i in result:
  print(str(res_i[1]).zfill(6) + str(res_i[3]).zfill(6))

Submission status: Wrong Answer

Solution code:
n, m = map(int, input().split())
a = [list(map(int, input().split())) for i in range(m)]
for i in range(m):
    a[i].append(i+1)
a.sort()
def num(x,y):
    return str(1000000+x).lstrip("1")+str(1000000+y).lstrip("1")
for i in range(m):
    if i == 0:
        w = 1
    elif i >= 1 and a[i][0] == a[i-1][0]:
        w += 1
    else:
        w = 1

    a[i].append(num(a[i][0], w))
a.sort(key=lambda x:x[2])
    
for i in range(m):
    print(a[i][3])

Submission status: Wrong Answer

Solution code:
n,m=map(int,input().split())
l=[]
for i in range(m):
  p,y=map(int,input().split())
  l.append([p,y,i])
l.sort()
y=[]
q=l[0][0]
r=0
for i in range(m):
  x=''
  if q==l[i][0]:
    r+=1
  else:
    r=1
  x+='0'*(6-len(str(l[i][0])))+str(l[i][0])
  x+='0'*(6-len(str(r)))+str(r)
  y.append([l[i][2],x])
y.sort()
for i in range(m):
  print(y[i][1])

Submission status: Wrong Answer

Solution code:
N,M=map(int,input().split())
D={}
L=[]

for i in range(M):
    P,Y=map(int,input().split())
    L.append([P,Y])
    if P not in D:
        D[P]=[]
    D[P].append(Y)
    
for v in D.values() :
    v.sort()

for i in L:
    print(int("00000"+str(i[0]*1000000 + D[i[0]].index(i[1])+1)))

Submission status: Wrong Answer

Solution code:
N,M=map(int,input().split())
D={}
L=[]

for i in range(M):
    P,Y=map(int,input().split())
    L.append([P,Y])
    if P not in D:
        D[P]=[]
    D[P].append(Y)
    
for v in D.values() :
    v.sort()

for i in L:
    print("00000"+str(i[0]*1000000 + D[i[0]].index(i[1])+1))

Submission status: Wrong Answer

Solution code:
n,m=map(int,input().split())
l=[]
for i in range(m):
    a,b=map(int,input().split())
    l.append([a,b])
x=sorted(l)
dic={}
x.append([0,0])
f=1
for i in range(m):
    if x[i][0]==x[i+1][0]:
        dic[str(x[i][0])+'000000'+str(x[i][1])]=f
        f+=1
    else:
        dic[str(x[i][0])+'000000'+str(x[i][1])]=f
        f=1
for i in range(m):
    b=dic[str(l[i][0])+'000000'+str(l[i][1])]
    p=len(list(str(l[i])))
    q=len(list(str(b)))
    ans=''
    for j in range(6-p):
        ans+='0'
    ans+=str(l[i])
    for j in range(6-q):
        ans+='0'
    ans+=str(b)
    print(ans)

Submission status: Wrong Answer

Solution code:
n,m=map(int,input().split())
city_list = [[] for _ in range(n)]

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

for ppyy in py:
  city_list[ppyy[0]-1].append(ppyy[1])

for index, ppyy in enumerate(city_list):
  ppyy.sort()
  for index2, pppyyy in enumerate(ppyy):
    print(str(index+1).zfill(6)+str(index2+1).zfill(6))

Submission status: Wrong Answer

Solution code:
N, M = map(int, input().split())
l=[]
l_=[]
for i in range(N):
    l_.append([])
for i in range(M):
    l.append(list(map(int, input().split())))
    print(l[i][1])
    l_[l[i][0] - 1].extend([l[i][1]])
    #print(l_)
for i in range(N):
    l_[i] = sorted(l_[i])
for i in range(M):
    numN = str(l[i][0]).zfill(6)
    numM = str(l_[l[i][0]-1].index(l[i][1]) + 1).zfill(6)
    print(numN + numM)

Submission status: Wrong Answer

Solution code:
import numpy as np
n,m=map(int,input().split())
d=[[]*m for i in range(n)]
l=[]
for i in range(m):
    a,b=map(int,input().split())
    d[a-1].append(b)
    l.append(a)

for i in range(n):
    d[i]=list(np.argsort(d[i]))
    
for i in range(m):
    b=d[l[i]-1].pop(0)
    b+=1
    p=len(list(str(l[i])))
    q=len(list(str(b)))
    ans=''
    for j in range(6-p):
        ans+='0'
    ans+=str(l[i])
    for j in range(6-q):
        ans+='0'
    ans+=str(b)
    print(ans)

Submission status: Wrong Answer

Solution code:
n,m = map(int, input().split())
py = []
for i in range(m):
  a,b = map(int, input().split())
  py.append([a,b,i])
py.sort()
p = py[0][0]
y = 1
for i in range(m):
  if py[i][0] == p:
    py[i][1] = y
    y += 1
  else:
    py[i][1] = 1
    y = 1
    p = py[i][0]
py = sorted(py, key=lambda x:x[2])
for p,y,i in py:
  print("{:0=6}{:0=6}".format(p,y))

Submission status: Wrong Answer

Solution code:
n,m = map(int, input().split())
py = []
for i in range(m):
  a,b = map(int, input().split())
  py.append([a,b,i])
py.sort()
print(py)
p = py[0][0]
y = 1
for i in range(m):
  if py[i][0] == p:
    py[i][1] = y
    y += 1
  else:
    py[i][1] = 1
    y = 1
    p = py[i][0]
py = sorted(py, key=lambda x:x[2])
for p,y,i in py:
  print("{:0=6}{:0=6}".format(p,y))

Submission status: Wrong Answer

Solution code:
n,m = map(int, input().split())
py = []
for i in range(m):
  a,b = map(int, input().split())
  py.append([a,b,i])
py.sort()
p = 1
y = 1
for i in range(m):
  if py[i][0] == p:
    py[i][1] = y
    y += 1
  else:
    py[i][1] = 1
    y = 1
    p = py[i][0]
py = sorted(py, key=lambda x:x[2])
for p,y,i in py:
  print("{:0=6}{:0=6}".format(p,y))

Submission status: Wrong Answer

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

ans = [[0,0,0] for i in range(m)]

pre = data[0][1]
num = 1
for i in range(m):
    if pre != data[i][1]:
        num = 1
        ans[i][0] = data[i][1]
        ans[i][1] = num
    else:
        ans[i][0] = data[i][1]
        ans[i][1] = num
        num += 1
    pre = data[i][1]
    ans[i][2] = data[i][0]
ans = sorted(ans, key = lambda x:x[2])
for i in range(m):
    print("{:0=6}{:0=6}".format(ans[i][0],ans[i][1]))

Submission status: Wrong Answer

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

ans = [[0,0,0] for i in range(m)]

pre = data[0][1]
num = 1
for i in range(m):
    if pre != data[i][1]:
        num = 1
        ans[i][0] = data[i][1]
        ans[i][1] = num
    else:
        ans[i][0] = data[i][1]
        ans[i][1] = num
        num += 1
    pre = data[i][1]
    ans[i][2] = data[i][0]
ans = sorted(ans, key = lambda x:x[2])
for i in range(m):
    print(ans[i][0], ans[i][1])
    print("{:0=6}{:0=6}".format(ans[i][0],ans[i][1]))

Submission status: Wrong Answer

Solution code:
from operator import itemgetter

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

for idx in range(M):
    p, y = map(int, input().split())
    P.append(p)
    Y.append(y)
    IDX.append(idx)
    
PYIDX = zip(P,Y,IDX)
PYIDX = sorted(PYIDX, key=itemgetter(1))
PYIDX = [list(x) for x in PYIDX]

for i in range(M):
    if i == 0 or PYIDX[i-1][0] != PYIDX[i][0]:
        city_number = 1
    else:
        city_number += 1
    PYIDX[i].append(str(PYIDX[i][0]).zfill(6) + str(city_number).zfill(6))

PYIDX = sorted(PYIDX, key=itemgetter(2))

for idx in range(M):
    print(PYIDX[idx][3])

Submission status: Wrong Answer

Solution code:
def slove():
    import sys
    input = sys.stdin.readline
    n, m = list(map(int, input().rstrip('\n').split()))
    py = []
    ls = [1] * (n + 1)
    for i in range(m):
        p, y = list(map(int, input().rstrip('\n').split()))
        py.append([p, y, 0, i])
    py.sort()
    for i in range(m):
        py[i][2] = ls[py[i][0]]
        ls[py[i][0]] += 1
    py.sort(key=lambda x: x[3])
    for i in range(len(py)):
        a = ["0"] * 6
        a.append(str(py[i][0]))
        a = a[-6:]
        b = ["0"] * 6
        b.append(str(py[i][2]))
        b = b[-6:]
        print("".join(a + b))


if __name__ == '__main__':
    slove()

Submission status: Wrong Answer

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


length = [list(map(int,input().split())) for _ in range(M)]
for i in range(M):
  length[i].insert(2,i)
length = sorted(length)
print(length)
ans_list =[0]*M
count = 1
for i in range(M):
  if i == 0:
    ans = str(length[i][0]).zfill(6) + str(count).zfill(6)
    ans_list[i] = [length[i][2],ans]
  elif i >= 1 and length[i][0] == length[i-1][0]:
    count += 1
    ans = str(length[i][0]).zfill(6) + str(count).zfill(6)
    ans_list[i] = [length[i][2],ans]
  elif i >= 1 and length[i][0] != length[i-1][0]:
    count = 1
    ans = str(length[i][0]).zfill(6) + str(count).zfill(6)
    ans_list[i] = [length[i][2],ans]
ans_list.sort(key=lambda x: x[0])
for i in range(M):
  print(ans_list[i][1])

Submission status: Wrong Answer

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


length = [input().split() for _ in range(M)]
for i in range(M):
  length[i].insert(0,i)
length.sort(key=lambda x: x[1])
length.sort(key=lambda x: x[2])

ans_list =[0]*M
count = 1
for i in range(M):
  if i == 0:
    ans = length[i][1].zfill(6) + "1".zfill(6)
    ans_list[i] = [length[i][0],ans]
  elif i >= 1 and length[i][1] == length[i-1][1]:
    count += 1
    ans = length[i][1].zfill(6) + str(count).zfill(6)
    ans_list[i] = [length[i][0],ans]
  elif i >= 1 and length[i][1] != length[i-1][1]:
    count = 1
    ans = length[i][1].zfill(6) + str(count).zfill(6)
    ans_list[i] = [length[i][0],ans]
ans_list.sort(key=lambda x: x[0])
for i in range(M):
  print(ans_list[i][1])

Submission status: Wrong Answer

Solution code:
import heapq

N,M = map(int, input().split())
entry = []
N_list = [[] for _ in range(N)]
for m in range(M):
  p, y = map(int, input().split())
  entry.append((p-1,y))
  heapq.heappush(N_list[p-1], y)
  #N_list[p-1].append(y)

#N_list_sorted = [n.sort() for n in N_list]

for e in entry:
  p, y = e[0], e[1]
  idx = str(N_list[p].index(y)+1).zfill(6)
  print(str(p+1).zfill(6)+idx)

Submission status: Wrong Answer

Solution code:
N,M=map(int,input().split())
data=[list(map(int,input().split()+[i])) for i in range(M)]
data=sorted(data,key=lambda x:x[1])
data=sorted(data,key=lambda x:x[0])
preP=None
count=None
printdata=[]
for i in data:
    if preP==i[0]:
        count+=1
    else:
        preP=i[0]
        count=1
    printdata.append(["0"*(6-len(str(preP)))+str(preP)+"0"*(6-len(str(count)))+str(count),i[2]])
printdata=sorted(printdata,key=lambda x:x[1])
for i in printdata:
    print(i)

Submission status: Wrong Answer

Solution code:
N,M=map(int,input().split())
data=[list(map(int,input().split())) for i in range(M)]
data=sorted(data, key=lambda x: x[1])
prepri=-1
count=0
printdata=[]
for i in data:
    if prepri!=i[0]:
        prepri=i[0]
        count=1
    else:
        count+=1
    printdata.append("0"*(6 - len(str(prepri))) + str(prepri) + "0"*(6 - len(str(count))) + str(count) )
for i in printdata:
    print(i)

Submission status: Wrong Answer

Solution code:
N,M=map(int,input().split())
data=[list(map(int,input().split())) for i in range(M)]
data=sorted(data, key=lambda x: x[1])
prepri=-1
count=0
printdata=[]
for i in data:
    if prepri!=i[0]:
        prepri=i[0]
        count=1
    else:
        count+=1
    printdata.append("0"*(6 - len(str(prepri))) + str(prepri) + "0"*(6 - len(str(count))) + str(count) )
printdata=sorted(printdata,reverse=True)
printdata=sorted(printdata, key=lambda x: x[6:],reverse=True)
for i in printdata:
    print(i)

Submission status: Wrong Answer

Solution code:
N,M=map(int,input().split())
data=[list(map(int,input().split())) for i in range(M)]
data=sorted(data, key=lambda x: x[1])
prepri=-1
count=0
printdata=[]
for i in data:
    if prepri!=i[0]:
        prepri=i[0]
        count=1
    else:
        count+=1
    printdata.append("0"*(6 - len(str(prepri))) + str(prepri) + "0"*(6 - len(str(count))) + str(count) )
printdata.reverse()
for i in printdata:
    print(i)

Submission status: Wrong Answer

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


def main():
    n, m = map(int, input().split())
    lst = [[] for _ in range(n + 1)]
    py = []
    for i in range(m):
        p, y = map(int, input().split())
        py.append([p, y])
        lst[p].append(y)

    for i in lst:
        i.sort
    ans = []
    for i, j in py:
        ans.append(str(i).zfill(6) + str(lst[i].index(j)+1).zfill(6))
    print(*ans, sep=('\n'))


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
n,m=map(int,input().split())
A=[tuple(map(int,input().split())) for i in range(m)]
A.sort()
M={}
for x,y in A:
    if x not in M:
        M[x]=[1]
    else:
        M[x] +=[M[x][-1]+1]

ans=[]
for v,m in M.items():
    v=str(v)
    for i in m:
        i=str(i)
        ans.append([int(i),v.zfill(6)+i.zfill(6)])

ans=sorted(ans)
for i in ans[::-1]:
    print(i[1])

Submission status: Wrong Answer

Solution code:
N,M=map(int,input().split())
PY=[]
for i in range(M):
    PY.append(list(map(int,input().split())))
    PY[i].append(i)
PY=sorted(PY,key=lambda x: x[1])

X=[1]
for i in range(1,M):
    if PY[i][0] == PY[i-1][0]:
        X.append(X[-1]+1)
    else:
        X.append(1)

for i in range(M):
    PY[i].append(str(PY[i][0]).rjust(6,'0')+\
              str(X[i]).rjust(6,'0'))

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

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

Submission status: Wrong Answer

Solution code:
def fix(s):
  ss = str(s)
  while len(ss) < 6:
    ss = "0" + ss
  return ss

N, M = map(int, input().split())
PY = [(0,0,0)] * M
Num = [(0,0,0)] * M

for i in range (M):
    P, Y = map(int, input().split())
    PY[i] = (P, Y, i)
PY.sort()
print(PY)
for i in range (M):
  if PY[i-1][0] == PY[i][0]:
    Num[i] = (PY[i][2], PY[i][0], Num[i-1][2]+1)
  else:
    Num[i] = (PY[i][2], PY[i][0], 1)

Num.sort()
for i in range(M):
  print(fix(Num[i][1]) + fix(Num[i][2]))

Submission status: Wrong Answer

Solution code:
n,m=map(int,input().split())
city=[]
table=[]
for i in range(m):
    city.append(list(map(int,input().split())))
#    word=''.join(str(city[i]))
#    table.append(word)
city.sort()
temp=city[0][0]
count=1
for i in range(m):
    if temp!=city[i][0]:
        temp=city[i][0]
        count=1
    top=str(0)*(6-len(str(city[i][0])))+str(city[i][0])
    bottom=str(0)*(6-len(str(count)))+str(count)
    print(top+bottom)
    count+=1

Submission status: Wrong Answer

Solution code:
def fix(s):
  ss = str(s)
  while len(ss) < 6:
    ss = "0" + ss
  return ss

N, M = map(int, input().split())
PY = [(0,0,0)] * M
Num = [(0,0,0)] * M

for i in range (M):
    P, Y = input().split()
    PY[i] = (P, Y, i)
PY.sort()

for i in range (M):
  if PY[i-1][0] == PY[i][0]:
    Num[i] = (PY[i][2], PY[i][0], Num[i-1][2]+1)
  else:
    Num[i] = (PY[i][2], PY[i][0], 1)

Num.sort()
for i in range(M):
  print(fix(Num[i][1]) + fix(Num[i][2]))

Submission status: Wrong Answer

Solution code:
import sys
import os
from operator import itemgetter

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

for i in range(M):
    p,y = map(int,input().split())
    cities[i] = [p,y,i]
cities = sorted(cities,key=itemgetter(1))
cities = sorted(cities,key=itemgetter(0))

out = ["*" for _ in range(M)]
beforeCity = cities[0][0]
cityCnt = 1
for i in range(M):
    curCity = cities[i][0]
    if beforeCity != curCity:   cityCnt = 1
    cityNo1 = str(curCity).zfill(6)
    cityNo2 = str(cityCnt).zfill(6)
    out[cities[i][2]] = cityNo1+cityNo2
    cityCnt += 1

for a in out:
    print(a)

Submission status: Wrong Answer

Solution code:
from operator import itemgetter

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

for i in range(M):
    p,y = map(int,input().split())
    cities[i] = [p,y,i]
cities = sorted(cities,key=itemgetter(1))
cities = sorted(cities,key=itemgetter(0))

out = ["*" for _ in range(M)]
beforeCity = cities[0][0]
cityCnt = 1
for i in range(M):
    curCity = cities[i][0]
    if beforeCity != curCity:
        cityCnt = 1
    if len(str(curCity)) < 6:
        cityNo1 = "0"*(6 - len(str(curCity)))+str(curCity)
    else:
        cityNo1 = str(curCity)
    if len(str(cityCnt)) < 6:
        cityNo2 = "0"*(6 - len(str(cityCnt)))+str(cityCnt)
    else:
        cityNo2 = str(cityCnt)
    out[cities[i][2]] = cityNo1+cityNo2
    cityCnt += 1

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

Submission status: Wrong Answer

Solution code:
from operator import itemgetter
N,M = map(int,input().split())
cities = [ 0 for _ in range(M) ]

for i in range(M):
    p,y = map(int,input().split())
    cities[i] = [p,y,i]
cities = sorted(cities,key=itemgetter(1))
cities = sorted(cities,key=itemgetter(0))

out = ["*" for _ in range(M)]

beforeCity = cities[0][0]
cityCnt = 1
for i in range(M):
    if beforeCity != cities[i][0]:
        cityCnt = 1
    if len(str(cities[i][0])) < 6:
        cityNo1 = "0"*(6 - len(str(cities[i][0])))+str(cities[i][0])
    else:
        cityNo1 = str(cities[i][0])
    if len(str(cityCnt)) < 6:
        cityNo2 = "0"*(6 - len(str(cityCnt)))+str(cityCnt)
    else:
        cityNo2 = str(cityCnt)
    out[cities[i][2]] = cityNo1+cityNo2
    cityCnt += 1
for a in out:
    print(a)

Submission status: Wrong Answer

Solution code:
# coding: UTF-8 

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

py2=sorted(py)


for i in range(M):
    num1=py2.index(py[i]) #num1はpy上の要素が、sortされた時何番目にあるかを示す
    num2=0
    for j in range(0,num1)[::-1]:
        if py2[j][0]!=py2[num1][0]:
            num2=j
        break
    if num2==0:
        num3=num1-num2+1
    else:
        num3=num1-num2
    print(str(py[i][0]).zfill(6)+str(num3).zfill(6))

Submission status: Wrong Answer

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

#list(set(np.array(lst).T.tolist()[0]))
ll=sorted(lst)

j=1
for i in list(set(np.array(lst).T.tolist()[0])):
    for k in ll:
        if i > k[0]:
            continue
        if i == k[0]:
            k[1]=i*1000000+j
            j+=1
        else:
            j=1
            break
#ans
for ans in sorted(ll, key=lambda x:x[2]):
    print('{0:012d}'.format(ans[1]))