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:
nm_lst = list(map(int, input().split()))
city_lst = [list(map(int, (str(i)+' '+input()).split())) for i in range(nm_lst[1])]

city_lst = sorted(city_lst, key = lambda x: x[1]*10**7 + x[2])

ans_lst = []
num_num = 0
for n, city in enumerate(city_lst):
    prefec_num = city[1]
    prefec_str = '0' * (6-len(str(prefec_num))) + str(prefec_num)
    if prefec_num != city_lst[n-1][1]:
        num_str = '000001'
        num_num = 1
    else:
        num_num += 1
        num_str = '0' * (6-len(str(num_num))) + str(num_num)
    ans_lst.append([city[0], prefec_str, num_str])
    
ans_lst = sorted(ans_lst, key = lambda x:x[0])

for city in ans_lst:
    print(city[1]+city[2])

Submission status: Wrong Answer

Solution code:
n, m = map(int,input().split())
l = []
for i in range(m):
    l.append(list(map(int,input().split())))
l.sort()
p = 0
for i in l:
    if i[0] != p:
        p = i[0]
        x = 1
    else:
        x += 1
    print(str(i[0]).zfill(6)+ str(x).zfill(6))

Submission status: Wrong Answer

Solution code:
N,M=map(int,input().split(" "))
P=[]
Y=[]
Q=[]
QQ=[]
for i in range(0,M):
  pp,yy=map(int,input().split(" "))
  P.append(pp)
  Y.append(yy)
  Q.append([pp,yy])
print(P)
print(Y)
print(Q)

Q.sort()
print(Q)

MAEA=Q[0][0]
for II in Q:
  A=II[0]
  B=II[1]
  if MAEA!=A:
    QQ.sort()
    print("oo"+str(QQ),str(II),str(Q[M-1]))
    for iii in range(0,len(QQ)):      
      print(("%06d"%(QQ[iii][1])+("%06d"%(iii+1))))
    QQ=[]
    
  QQ.append([B,A])
  print("GG"+str(QQ))
  
  if II==Q[M-1]:
    QQ.sort()
    print("oshimai"+str(QQ),str(II),str(Q[M-1]))
    for iii in range(0,len(QQ)):      
      print(("%06d"%(QQ[iii][1])+("%06d"%(iii+1))))
    
  MAEA=A
  continue

Submission status: Wrong Answer

Solution code:
n, m = map(int, input().split())
p = []
tmp = [[] for i in range(n+1)]
for i in range(m):
  p.append(list(map(int, input().split())))
  tmp[p[i][0]].append(p[i][1])
for i in range(n):
  tmp[i].sort()
for i in range(m):
  print('{:0=6}{:0=6}'.format(p[i][0], tmp[p[i][0]].index(p[i][1])+1))

Submission status: Wrong Answer

Solution code:
import numpy as np

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

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

for inputs in input_list:
    m_list[inputs[0]-1].append(inputs[1])

index_list_sorted = []
for arr in m_list:
    index_list_sorted.append(np.argsort(arr))

cnt = [0] * N
for inputs in input_list:
    p = inputs[0]-1
    num = index_list_sorted[p][cnt[p]] + 1
    print(str(inputs[0]).zfill(6) + str(num).zfill(6))
    cnt[p] += 1

Submission status: Wrong Answer

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

m_list = [[] for j in range(N)]

for inputs in input_list:
    m_list[inputs[0]-1].append(inputs[1])

print(m_list)
for arr in m_list:
    arr.sort()

print(m_list)

for inputs in input_list:
    num = m_list[inputs[0]-1].index(inputs[1]) + 1
    print(str(inputs[0]).zfill(6) + str(num).zfill(6))

Submission status: Wrong Answer

Solution code:
import numpy as np
from operator import itemgetter

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

for i, c in enumerate(C):
  C[i] = [int(c[0]), int(c[1])]
  C[i].append(i)

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

counter = 1
current = 1

for c in C_sorted:
  if current < c[0]:
    counter = 1
  pref = str(c[0])
  num = str(counter)
  number = ''
  for i in range(6 - len(pref)):
    number += '0'
  number += pref
  for i in range(6 - len(num)):
    number += '0'
  number += num

  c.append(number)
  counter += 1
  current = c[0]

