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:
import sys

def solve(N, T, ls_ct):
    radi={}
    radi2={}
    for line in ls_ct:
        if line[0] not in radi:
            radi[line[1]] = line[0]
        if line[0] not in radi2:
            radi2[line[0]] = [line[1]]
        else:
            radi2[line[0]].append(line[1])
    re=[i for i in radi2.values()]
    for i in range(len(re)):
        re[i].sort()
    redic={}
    for i in range(len(re)):
        rank = 1
        for ii in re[i]:
            redic[ii] = rank
            rank += 1
    ans = []
    cnt = 0
    for i in radi.keys():
        a = str(radi[i]).zfill(6)
        b = str(redic[i]).zfill(6)
        ans.append(a + b)
        cnt += 1
    return  '\n'.join(ans)

def readQuestion():
    ws = sys.stdin.readline().strip().split()
    N = int(ws[0])
    T = int(ws[1])
    ls_ct = [list(map(int, sys.stdin.readline().strip().split())) for j in range(T)]
    return (N, T, ls_ct)

def main():
    print(solve(*readQuestion()))
main()

Submission status: Wrong Answer

Solution code:
import sys

def solve(N, T, ls_ct):
    print('ls_ct =', ls_ct)
    radi={}
    radi2={}
    for line in ls_ct:
        if line[0] not in radi:
            radi[line[1]] = line[0]
        if line[0] not in radi2:
            radi2[line[0]] = [line[1]]
        else:
            radi2[line[0]].append(line[1])
    re=[i for i in radi2.values()]
    for i in range(len(re)):
        re[i].sort()
    redic={}
    for i in range(len(re)):
        rank = 1
        for ii in re[i]:
            redic[ii] = rank
            rank += 1
    ans = []
    cnt = 0
    for i in radi.keys():
        a = str(radi[i]).zfill(6)
        #b = redic
        b = str(redic[i]).zfill(6)
        ans.append(a + b)
        cnt += 1
    return  '\n'.join(ans)

def readQuestion():
    ws = sys.stdin.readline().strip().split()
    N = int(ws[0])
    T = int(ws[1])
    ls_ct = [list(map(int, sys.stdin.readline().strip().split())) for j in range(T)]
    return (N, T, ls_ct)

def main():
    print(solve(*readQuestion()))
main()

Submission status: Wrong Answer

Solution code:
"""
C - ID
"""
import numpy as np

#入力処理
def simple_input():
    temp_input = input().rstrip().split(' ')
    if len(temp_input) > 1:
        return temp_input
    return temp_input[0]

#メイン処理
if __name__ == '__main__':
    #入力
    n,m = simple_input()
    n = int(n)
    m = int(m)
    shi = np.zeros(shape=(m, 5), dtype=int)

    for i in range(m):
        tp,ty = simple_input()
        shi[i,0] = i
        shi[i,1] = int(tp)
        shi[i,2] = int(ty)
        shi[i,4] = shi[i,1] * 100000 + shi[i,2]

    #県、年順に並び替え
    shi = shi[ shi[:,4].argsort(), :]

    #県別番号振り
    prep = None
    count = 0
    for i in range(m):
        if(prep != shi[i,1]):
            prep = shi[i,1]
            count = 0
        count += 1
        shi[i,3] = count

    #出力
    shi = shi[ shi[:,0].argsort(), :]    #id
    for i in range(m):
        print("{0:06d}{1:06d}".format(shi[i,1], shi[i,3]))

Submission status: Wrong Answer

Solution code:
import sys
def solve(n,m,a):
    bb = {i+1:[] for i in range(n)}
    for [s1,s2] in a:
        bb[s1].append(s2)
    b = [i for i in bb.values()]
    for i in range(len(b)):
        b[i].sort()
    c = {s2:s1 for [s1,s2] in a}
    d = [s2 for [s1,s2] in a]

    ans = ""
    for i in range(m):

        ken = str(c[d[i]])
        ban = str(b[c[d[i]]-1].index(d[i])+1)

        zero = ""
        for i in range(6-len(ken)):
            zero += "0"
        ans += zero
        ans += ken
        zero = ""
        for i in range(6-len(ban)):
            zero += "0"
        ans += zero
        ans += ban
        ans += "\n"
    
    return ans 
def readQuestion():
    ws = sys.stdin.readline().strip().split()
    N = int(ws[0])
    M = int(ws[1])
    ls_PY = [list(map(int, sys.stdin.readline().strip().split())) for j in range(N+1)]
    return (N, M, ls_PY)