print(C_sorted)

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

for c in C_reversed:
  print(c[3])

Submission status: Wrong Answer

Solution code:
import numpy as np
from operator import itemgetter

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

for i, c in enumerate(C):
  C[i] = [int(c[0]), int(c[1])]
  C[i].append(i)

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

counter = 1
current = 1
for c in C_sorted:
  if current < c[0]:
    counter = 1
  pref = str(c[0])
  num = str(counter)
  number = ''
  for i in range(6 - len(pref)):
    number += '0'
  number += pref
  for i in range(6 - len(num)):
    number += '0'
  number += num

  c.append(number)
  counter += 1
  current = c[0]

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

for c in C_reversed:
  print(c[3])

Submission status: Wrong Answer

Solution code:
n, m = map(int, input().split())
index = 0
listForL = []
listForL2 = []
while index < m:
    p, y = map(int, input().split())
    listForL.append([p, y])
    listForL2.append([p, y, index])
    index+=1

listForL2.sort()
listForAns=[0]*m
index2 =0
count = 0
before=0
while index2 < len(listForL2):
    if before!=listForL2[index2][0]:
        count=1
        before = listForL2[index2][0]
    else:
        count+=1
    mojiR=str(listForL2[index2][0])
    mojiL=str(count)
    index3=0
    if len(mojiR)==1:
        mojiR="00000"+mojiR
    elif len(mojiR)==2:
        mojiR = "0000"+mojiR
    elif len(mojiR)==3:
        mojiR = "000"+mojiR
    elif len(mojiR)==4:
        mojiR = "00"+mojiR
    elif len(mojiR)==5:
        mojiR = "0"+mojiR
    if len(mojiL) == 1:
        mojiL = "00000"+mojiL
    elif len(mojiL) == 2:
        mojiL = "0000"+mojiL
    elif len(mojiL) == 3:
        mojiL = "000"+mojiL
    elif len(mojiL) == 4:
        mojiL = "00"+mojiL
    elif len(mojiR) == 5:
        mojiL = "0"+mojiL
    listForAns[listForL2[index2][2]]=mojiR+mojiL
    index2+=1

for ans in listForAns:
    print(ans)

Submission status: Wrong Answer

Solution code:
n, m = map(int, input().split())
index = 0
listForL = []
listForL2 = []
while index < m:
    p, y = map(int, input().split())
    listForL.append([p, y])
    listForL2.append([p, y])
    index+=1

listForL2.sort()
print(listForL2)
listForId=[]
index2 =0
count = 0
before=0
while index2 < len(listForL2):
    if before!=listForL2[index2][0]:
        count=1
        before = listForL2[index2][0]
    else:
        count+=1
    mojiR=str(listForL2[index2][0])
    mojiL=str(count)
    index3=0
    while index3 < 6:
        if len(mojiR)< 6:
            mojiR="0"+mojiR
        elif len(mojiR)==6:
            break
        index3+=1
    index4=0
    while index4 < 6:
        if len(mojiL)< 6:
            mojiL="0"+mojiL
        elif len(mojiL)==6:
            break
        index4+=1
    index2+=1
    listForId.append(mojiR+mojiL)

index5=0
while index5 < len(listForL):
    targetI = listForL2.index(listForL[index5])
    print(listForId[targetI])
    index5+=1

Submission status: Wrong Answer

Solution code:
# coding:utf-8

import sys
from collections import Counter, defaultdict

INF = float('inf')
MOD = 10 ** 9 + 7

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def II(): return int(sys.stdin.readline())
def SI(): return input()


n, m = LI()
YP = [[y, p] for p, y in (LI() for _ in range(m))]

YP.sort()

P = defaultdict(int)
for y, p in YP:
    P[p] += 1
    l1, l2 = len(str(p)), len(str(P[p]))
    id = (6 - l1) * '0' + str(p) + (6 - l2) * '0' + str(P[p])
    print(id)

Submission status: Wrong Answer

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

    pref = []
    for _ in range(M):
        P, Y = list(map(int, input().split()))
        pref.append((P, Y))

    pref_sorted = sorted(enumerate(pref), key=lambda x: x[1])

    res = []
    for i in range(1, N + 1):
        c = 1
        for j, (p, y) in pref_sorted:
            if i == p:
                res.insert(j, str(p).zfill(6) + str(c).zfill(6))
                c += 1
    for r in res:
        print(r)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
n,m=map(int,input().split())
cnt=[0]*(n+1)
a=[]
for i in range(m):
    p,y=map(int,input().split())
    a.append((y,p,i))
a.sort()
b=[]
for y,p,i in a:
    cnt[p]+=1
    b.append((i,"{0:06}{0:06}".format(p,cnt[p])))
b.sort()
for i,r in b:
    print(r)

Submission status: Wrong Answer

Solution code:
n,m=map(int,input().split())
cnt=[0]*(n+1)
a=[]
for i in range(m):
    p,y=map(int,input().split())
    a.append((y,p,i))
a.sort()
print(a)
b=[]
for y,p,i in a:
    cnt[p]+=1
    b.append((i,"{0:06}{0:06}".format(p,cnt[p])))
b.sort()
print(b)
for i,r in b:
    print(r)

Submission status: Wrong Answer

Solution code:
from bisect import bisect
L = list(map(int,input().split()))
N = L[0]
M = L[1]
P = list()
Y = list()
S = list()
for x in range(0,N):
    S.append(list())
for x in range(0,M):
    X = list(map(int,input().split()))
    P.append(X[0])
    Y.append(X[1])
    S[X[0]-1].append(X[1])
for y in range(0,M):
    n = 0
    n = bisect(S[P[y]-1],Y[y])
    nstr = str(n)
    Pstr = str(P[y])
    while len(nstr) < 6:
        nstr = '0' + nstr
    while len(Pstr) < 6:
        Pstr = '0' + Pstr
    number = Pstr + nstr
    print(number)

Submission status: Wrong Answer

Solution code:
import bisect
N,M=map(int,input().split())
A=[[] for j in range(N)]
px=[]
for i in range(M):
    p,x=map(int,input().split())
    A[p-1].append(x)
    px.append([p,x])
for m in range(N):
    A[m].sort()
for k in range(M):
    q=bisect.bisect_left(A[px[k][0]-1],px[k][1])
    print("0"*(6-len(str(px[k][0])))+str(px[k][0])+"0"*(6-len(str(q)))+str(q+1))

Submission status: Wrong Answer

Solution code:
import bisect
N,M=map(int,input().split())
A=[[] for j in range(N)]
px=[]
for i in range(M):
    p,x=map(int,input().split())
    A[p-1].append(x)
    px.append([p,x])
for m in range(N):
    A[m].sort()
for k in range(M):
    q=bisect.bisect_left(A[px[k][0]-1],px[k][1])
    print("0"*(6-len(str(px[k][0])))+str(px[k][0])+"0"*(6-len(str(q)))+str(q+1))

Submission status: Wrong Answer

Solution code:
import bisect
N,M=map(int,input().split())
A=[[] for j in range(N)]
px=[]
for i in range(M):
    p,x=map(int,input().split())
    A[p-1].append(x)
    px.append([p,x])
for m in range(N):
    A[m].sort()
for k in range(M):
    q=bisect.bisect_left(A[px[k][0]-1],px[k][1])
    print("0"*(6-len(str(px[k][1])))+str(px[k][0])+"0"*(6-len(str(q)))+str(q+1))

Submission status: Wrong Answer

Solution code:
# N個の県, 全部でM個の市
N, M = input().split()
N = int(N)
M = int(M)
PY = []
# 全ての県のi番目の都市を管理
Pwas = [0 for i in range(N)]

for i in range(M):
    # 県PにY年に生まれた都市
    P, Y = input().split()
    PY.append((P, Y, i))

# 全ての都市を生誕年ソート
sortedPY = sorted(PY, key=lambda PY:PY[1])