def main():
    N, M, ls_PY = readQuestion()
    answer = solve(N, M, ls_PY)
    print(answer)

Submission status: Wrong Answer

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

ans=[]
p=[]

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

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

k=p[0][1]
s=0

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

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

for i in range(m):
    print("%06d%06d"%(ans[i][1],ans[i][2]))

Submission status: Wrong Answer

Solution code:
n = input().split()
l1 = []
for i in range(int(n[1])):
    l1.append(input().split())

for i in range(int(n[1])):
    for j in range(2):
        l1[i][j] = int(l1[i][j])

print(l1)
m = 0
for k in l1:
    k.append(m)
    m += 1

print(l1)
l3 = sorted(l1)
print(l3)

l3[0][1] = 1
for i in range(1,len(l3)):
    if l3[i][0]==l3[i-1][0]:
        l3[i][1]=l3[i-1][1]+1
    else:
        l3[i][1]=1

for i in range(len(l3)):
    l3[i][2],l3[i][0]=l3[i][0],l3[i][2]
for i in range(len(l3)):
    l3[i][1],l3[i][2]=l3[i][2],l3[i][1]
l3.sort()


for i in range(int(n[1])):
    for j in range(2):
        l3[i][j] = str(l3[i][j])

for i in range(len(l3)):
    print(str(l3[i][1]).zfill(6)+str(l3[i][2]).zfill(6))

Submission status: Wrong Answer

Solution code:
import bisect

n, m = [int(_) for _ in input().split(' ')]

p, y = [], []
for _ in range(m):
    temp = [int(_) for _ in input().split(' ')]
    p.append(temp[0])
    y.append(temp[1])
ys = dict()
for i in range(m):
    if not(p[i] in ys):
        ys[p[i]] = []
    ys[p[i]].append(y[i])

for j in ys.keys():
    ys[j].sort()

print(ys)

for i in range(m):
    print('{0}{1}'.format(str(p[i]).zfill(6), str(bisect.bisect(ys[p[i]], y[i])).zfill(6)))

Submission status: Wrong Answer

Solution code:
from operator import itemgetter
n,m = map(int,input().split())
lis = []
ans = [0 for i in range(m)]
num = [0 for i in range(n)]
for i in range(m):
  a,b = map(int,input().split())
  lis.append([i,a,b])