for i,x in enumerate(sortedPY):
    P = x[0]
    # Pwasのindexでどこの県かを管理し、値に何個都市があるか入っている
    idx = int(P) - 1
    Pwas[idx] = Pwas[idx] + 1
    PY[x[2]] = P.zfill(6) + str(Pwas[idx]).zfill(6)

for x in PY:
    print(x)

Submission status: Wrong Answer

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

for i in range(M):
    Px, Yy = input().split()
    PY.append((Yy, Px, i))

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

for i,x in enumerate(sortedPY):
    P = x[1]
    idx = int(P) - 1
    Pwas[idx] = Pwas[idx] + 1
    PY[x[2]] = P.zfill(6) + str(Pwas[idx]).zfill(6)

for x in PY:
    print(x)

Submission status: Wrong Answer

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

def numbering(Y, P):
    # Pwas[P-1]に今まで何個あったかが入っている
    # 6ケタ市 + 6ケタ順番
    idx = int(P) - 1
    Pwas[idx] = Pwas[idx] + 1
    num = P.zfill(6) + str(Pwas[idx]).zfill(6)
    return num

for i in range(M):
    Px, Yy = input().split()
    # 年、県のTuple
    PY.append((Yy, Px, i))

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

result = []
for i,x in enumerate(PY):
    PY[i] = (x[2], numbering(x[0], x[1]))

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

for x in PY:
    print(x[1])

Submission status: Wrong Answer

Solution code:
def numbering(Y, P):
    # Pwas[P-1]に今まで何個あったかが入っている
    # 6ケタ市 + 6ケタ順番
    idx = int(P) - 1
    Pwas[idx] = Pwas[idx] + 1
    num = P.zfill(6) + str(Pwas[idx]).zfill(6)
    return num

N, M = input().split()
N = int(N)
M = int(M)
PY = []
Pwas = [0 for i in range(N)]

for i in range(M):
    Px, Yy = input().split()
    # 年、県のTuple
    PY.append((Yy, Px, i))

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

result = []
for i,x in enumerate(PY):
    PY[i] = (x[2], numbering(x[0], x[1]))

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

for x in PY:
    print(x[1])

Submission status: Wrong Answer

Solution code:
def numbering(Y, P):
    # Pwas[P-1]に今まで何個あったかが入っている
    # 6ケタ市 + 6ケタ順番
    idx = int(P) - 1
    Pwas[idx] = Pwas[idx] + 1
    num = P.zfill(6) + str(Pwas[idx]).zfill(6)
    return num

N, M = input().split()
N = int(N)
M = int(M)
PY = []
Pwas = [0 for i in range(N)]

for i in range(M):
    Px, Yy = input().split()
    # 年、県のTuple
    PY.append((Yy, Px, i))

PY.sort()

result = []
for x in PY:
    result.append((x[2], numbering(x[0], x[1])))

result.sort()

for x in result:
    print(x[1])

Submission status: Wrong Answer

Solution code:
def numbering(Y, P):
    # Pwas[P-1]に今まで何個あったかが入っている
    # 6ケタ市 + 6ケタ順番
    idx = int(P) - 1
    Pwas[idx] = Pwas[idx] + 1
    num = P.zfill(6) + str(Pwas[idx]).zfill(6)
    return num

N, M = input().split()
N = int(N)
M = int(M)
PY = []
Pwas = [0 for i in range(N)]

for i in range(M):
    Px, Yy = input().split()
    # 年、県のTuple
    PY.append((Yy, Px))

PY.sort()

for x in PY:
    print(numbering(x[0], x[1]))

Submission status: Wrong Answer

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

cities = []
for x in range(M):
    l2 = input().split(' ')
    cities.append(l2)

# init ここまで

# 6桁にする関数fill
def fill(s):
    while len(s) < 6:
        s = '0' + s
    return s

ids = []
#index i にi県の市ディクショナリを作る。
dic = {}
for city in cities:
    pref = city[0]
    if(not (pref in dic)):
        dic[pref] = []
    dic[pref].append(city)


# 各県について、市のできた順に番号割り振り


for pref in dic.keys():
    cityList = dic[pref]
    l = len(cityList)
    for i in range(l-1):
        for j in range(l-1, 0, -1):
            if(int(cityList[i][1]) > int(cityList[j][1])):
                cityList[i], cityList[j] = cityList[j], cityList[i]

for pref in dic.keys():
    for i in range(len(dic[pref])):
        dic[pref][i].append(str(i+1))


for city in cities:
    print(fill(city[0]) + fill(city[2]))

Submission status: Wrong Answer

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

cities = []
for x in range(M):
    l2 = input().split(' ')
    cities.append(l2)

# init ここまで

# 6桁にする関数fill
def fill(s):
    while len(s) < 6:
        s = '0' + s
    return s

ids = []
#index i にi県の市ディクショナリを作る。
dic = {}
for city in cities:
    pref = city[0]
    if(not (pref in dic)):
        dic[pref] = []
    dic[pref].append(city)


# 各県について、市のできた順に番号割り振り


for pref in dic.keys():
    cityList = dic[pref]
    l = len(cityList)
    for i in range(l):
        for j in range(l-1, 0, -1):
            if(int(cityList[i][1]) > int(cityList[j][1])):
                cityList[i], cityList[j] = cityList[j], cityList[i]

for pref in dic.keys():
    for i in range(len(dic[pref])):
        dic[pref][i].append(str(i+1))


for city in cities:
    print(fill(city[0]) + fill(city[2]))

Submission status: Wrong Answer

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

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

count = {}
order = {}

for i, p, y in ipy:
    if not p in count:
        count[p] = 1
    else:
        count[p] += 1
    order[i, p] = count[p]
    
for i, p, y in ipy:
    print('{:06}{:06}'.format(i, order[i, p]))

Submission status: Wrong Answer

Solution code:
N, M = map(int, input().split(' '))
PY = [list(input().split(' ')) for m in range(M)]
sorted_PY = sorted(PY, key=lambda x:(x[0], x[1]))
sorted_P = [p[0] for p in sorted_PY]
sorted_Y = [y[1] for y in sorted_PY]
for m in range(M):
    pre_id = PY[m][0].zfill(6)
    suf_id = str((sorted_Y.index(PY[m][1]) - sorted_P.index(PY[m][0]) + 1)).zfill(6)
    print(pre_id + suf_id)

Submission status: Wrong Answer

Solution code:
import bisect
n, m = map(int, input().split())
p = []
y = []
py = []
categorized = [[] for i in range(n+1)]
for i in range(m):
    tmpp, tmpy = map(int, input().split())
    p.append(tmpp)
    y.append(tmpy)
    categorized[tmpp].append(tmpy)

for c in categorized:
    c.sort()
print(categorized)
for i in range(m):
    order = bisect.bisect(categorized[p[i]], y[i])
    print('%06d%06d' % (p[i], order))

Submission status: Wrong Answer

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

l=[]
cnt = 1
for i in range(n[1]):
    l.append(str(t[i][0]).rjust(6,'0') + str(cnt).rjust(6,'0')) #6桁ゼロ埋め
    try:
      if t[i+1][0] != t[i][0]:
        cnt = 1
      else:
        cnt += 1
    except(IndexError):
      break

for i in range(n[1]):
  print(l[i])

Submission status: Wrong Answer

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

l=[]
cnt = 1
for i in range(n[1]):
    print(str(t[i][0]).rjust(6,'0') + str(cnt).rjust(6,'0')) #6桁ゼロ埋め
    try:
      if t[i+1][0] != t[i][0]:
        cnt = 1
      else:
        cnt += 1
    except(IndexError):
      break

Submission status: Wrong Answer

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

l=[]
cnt = 1
for i in range(n[1]):
    print(str(t[i][0]).rjust(6,'0') + str(cnt).rjust(6,'0'))
    if i == n[1]-1:
      break
    if t[i+1][0] != t[i][0]:
        cnt = 1
    cnt += 1

Submission status: Wrong Answer

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

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

print(city)