lis.sort(key=itemgetter(2))
for i in range(m):
  num[lis[i][1]-1] += 1
  cou = max(0,5-(lis[i][1] // 10))
  co = max(0,5-(num[lis[i][1]-1] // 10))
  ans[lis[i][0]] = "0" * cou + str(lis[i][1]) + "0" * co + str(num[lis[i][1]-1])
for i in range(m):print(ans[i])

Submission status: Wrong Answer

Solution code:
from operator import itemgetter
n,m = map(int,input().split())
lis = []
ans = [0 for i in range(m)]
num = [0 for i in range(n)]
for i in range(m):
  a,b = map(int,input().split())
  lis.append([i,a,b])
lis.sort(key=itemgetter(2))
for i in range(m):
  num[lis[i][1]-1] += 1
  cou = 6-(lis[i][1] // 10)
  co = 6-(num[lis[i][1]-1] // 10)
  ans[lis[i][0]] = "0" * cou + str(lis[i][1]) + "0" * co + str(num[lis[i][1]-1])
for i in range(m):print(ans[i])

Submission status: Wrong Answer

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

N,M=[int(n) for n in input().split()]
lis=[[i]+[int(n) for n in input().split()] for i in range(M)]
print(lis)
l_2=sorted(lis, key=lambda x: x[2])
dic={}
for k,i,j in l_2:
    dic[i]=dic.get(i,0)+1
    lis[k]='{:0=6}{:0=6}'.format(i,dic[i])
for i in lis:print(i)

Submission status: Wrong Answer

Solution code:
n, m = map(int, input().split())
p = [0]*m
y = [0]*m
for i in range(m):
    p[i], y[i] = map(int, input().split())
    p[i] = p[i] - 1
l = [i for i in range(m)]
for i in range(m):
    l[i] = [i, p[i],y[i]]
 
l.sort(key=lambda x:x[1])
l.sort(key=lambda x:x[2])
print(l)
 
count = [1]*(n)
ans = [[]]*m
for i in range(m):
    ans[i] = [l[i][0], str(l[i][1]).zfill(6) + str(count[(l[i][1])]).zfill(6)]
    count[(l[i][1])] = count[(l[i][1])] + 1
 
 
 
ans.sort(key=lambda x:x[0])
for i in range(m):
    print(ans[i][1])

Submission status: Wrong Answer

Solution code:
n, m = map(int, input().split())
p = [0]*m
y = [0]*m
for i in range(m):
    p[i], y[i] = map(int, input().split())
l = [i for i in range(m)]
for i in range(m):
    l[i] = [i, p[i],y[i]]
 
l.sort(key=lambda x:x[1])
l.sort(key=lambda x:x[2])
print(l)
 
count = [1]*(n+1)
ans = [[]]*m
for i in range(m):
    ans[i] = [l[i][0], str(l[i][1]).zfill(6) + str(count[(l[i][1])]).zfill(6)]
    count[(l[i][1])] = count[(l[i][1])] + 1
 
 
 
ans.sort(key=lambda x:x[0])
for i in range(m):
    print(ans[i][1])

Submission status: Wrong Answer

Solution code:
def ABC113C():
    
    N, M = map(int, input().split())
    PY = [list(map(int, input().split())) for i in range(M)]
    P = [[] for i in range(10 ** 5)]

    from operator import itemgetter
    PY.sort(key = itemgetter(1))
    for k in range(len(PY)):
        i = PY[k][0]
        j = PY[k][1]
        P[i - 1].append([j, k])
    anslist = []
    for i in range(len(P)):
        for j in range(len(P[i])):
            anslist.append([i + 1, j + 1, P[i][j][1] + 1])
    anslist.sort(key = itemgetter(2))
    for i, j, k in anslist:
        i = str(i)
        j = str(j)
        while len(i) != 6:
            i = "0" + i
        while len(j) != 6:
            j = "0" + j
        print(i + j)
ABC113C()

Submission status: Wrong Answer

Solution code:
from operator import itemgetter

N,M=map(int,input().split())
PY=[]
ans=[0 for i in range(M)]
cc=[0 for i in range(N)]
for i in range(M):
    PYi=list(map(int,input().split()))
    PY.append([i,PYi[0],PYi[1]])
     
PY=sorted(PY, key=itemgetter(2))

for i in range(M):
    cc[PY[i][1]-1]+=1
    ans[PY[i][0]]=cc[PY[i][1]-1]

for i in range(M):
    a=format(PY[i][1],'06d')
    b=format(ans[i],'06d')
    print(a+b)

Submission status: Wrong Answer

Solution code:
import numpy as np
N,M = map(int,input().split())
dtype=[('id',int),('p',int),('y',int)]
py = np.array([1]*M).astype(dtype)
for i in range(M):
    py[i][0] = i
    py[i][1],py[i][2] = map(int,input().split())
py = np.sort(py,order=("p",'y'))
ans= ["1"]*M
h = 1
f = -1
for t in py:
    if f != int(t[1]):
        f = int(t[1])
        h = 1
    else:
        h += 1
    ans[t[0]] = "0"*(6-(f//10+1))+str(f)+"0"*(6-(h//10+1))+str(h)
for st in ans:
    print(st)

Submission status: Wrong Answer

Solution code:
import bisect
N, M = map(int, input().split())
P, Y = [], []
pref = [[] for _ in range(N+1)] # non-0-indexed
for m in range(M):
    p,y = map(int, input().split())
    P.append(p)
    Y.append(y)
for p in pref:
	p = p.sort()
    
for p,y in zip(P,Y):
    ans = "{:0>6}".format(p)
    i = bisect.bisect(pref[p], y)
    ans += "{:0>6}".format(i)
    print(ans)

Submission status: Wrong Answer

Solution code:
import bisect
N, M = map(int, input().split())
P, Y = [], []
pref = [[] for _ in range(N+1)] # non-0-indexed
for m in range(M):
    p,y = map(int, input().split())
    P.append(p)
    Y.append(y)
bisect.insort(pref[p], y)

    
for p,y in zip(P,Y):
    ans = "{:0>6}".format(p)
    i = bisect.bisect(pref[p], y)
    ans += "{:0>6}".format(i)
    print(ans)

Submission status: Wrong Answer

Solution code:
print('Super ultimate great language')

Submission status: Wrong Answer

Solution code:
from operator import itemgetter
n,m = map(int,input().split())
py = [list(map(int,input().split())) for _ in range(m)]
copy = py
sorted(py, key=itemgetter(1))
a = [1]*n
b = [0]*m
for i in range(m):
  b[i] = a[py[i][0]-1]
  a[py[i][0]-1] += 1
for j in range(m):
  x = py.index(copy[j])
  print(1000000*copy[j][0]+b[x])

Submission status: Wrong Answer

Solution code:
from itertools import chain


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

P = [0] * N

I = list(range(M))

Q = [None] * M
Y = [None] * M

for m in range(M):
    Q[m], Y[m] = map(int, input().split())
    P[Q[m]-1] += 1

D = zip(I, Q, Y)
D = sorted(D, key=lambda x: [x[1], x[2]])
I, Q, Y = map(list, zip(*D))

print(P)

P = list(chain.from_iterable([list(range(1, p+1)) for p in P]))

print(P)

D = zip(I, Q, Y, P)
D = sorted(D, key=lambda x: x[0])
I, Q, Y, P = map(list, zip(*D))

print(P)

for i in range(M):
    print('%06d%06d' % (Q[i], P[i]))

Submission status: Wrong Answer

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

N,M = [int(x) for x in stdin.readline().rstrip().split()]
counter = 0
country = 1

ID = []

for i in range(M):
    p,y = [int(x) for x in stdin.readline().rstrip().split()]
    ID.append([p,y,i,"no"])
ID.sort(key=itemgetter(0,1))

for i in range(M):
    if ID[i][0] != country:
        counter = 0
    country = ID[i][0]
    counter += 1
    ID_m = format(ID[i][0],"04") + format(counter,"04")
    ID[i][3] = ID_m
    
ID.sort(key=itemgetter(2))

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

Submission status: Wrong Answer

Solution code:
import numpy as np
(N, M) = map(int,input().split())
P = np.empty(M,dtype=np.int64)
Y = np.empty(M,dtype=np.int64)
for i in range(M):
    (P[i], Y[i]) = map(int,input().split())

x = np.zeros(M,dtype=np.int64)
A = [ [] for _ in range(N) ]
for i in range(M):
    A[P[i]-1].append(i)

for j in range(N):
    m = len(A[j])
    if m == 0:
        continue

    cities = np.array(A[j])
    order = Y[cities].argsort() + 1
    for (i,c) in enumerate(cities):
        x[c] = order[i]

for i in range(M):
    print('{:0=6}'.format(P[i])+'{:0=6}'.format(x[i]))

Submission status: Wrong Answer

Solution code:
n,m=map(int,input().split())
i=1
id_list=[]
y_list=[]
id_list2=[]
before=""
after=""
j=0
while j<n:
    id_list.append([0])
    j=j+1 
while i<=m:
    p,y=map(int,input().split())
    y_list.append((p,y))
    id_list[p-1].append(y)
    i+=1
print("n:",n,"p:",p)
for i in range(n):
    id_list[i].sort()
print(id_list)
for item in y_list:
    before=str(item[0])
    while len(before)<6:
        before="0"+before
    after=str(id_list[item[0]-1].index(item[1]))
    
    while len(after)<6:
        after="0"+after
    id_list2.append(before+after)
for idx in id_list2:
    print(idx)

Submission status: Wrong Answer

Solution code:
n,m=map(int,input().split())
i=1
id_list=[]
y_list=[]
id_list2=[]
before=""
after=""
while n>0:
    id_list.append([0])
    n=n-1 
while i<=m:
    p,y=map(int,input().split())
    y_list.append((p,y))
    id_list[p-1].append(y)
    i+=1
for i in range(n):
    id_list[i].sort()
for item in y_list:
    before=str(item[0])
    while len(before)<6:
        before="0"+before
    after=str(id_list[item[0]-1].index(item[1]))
  
    while len(after)<6:
        after="0"+after
    id_list2.append(before+after)
for idx in id_list2:
    print(idx)

Submission status: Wrong Answer

Solution code:
from itertools import groupby

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

py = [py_i + [i] for i, py_i in enumerate(py)]
py_ = []
for key, group in groupby(py, lambda x: x[0]):
	for i, city in enumerate(group):
		py_.append(city + [i+1])
py = sorted(py_, key=lambda x: x[3])

for py_i in py:
	print(str(py_i[0]).zfill(6) + str(py_i[3]).zfill(6))

Submission status: Wrong Answer

Solution code:
from operator import itemgetter

N,M=map(int,input().split())
PY=[]
P=[[] for i in range(N)]
ans=[0 for i in range(M)]
for i in range(M):
    PYi=list(map(int,input().split()))
    PY.append(PYi)
    P[PYi[0]-1].append([i,PYi[1]])

for i in range(N):
    P[i]=sorted(P[i], key=itemgetter(1))

for i in range(N):
    for j in range(len(P[i])):
        ans[P[i][j][0]]=j+1

for i in range(M):
    a=format(PY[i][0],'06x')
    b=format(ans[i],'06x')
    print(a+b)

Submission status: Wrong Answer

Solution code:
from operator import itemgetter

N,M=map(int,input().split())
PY=[]
P=[[] for i in range(N)]
ans=[0 for i in range(M)]
for i in range(M):
    PYi=list(map(int,input().split()))
    PY.append(PYi)
    P[PYi[0]-1].append([i,PYi[1]])

for i in range(N):
    P[i]=sorted(P[i], key=itemgetter(1))

for i in range(N):
    for j in range(len(P[i])):
        ans[P[i][j][0]]=j+1

print(P)
print(ans)
print(N)
for i in range(M):
    a=format(PY[i][0],'06x')
    b=format(ans[i],'06x')
    print(a+b)

Submission status: Wrong Answer

Solution code:
n,p = map(int, input().split())
lst = [list(map(int, input().split())) for i in range(p)]
plst = []
plst = [i[0] for i in lst]
ylst = [i[1] for i in lst]
dic = {i : sorted([j[1] for j in lst if j[0] == i]) for i in plst}
print(dic)
for k in range(p):
  x = str(lst[k][0]).zfill(6)
  y = str(dic[lst[k][0]].index(lst[k][1])+1).zfill(6)
  print(x + y)

Submission status: Wrong Answer

Solution code:
n,m = map(int,input().split())
d = [[]]*(n+1)
q = [[]]*(n+1)
p = [0]*m
y = [0]*m
for i in range(m):
  p[i], y[i] = map(int,input().split())
  d[p[i]] = d[p[i]] + [y[i]]
for i in range(n+1):
  if len(d[i]) == 0:
    continue
  d[i] = sorted(d[i])
  d[i] = dict([[d[i][j],j] for j in range(len(d[i]))])
print(d)
for i in range(m):
  print("{0:06d}".format(p[i])+"{0:06d}".format(d[p[i]][y[i]]+1))

Submission status: Wrong Answer

Solution code:
n, m = map(int,input().split())
list = [input().split() for i in range(m)]
     
list2 = [list[i][0] for i in range(m)]
     
l = [sorted([list[i][1] for i in range(m) if int(list[i][0]) == j+1]) for j in range(n)]
     
y = [l[int(list[i][0])-1].index(list[i][1])+1 for i in range(m)]
     
for i in range(m):
        print((list2[i].zfill(6))+(str(y[i]).zfill(6)))

Submission status: Wrong Answer

Solution code:
n, m = map(int, input().split())
a = [0] * (n+1)
b = [list(map(int, input().split())) + [i] + [0] for i in range(m)]
b.sort(key= lambda x:x[1])
for i, (v, x, y, z) in enumerate(b):
    a[v-1] += 1
    b[i][3] = a[v-1]
b.sort(key = lambda x:x[2])
for v,x,y,z in b:
    print("{0:06d}{0:06d}".format(v,z))

Submission status: Wrong Answer

Solution code:
n, m = map(int, input().split())
a = [0] * (n)
b = [list(map(int, input().split())) + [i] + [0] for i in range(m)]
b.sort(key= lambda x:x[1])
for i, (v, x, y, z) in enumerate(b):
    a[v-1] += 1
    b[i][3] = a[v-1]
b.sort(key = lambda x:x[2])
for v,x,y,z in b:
    print("{0:06d}{0:06d}".format(v,z))

Submission status: Wrong Answer

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

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

d = []
for i in range(b):
    k,kk = map(int,input().split())
    d.append([k, kk,0])

da = sorted(d)

kkk = da[0][0]
ll = 0
for i in da:
    kkkk = i[0]
    if kkk == kkkk:
        ll += 1
        i[2] += ll
    else:
        kkk = kkkk
        ll = 1
        i[2] += ll
for i in d:
    p = (da.index(i)-1)
    n = str(i[0])
    m = str(d[p][2])

    n = "0"*(6-len(n)) + n
    m = "0"*(6-len(m)) + m

    print(n+m)

Submission status: Wrong Answer

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

shi_map = []

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

shi_map = sorted(shi_map, key=lambda x: (x[1], x[2]))
print(shi_map)

result = {}
shi_count = {}
for i, p, y in shi_map:

    if p in shi_count:
        c = shi_count[p]
        count = c + 1
        shi_count[p] = count
    else:
        shi_count[p] = 1
        count = 1
    result[i] = [p, count]
result = list(sorted(result.items(), key=lambda x: x[0]))

for i, p in result:

    p2 = str(p[0]).zfill(6)

    y = str(p[1]).zfill(6)
    r = p2+y
    print(r)

Submission status: Wrong Answer

Solution code:
import copy

n, m = input().strip().split(' ')
n, m = [int(n), int(m)]

p = []
y = []

for i in range(m):
    a, b = input().strip().split(' ')
    a, b = [int(a), int(b)]
    p.append(a)
    y.append(b)

z = copy.deepcopy(y)

for i in range(len(z)-1):
    for j in range(i, len(z)-1, 1):
        if z[j] > z[j + 1]:
            tmp = z[j]
            z[j] = z[j + 1]
            z[j + 1] = tmp

min = []
order = []
for i in range(n):
    min.append(0)
    
for i in range(m):
    order.append(0)
    
for i in range(m):
    for j in range(m):
        if z[i] == y[j]:
            min[p[j] - 1] += 1
            order[j] = min[p[j] - 1]

def addzero(a):
    str = ''
    for i in range(6 - len(a)):
        str += '0'
    return str

for i in range(m):
    print(addzero(str(p[i])) + str(p[i]) + addzero(str(order[i])) + str(order[i]))

Submission status: Wrong Answer

Solution code:
nm=list(map(int,input().split()))
n=nm[0]
m=nm[1]
py=[]
y=[]
for i in range(m):
    py.append([])
for i in range (n):
    y.append([])
for i in range(m):
    py[i]=list(map(int,input().split()))
    y[py[i][0]-1].append(py[i][1])
for i in range(n):
    y[i].sort()
print(py)
print(y)
for i in range(m):
    if py[i][0]<10:
        print("00000"+str(py[i][0]*10**6+y[py[i][0]-1].index(py[i][1])+1))
    elif  py[i][0]<100:
        print("0000"+str(py[i][0]*10**6+y[py[i][0]-1].index(py[i][1])+1))
    elif py[i][0]<1000:
        print("000"+str(py[i][0]*10**6+y[py[i][0]-1].index(py[i][1])+1))
    elif py[i][0]<10000:
        print("00"+str(py[i][0]*10**6+y[py[i][0]-1].index(py[i][1])+1))
    elif py[i][0]<100000:
        print("0"+str(py[i][0]*10**6+y[py[i][0]-1].index(py[i][1])+1))
    else:
        print(str(py[i][0]*10**6+y[py[i][0]-1].index(py[i][1])+1))

Submission status: Wrong Answer

Solution code:
N, M = map(int, input().split())
data = [[int(i) for i in input().split()] for i in range(M)]
  
corresp = {}
for n in range(1, N+1):
    data_n = []
    for i in range(M):
        if data[i][0] == n:
            data_n.append(data[i])
    sort_n = sorted(data_n, key=lambda data_n_i: data_n_i[1])
    for k in range(len(sort_n)):
        corresp.update({str(sort_n[k]):k+1})
    

for i in range(M):
    print('{0:012d}'.format(data[i][0]*100000+corresp[str(data[i])]))

Submission status: Wrong Answer

Solution code:
import numpy as np

n, m = list(map(int, input().split()))
mat = np.zeros((m, 2))
for i in range(m):
	mat[i, 0], mat[i, 1] = list(map(int, input().split()))
mat = np.c_[mat, np.array(range(m))]
mat_ = mat[mat[:, 0].argsort()]
mat__ = mat_[mat_[:, 1].argsort()]

res = []

cnt = 0
prev_i = 0
#print(mat_)
for i in mat__[:, 0]:
	if prev_i != i:
		cnt = 1
	else:
		cnt += 1
	res.append('{0:06d}{1:06d}'.format(int(i), int(cnt)))
	prev_i = i
#print(res)
#print(list(mat_[:, 2]))
for i in np.argsort(mat__[:, 2]):
	print(res[int(i)])
#res_ = res[np.argsort(mat_[:, 2])]
#for r in res_:
#	print(r)

Submission status: Wrong Answer

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

import sys
import numpy as np

if __name__ == '__main__':
    n, m = map(int, raw_input().split())
    cities = []
    city_lst = {}
    for i in range(0, m):
        p, y = map(int, raw_input().split())
        cities.append((p, y))
        if not p in city_lst:
            city_lst[p] = [y]
        else:
            city_lst[p].append(y)
    for key in city_lst.keys():
        np.array(city_lst[key]).sort()
    for city in cities:
        print str('%06d' % city[0]) + str('%06d' % (int(city_lst[city[0]].index(city[1]) + 1)))
        sys.stdout.flush()

Submission status: Wrong Answer

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

corresp = {}
for n in range(1, N+1):
    data_n = []
    for i in range(M):
        if data[i][0] == n:
            data_n.append(data[i])
    sort_n = sorted(data_n, key=lambda data_n_i: data_n_i[1])
    for k in range(len(sort_n)):
        corresp.update({str(sort_n[k]):k+1})
    

for i in range(M):
    print('{0:012d}'.format(data[i][0]*100000+corresp[str(data[i])]))

Submission status: Wrong Answer

Solution code:
n, m = list(map(int, input().split(" ")))
p = m*[0]
y = m*[0]
ken = [[0] for i in range(n)]
for i in range(m):
    p[i], y[i] = list(map(int, input().split(" ")))
    ken[p[i]-1].append(y[i])

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

for i in range(m):
    print("%06d%06d" %(p[i], ken[p[i]-1].index(y[i])))

Submission status: Wrong Answer

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

for i in range(len(lis)):
    lis[i].append(i)

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

city = 0
cnt = 1
for i in range(len(lis)):
    if lis[i][0] is not city:
        city = lis[i][0]
        cnt = 1
    num = str(lis[i][0]).zfill(6) + str(cnt).zfill(6)
    lis[i].append(num)
    cnt += 1
    
lis.sort(key=lambda x:x[2])

for i in range(len(lis)):
    print(lis[i][3])

Submission status: Wrong Answer

Solution code:
import bisect

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

for _ in range(M):
    P, Y = map(int, input().split())
    PY.append([P, Y])
    array[P-1].append(Y)

for p, y in PY:
    n = bisect.bisect_left(array[p-1], y) + 1
    print('%06d%06d' % (p, n))

Submission status: Wrong Answer

Solution code:
n, m = map(int,input().split())
xs = [0]*m
pre = [0]*m
for x in range(m):
    xs[x] = list(list(map(int,input().split())) + [x] + [x])
xs.sort()

print(xs)
skip = 0
for p in range(1,n+1):
    cnt = 1
    flag = 0
    for x in range(skip,len(xs)):
        if xs[x][0] <= p:
            xs[x][3] = cnt
            cnt += 1
            skip += 1
        else:
            flag = 1
        if flag:
            break


for x in sorted(xs, key=lambda x:x[2]):
    print('{0:06d}'.format(x[0]) + '{0:06d}'.format(x[3]))

Submission status: Wrong Answer

Solution code:
def con(var):
    var=str(var)
    while(len(var)<6):
        var="0"+var
    return var


def run():
    N,M=map(int,input().split())
    P=[-1]*M
    Y=[-1]*M
    arr=[]
    for i in range(M):
        P[i],Y[i]=input().split()
        P[i]=int(P[i])-1
        Y[i]=int(Y[i])
        arr.append([P[i],Y[i],i])
    arr=sorted(arr,key=lambda x:x[1])
    print(arr)
    ans=[0]*M
    cnt=[0]*N
    for i in range(M):
        cnt[arr[i][0]]=cnt[arr[i][0]]+1
        ans[arr[i][2]]=con(arr[i][0]+1)+con(cnt[arr[i][0]])
    for i in range(M):
        print(ans[i])
run()

Submission status: Wrong Answer

Solution code:
import numpy as np
N,M = map(int,input().split())
P = []
Y = []
index = range(1,M+1)
for i in range(M):
 a,b= map(int,input().split())
 P.append(a)
 Y.append(b)
for i in range(1,N+1):
 a = [j for j, x in enumerate(P) if x == i]
 for p in range(len(a)+1,1,-1):
  print('{0:04d}'.format(i)+'{0:04d}'.format(p-1))

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline
from operator import itemgetter

N,M = (int(i) for i in input().split())

pp = [[] for _ in range(N)]

clist = []
for _ in range(M):
    p, y = (int(i) for i in input().split())
    clist.append((p,y))

plist = sorted(clist, key=itemgetter(0))

for p, y in plist:
    pp[p-1].append(y)

for p, y in clist:
    num = pp[p-1].index(y) + 1
    print('%06d' % p + '%06d' % num)

Submission status: Wrong Answer

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

a_dict = {}
for pi,yi in e:
    if(pi not in a_dict):
        a_dict[pi] = [yi]
    else:
        a_dict[pi] += [yi]

for v in a_dict.values():
    print(v)

for pi,yi in e:
    print('{0:06d}'.format(pi)+'{0:06d}'.format(a_dict[pi].index(yi)+1))

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline
from operator import itemgetter

N,M = (int(i) for i in input().split())

pp = [[] for _ in range(N)]

clist = []
for _ in range(M):
    p, y = (int(i) for i in input().split())
    clist.append((p,y))

clist = sorted(clist, key=itemgetter(1))

for p, y in clist:
    pp[p-1].append(y)

for p, y in clist:
    num = pp[p-1].index(y) + 1
    print('%06d' % p + '%06d' % num)

Submission status: Wrong Answer

Solution code:
import copy
n, m = map(int, input().split())
s = []
for i in range(m):#h:高さ
    s.append([int(i) for i in input().split()])
    #l2 = l[:]
t = s[:]
t.sort()
t.sort(key=lambda x: x[1])
co = 1
for i in range(m):
    if i != 0:
        if t[i][0] != t[i - 1][0]:
            co = 1
    if t[i][0] <10:
        moji1 = "00000" + str(t[i][0])
    elif t[i][0] <100:
        moji1 = "0000" + str(t[i][0])
    elif t[i][0] <1000:
        moji1 = "000" + str(t[i][0])
    elif t[i][0] <10000:
        moji1 = "00" + str(t[i][0])
    elif t[i][0] <100000:
        moji1 = "0" + str(t[i][0])
    else:
        moji1 = str(t[i][0])

    if co <10:
        moji2 = "00000" + str(co)
    elif co <100:
        moji2 = "0000" + str(co)
    elif co <1000:
        moji2 = "000" + str(co)
    elif co <10000:
        moji2 = "00" + str(co)
    elif co <100000:
        moji2 = "0" + str(co)
    else:
        moji2 = str(co)
    t[i].append(moji1 + moji2)
    co += 1

for i in range(m):
    print(s[i][2])

Submission status: Wrong Answer

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

Info = [[] for i in range(10 ** 5 + 1)]
for i in range(M):
    p, y = map(int, input().split())
    Info[p].append((y, i))

ans = []
for pre_id, info in enumerate(Info):
    info = sorted(info)
    for i in range(len(info)):
        ans.append((info[i][1], str(pre_id)[::-1].zfill(6), str(i + 1)[::-1].zfill(6)))

ans.sort()
for i, x, y in ans:
    print(str(x) + str(y))

Submission status: Wrong Answer

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


for i in range(m):
    c = 1
    for j in range(m):
        if py[i][0] == py[j][0] and py[i][1] > py[j][1]:
            c += 1
    a = py[i][0] * 10**6 + c
    if a < 10**7:
        print("00000",str(a))
    elif a < 10**8:
        print("0000",str(a))
    elif a < 10**9:
        print("000",str(a))
    elif a < 10**10:
        print("00",str(a))
    elif a < 10**11:
        print("0",str(a))
    else:
        print(a)

Submission status: Wrong Answer

Solution code:
import numpy as np
N,M = map(int,input().split())
py = np.zeros(M*3).reshape(M,3)
for i in range(M):
    py[i][0] = i
    py[i][1],py[i][2] = map(int,input().split())
dtype=[('id',int),('p',int),('y',int)]
py = np.array(py,dtype=dtype)
py = np.sort(py,order=("p",'y'))
print(py)
ans= ["1"]*M
h = 1
f = -1
for t in py:
    if f != int(t[1][0]):
        f = int(t[1][0])
        h = 1
    else:
        h += 1
    ans[t[0][0]] = "0"*(6-(f//10+1))+str(f)+"0"*(6-(h//10+1))+str(h)
for st in ans:
    print(st)