out = [0]*M
cnt = 1
for i in range(len(city)):
	out[city[i][2]] = '{0:06d}{1:06d}'.format(city[i][0], cnt)
	try:
		if city[i+1][0] == city[i][0]: cnt += 1
		else: cnt = 1
	except(IndexError):
		cnt += 1

for o in out:
	print(o)

Submission status: Wrong Answer

Solution code:
import heapq

py = [ [] for _ in range(100010)]
p=[]
y=[]
n,m = map(int,input().split())
for _ in range(m):
        pp,yy = map(int,input().split())
        p.append(pp)
        y.append(yy)
        py[pp].append(yy)

for i in range(m):
        py[i].sort()

for i in range(m):
        id = py[p[i]].index(y[i]) + 1
        print("{0:06d}{1:06d}".format(p[i],id))

Submission status: Wrong Answer

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

P = [0 for i in range(M)]
Y = [0 for i in range(M)]
PM1 = [0 for i in range(M)]

for i in range(M):
    P[i], Y[i] = map(int, input().split())
    PM1[i] = P[i] * 10000000000 + Y[i]

PM2 = sorted(PM1)
print(PM2)

first = [0 for i in range(N)]
for i in range(N):
    for j in range(M):
        if PM2[j] >= (i + 1) * 10000000000:
            first[i] = j + 1
            break
print(first)

for i in range(M):
    print(str(P[i]).zfill(6) + str(PM2.index(PM1[i])
          + 1 - (first[P[i] - 1] - 1)).zfill(6))

Submission status: Wrong Answer

Solution code:
N, M = map(int, input().split())
dct = {}
for x in range(M):
    P, Y = input().split()
    dct[x] = P.zfill(6) + ' ' + Y.zfill(6)

lst = sorted(dct.items(), key=lambda x:x[1])

idx = 1
a = ''
dct2 = {}
for k, v in lst:
    p, y = v.split()
    if a != p:
        idx = 1
        a = p
    else:
        idx += 1        
    dct2[k] = p + str(idx).zfill(6)

for k, v in sorted(dct2.items()):
    print(v)

Submission status: Wrong Answer

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


PY.sort()
Ans={i:0 for i in range(M)}
counter=0

for i in range(M):
    if i==0:
        counter+=1
    elif PY[i][0]==PY[i-1][0]:
        counter+=1
    else:
        counter=1
    Ans[i]=str(PY[i][0]).zfill(6)+str(counter).zfill(6)
    
for i in range(M):
    print Ans[i]

Submission status: Wrong Answer

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

def FillZero(num,f=6):
    s = ""
    s += str((f - len(str(num))) * "0")
    s += str(num)
    return(s)

for i in range(M):
    l[i].append(i)

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

key0 = l[0][0]
key1 = 0
for i in range(M):
    if key0 == l[i][0]:
        key1 += 1
        l[i][1] = key1
    else:
        key1 = 1
        l[i][1] = key1
        key0 += 1

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

for i in range(M):
    print(FillZero(l[i][0]) + FillZero(l[i][1]))

Submission status: Wrong Answer

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

def FillZero(num,f=6):
    s = ""
    s += (f - len(str(num))) * "0"
    s += str(num)
    return(s)

for i in range(M):
    l[i].append(i)

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

key0 = l[0][0]
key1 = 0
for i in range(M):
    if key0 == l[i][0]:
        key1 += 1
        l[i][1] = key1
    else:
        key1 = 1
        l[i][1] = key1
        key0 += 1

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

for i in range(M):
    print(FillZero(l[i][0]) + FillZero(l[i][1]))

Submission status: Wrong Answer

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

def FillZero(num,f=6):
    s = ""
    s += (f - len(str(num))) * "0"
    s += str(num)
    return(s)

for i in range(M):
    l[i].append(i)

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

key0 = l[0][0]
key1 = 1
for i in range(M):
    if key0 == l[i][0]:
        l[i][1] = key1
        key1 += 1
    else:
        key1 = 1
        l[i][1] = key1
        key0 += 1

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

for i in range(M):
    print(FillZero(l[i][0]) + FillZero(l[i][1]))

Submission status: Wrong Answer

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

def FillZero(num,f=6):
    s = ""
    s += (f - len(str(num))) * "0"
    s += str(num)
    return(s)

for i in range(M):
    l[i].append(i)

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

key0 = l[0][0]
key1 = 1
for i in range(M):
    if key0 == l[i][0]:
        l[i][1] = key1
        key1 += 1
    else:
        key1 = 1
        l[i][1] = key1
        key0 += 1

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

for i in range(M):
    print(FillZero(l[i][0]) + FillZero(l[i][1]))

Submission status: Wrong Answer

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

def func(l,x):
    return [i for i,_x in enumerate(l) if _x == x]

p = []
y = []
number = []


for i in range(m):
    a,b = map(int,input().split())
    for j in func(p,a):
        if y[j] > b:
            number[j] += 1

    p.append(a)
    y.append(b)
    number.append(1)


for i in range(m):
    year=str(p[i]).zfill(6)
    num=str(number[i]).zfill(6)
    print("{0}{1}\n".format(year,num))

Submission status: Wrong Answer

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

inputs = []
sorted_inputs = {}

for _ in range(M):
    P, Y = map(int, input().split())
    inputs.append((P, Y))
    if sorted_inputs.get(P) is None:
        sorted_inputs[P] = [Y]
    else:
        sorted_inputs[P].append(Y)

for input in sorted_inputs:
    sorted_inputs[input].sort()

for input in inputs:
    first = str(input[0]).rjust(8, '0')
    latter = str(sorted_inputs[input[0]].index(input[1])+1).rjust(8, '0')
    print(first + latter)

Submission status: Wrong Answer

Solution code:
from bisect import bisect

T = list(map(int,input().split()))
N = T[0]
M = T[1]
P =list()
Y = list()
D = dict()

for x in range(0,M):
    S = list(input().split())
    P.append(S[0])
    Y.append(S[1])
    if S[0] in D:
        D[S[0]].append(S[1])
    else:
        D.setdefault(S[0],list())
        D[S[0]].append(S[1])
    D[S[0]] = sorted(D[S[0]])

for y in range(0,M):
    x = bisect(D[P[y]],Y[y])
    x = '0'*(6 - len(str(x))) + str(x)
    P[y] = '0'*(6-len(P[y])) + P[y]
    number = P[y] + x
    print(number)

Submission status: Wrong Answer

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

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

cnt = 1
prev_p = 0
for i in py:
    p, y = i[1][0], i[1][1]
    if prev_p == p:
        cnt += 1
    else:
        cnt = 1

    ans = str(p).zfill(6) + str(cnt).zfill(6)
    i.append(ans)
    prev_p = p

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

Submission status: Wrong Answer

Solution code:
#coding:utf-8


if __name__ == "__main__":
    N, M = map(int, input().split())
    city_list = []
    pref_dec = {}
    for m in range(M):
        p, y = map(int, input().split())
        city_list.append((p, y))
        if p not in pref_dec:
            pref_dec[p] = []
        pref_dec[p].append(y)

    for p in pref_dec.keys():
        pref_dec[p].sort()

    print(pref_dec)
    for m in range(M):
        p_id = city_list[m][0]
        y_id = pref_dec[p_id].index(city_list[m][1]) + 1
        print(str(p_id).zfill(6) + str(y_id).zfill(6))

Submission status: Wrong Answer

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

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

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

index=1
for i in range(M):
    if i>0:
        if city[i-1][1] != city[i][1]:
            index=1
    
    city[i][2]=index
    index+=1

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

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

Submission status: Wrong Answer

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

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

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

index=1
for i in range(len(city)):
    if i>0:
        if city[i-1][1] != city[i][1]:
            index=1
    
    city[i][2]=index
    index+=1

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

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

Submission status: Wrong Answer

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

for i in range(m):
    pm, ym = list(map(int, input().split()))
    city_list.append([i,pm,ym])

city_count = {}
city = {}

for i,p,y in sorted(city_list, key=lambda x: x[1]):
    if not p in city_count:
        city_count[p] = 1
    else:
        city_count[p] += 1
    city[i,p] = city_count[p]

for i,p,y in city_list:
    print("{:0=6}{:0=6}".format(p, city[i,p]))

Submission status: Wrong Answer

Solution code:
from operator import itemgetter
N, M = map(int, input().split())
c=[]
for i in range(M):
	c.append(input().split())
for i in range(M):
	c[i].append(i)
C = sorted(sorted(c,key=itemgetter(1)), key=itemgetter(0))
x = 1
for i in range(M):
	if i > 0  and int(C[i][0]) - int(C[i-1][0]) > 0:
		x = 1
	else:
		x += 1
	C[i].append(x)
c = sorted(C, key=itemgetter(2))
for i in range(M):
	print("{:06d}{:06d}".format(int(c[i][0]), int(c[i][3])))

Submission status: Wrong Answer

Solution code:
from operator import itemgetter
N, M = map(int, input().split())
c=[]
for i in range(M):
	c.append(input().split())
for i in range(M):
	c[i].append(i)
C = sorted(sorted(c,key=itemgetter(1)), key=itemgetter(0))
x = 0
for i in range(M):
	if i > 0  and int(C[i][0]) - int(C[i-1][0]) > 0:
		x = 1
	else:
		x += 1
	C[i].append(x)
c = sorted(C, key=itemgetter(2))
for i in range(M):
	print("{:06d}{:06d}".format(int(c[i][0]), int(c[i][3])))

Submission status: Wrong Answer

Solution code:
# coding: utf-8


def main():
    n, m = map(int, input().split())
    li1 = []
    li2 = []
    for _ in range(n+1):
        li2.append([])
    for _ in range(m):
        tmplist = list(map(int, input().split()))
        li1.append(tmplist)
        li2[tmplist[0]].append(tmplist[1])

    for i in range(n+1):
        li2[i] = sorted(li2[i])
    print(li2)

    for ken, shi in li1:
        i = li2[ken].index(shi) + 1
        print('{0:0=6}{1:0=6}'.format(ken, i))


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
from operator import itemgetter, attrgetter

N, M = list(map(int,input().strip().split()))
ar = []
ans = []
num = 0

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

ar.sort(key=itemgetter(1))

for i in ar:
    a,b,c = i
    if num != a:
        num = a
        num2 = 0
    num2 += 1
    ans.append([str(num).zfill(6)+str(num2).zfill(6),c])

ans.sort(key=itemgetter(1))

for i in range(M):
    py,c = ans[i]
    print(py)

Submission status: Wrong Answer

Solution code:
from collections import defaultdict

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

Q=[]

for i in range(M):
  P,Y=map(int,input().split())
  Q.append([P,Y,i])
  
Q = sorted(Q,key=lambda x:x[1])
Q = sorted(Q,key=lambda x:x[0])

nowP=Q[0][0]
nownum=0

for l in Q:
  s=str(l[0]).zfill(6)
  if l[0]==nowP:
    num=nownum+1
    nownum=num
  else:
    nowP=l[0]
    num=1
  s+=str(num).zfill(6)
  l.append(s)
  
Q = sorted(Q,key=lambda x:x[2])

for l in Q:
  print(l[3])

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
a = int(input().split()[1])
c = [int(input().split()[0]) for i in range(a)]
import collections
c = collections.Counter(c)
for k,v in sorted(c.items()):
    for i in range(v):
        print('{k:08}{i:08}'.format(k=k,i=i+1))

Submission status: Wrong Answer

Solution code:
from collections import defaultdict
n,m = [int(x) for x in input().split()]
l = [input().split() for _ in range(m)]
d = defaultdict(list)
for p,y in l:
    d[p].append(y)

for p,y in l:
    i = list(sorted(d[p])).index(y)
    print("%06d%06d" % (int(p), i + 1))

Submission status: Wrong Answer

Solution code:
from collections import defaultdict
n,m = [int(x) for x in input().split()]
l = [input().split() for _ in range(m)]
d = defaultdict(list)
for p,y in l:
    d[p].append(y)
print(d)
for p,y in l:
    i = list(sorted(d[p])).index(y)
    print("%06d%06d" % (int(p), i + 1))