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
import collections
import itertools
import math
import re
from collections import Counter
from collections import deque
import bisect


MOD = 10 ** 9 + 7

N, M = [int(x) for x in input().split()]


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


PYlist = [None] * M
for i in range(M):
    P, Y = [int(x) for x in input().split()]
    P = P - 1
    PYlist[i] = (P, Y)
    KenList[P].append((i, Y))


# for i in range(N):
    # KenList[i] = sorted(KenList[i], key=lambda x: x[1])

for i in range(M):
    ken = PYlist[i][0]
    idx = 0
    kl = KenList[ken]
    for j in range(len(kl)):
        if kl[j][0] == i:
            idx = j
            break
    print("{0:06d}{1:06d}".format(ken+1, idx+1))


sys.exit(0)

Submission status: Wrong Answer

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



bef=0
state=0
retstr=''
triple=[]
for i in lists:
    if(i[0]!=bef):
        bef=i[0]
        state=1
        triple.append([i[0],i[1],str(i[0]).rjust(6,'0')+str(state).rjust(6,'0')])
    else:
        state+=1
        triple.append([i[0],i[1],str(i[0]).rjust(6,'0')+str(state).rjust(6,'0')])

for i in back:
    for s in triple:
        if(i[0]==s[0] and i[1]==s[1]):
            print(s[2])
            break

Submission status: Wrong Answer

Solution code:
n,m=map(int,input().split())
p=[[] for i in range(n)]
y=[]
nl=[]
for i in range(m):
    t1,t2=map(int,input().split())
    p[t1-1].append(t2)
for i in range(n):
    tl=sorted(p[i])
    for j in p[i]:
        u=str(i+1)
        w=tl.index(j)
        d=str(w+1)
        while len(u)<6:
            u="0"+u
        while len(d)<6:
            d="0"+d
        t=u+d
        nl.append(t)
for i in range(m):
    print(nl[i])

Submission status: Wrong Answer

Solution code:
import math
from functools import reduce
import collections
import itertools
a = list(map(int,input().split()))
n = a[0]
m = a[1]
li = [list(map(int,input().split())) for i in range(m)]
w0 = dict()
results = {}
for i in li:
    results.setdefault(i[0], []).append(i[1])
print(results)
for i in li:
    #print(results[i[0]])
    years = sorted(results[i[0]])
    co = 0
    for j in years:
        co += 1
        if j == i[1]:
            print("{0:06d}".format(i[0]) + "{0:06d}".format(co))

Submission status: Wrong Answer

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

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

sorted_Y=sorted(Y)

P_table=[[]]*N

for i in range(M):
	P_table[P[Y.index(sorted_Y[i])]-1].append(i)

answer=[0]*M
for i in range(N):
	i_pad="%06d" % (i+1)
	for j in range(len(P_table[i])):
		j_pad="%06d" % (j+1)
		answer[P_table[i][j]]=i_pad+j_pad

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

Submission status: Wrong Answer

Solution code:
n, m = map(int, input().split())
data = [0] * m
res = [0] * m
for i in range(m):
    d = list(map(int, input().split()))
    d.append(i)
    data[i] = tuple(d)
data.sort()
city_num = data[0][0]
birth_num = 1
print(data)
for item in data:
    # print(item, city_num)
    if item[0] != city_num:
        city_num = item[0]
        birth_num = 1
    res[item[2]] = '{:06d}{:06d}'.format(item[0], birth_num)
    birth_num += 1
for item in res:
    print(item)

Submission status: Wrong Answer

Solution code:
import numpy as np
N,M = [int(x) for x in input().strip('\n').split(' ')]
lis = np.zeros((M,3)).astype('int32')
for i in range(M):
    p,y = [int(x) for x in input().strip('\n').split(' ')]
    lis[i,0] = p
    lis[i,1] = y
for i in range(N+1):
    lis[lis[:,0]==i,2] = (lis[lis[:,0]==i,1].argsort()+1)
for i in range(M):
    print('%06d%06d' % (lis[i,0],lis[i,2]))

Submission status: Wrong Answer

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

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

P = []
Y = []
PY = []
dic = {}
for i in range(M):
    p,y = map(int,input().split())
    P.append(p)
    Y.append(y)

    dic[y] = ''

    PY.append((p,y))

PY = sorted(PY)
P  = sorted(P)
lenP = len(P)
for i in range(1,N+1):

    t_list = []
    righ = bisect.bisect_right(P,i,0,lenP)
    left = bisect.bisect_left(P,i,0,lenP)

    # print(i,P)
    # print(left,righ)

    if left != righ:
        for j in range(left,righ):
            t_list.append(PY[j][1])
        t_list = sorted(t_list)
#        print('t_list',t_list)
        for k in range(righ - left):
#            print('i k',i, k)
            y = t_list[k]
            dic[y] = str(i).zfill(6) + str(k+1).zfill(6)

for ans in dic.values():
    print(ans)

Submission status: Wrong Answer

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

cl = list(set(p))
cp = [p.count(cl[i]) for i in range(len(cl))]

print(cl)
print(cp)

for i in range(len(cl)):
    for j in range(1,cp[i]+1):
        print('{0:06d}'.format(cl[i])+'{0:06d}'.format(j))

Submission status: Wrong Answer

Solution code:
from sys import stdin, exit
from queue import PriorityQueue

PREFEC, CITIES = list(map(int, stdin.readline().split()))
pref = {str(key): PriorityQueue() for key in range(1, PREFEC+1)}
city = dict()
out = [0] * CITIES
for i in range(CITIES):
    p, c = stdin.readline().split()
    pref[p].put(c)
    dic = p + '0' + c
    city[dic] = i

for j in range(1, PREFEC+1):
    i = str(j)
    pref_index = 1
    while not pref[i].empty():
        si = pref[i].get()
        temp = i + '0' + si
        index = city[temp]
        sy = str(pref_index)
        p = i

        while len(p) != 6:
            p = '0' + p
        while len(sy) != 6:
            sy = '0' + sy

        out[index] = p + sy

        pref_index += 1

for o in out:
    print(o)
exit()

Submission status: Wrong Answer

Solution code:
 # -*- coding: utf-8 -*-
"""
Created on Sun Nov  4 18:54:20 2018
ABC113C
@author: maezawa
"""

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

#print(p)
#print(y)
    
cityn = ['']*m

ps = [[] for _ in range(n+1)]
for i in range(1,m+1):
    ps[p[i]].append(i)
    
for j in range(1,n+1):
    ps[j].sort(key = lambda x: y[x])
    for i, k in enumerate(ps[j]):
        left = '000000'+ str(j)
        right = '000000' + str(i+1)
        cityn[k-1] = left[len(left)-5:] + right[len(right)-5:]

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

Submission status: Wrong Answer

Solution code:
import numpy as np
N, M = map(int, input().split())
p_dict = {}
p = [0 for i in range(M)]
y = [0 for i in range(M)]
i_in_p = [0 for i in range(M)]

for i in range(M):
    pi, yi = map(int, input().split())
    p[i] = pi
    if pi not in p_dict:
        i_in_p[i] = 0
        p_dict[pi] = [yi]
        continue
    i_in_p[i] = len(p_dict[pi])
    p_dict[pi].append(yi)

for key in p_dict.keys():
    p_dict[key] = np.array(p_dict[key]).argsort()

for i in range(M):
    print('{:06d}{:06d}'.format(p[i], p_dict[p[i]][i_in_p[i]]+1))

Submission status: Wrong Answer

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

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

pp = []
for o in range(N):
    pp.append([])

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

spp = []
index = 0
for _ in range(N):
    spp.append(sorted(pp[index]))
#    spp.append((pp[o-1]))
    index = index + 1

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

Submission status: Wrong Answer

Solution code:
import numpy as np

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

city_dict = {}
for i in range(n):
    city_dict[i + 1] = []

ps = []
ys = []
cities = []
for i in range(m):
    p, y = map(int, input().split())
    city_dict[p].append(y)
    cities.append([p, y])

for city in cities:
    print('{0:06d}{1:06d}'.format(city[0], np.argsort(city_dict[city[0]])[city_dict[city[0]].index(city[1])] + 1))

Submission status: Wrong Answer

Solution code:
N, M =map(int, input().split())
Ps =[]
Ys =[]
dic = {}
for i in range(M):
    p, y = map(int, input().split())
    Ps.append(p)
    Ys.append(y)
    ls = dic.get(p, [])
    ls.append(y)
    dic[p] = ls
for P in Ps:
    dic[p].sort()
for i in range(M):
    p = Ps[i]
    y = Ys[i]
    number = dic[p].index(y) + 1
    strp = str(p)
    strn = str(number)
    print(strp.zfill(6) + strn.zfill(6))

Submission status: Wrong Answer

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

ps = sorted(ps)
ps

ans = []
count = 1
for i in range(m):
    if (i != 0 and (ps[i])[0] != (ps[i-1])[0]):
        count = 1
    else:
        pass
    ans.append([(ps[i])[2], 100000*((ps[i])[0]) + count])
    count += 1

ans = sorted(ans)

for i in ans:
    aw = i[1]
    aww = str(aw).zfill(12)
    print(aww)

Submission status: Wrong Answer

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



bef=0
state=0
retstr=''
triple=[]
for i in lists:
    if(i[0]!=bef):
        bef=i[0]
        state=1
        triple.append([i[0],i[1],str(i[0]).rjust(6,'0')+str(state).rjust(6,'0')])
    else:
        state+=1
        triple.append([i[0],i[1],str(i[0]).rjust(6,'0')+str(state).rjust(6,'0')])

for i in back:
    for s in triple:
        if(i[0]==s[0] and i[1]==s[1]):
            print(s[2])

Submission status: Wrong Answer

Solution code:
N,M=map(int, input().split())
lis=[]
for i in range(M):
    lis.append(list(map(int,input().split())))
l_2=sorted(lis, key=lambda x: x[1])
dic={}
for i,j in l_2:
    dic[i]=dic.get(i,0)+1
    res='{:0=6}{:0=6}'.format(i,dic[i])
    lis[lis.index([i,j])]=res
print(lis)

Submission status: Wrong Answer

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

py = []

for i in range(m):
    py.append(list(map(int, input().split())))

mapa ={}

for i in range(m):
    if py[i][0] in mapa:
        mapa[py[i][0]][py[i][1]] = i
    else:
        mapa[py[i][0]] = {py[i][1]:i}

ans = ['' for _ in range(m)]

for i in mapa:
    pri = mapa[i]
    pri = sorted(pri.items())
    print(pri)
    for j in range(len(pri)):
        ans[pri[j][1]] = ('000000' + str(i))[-6:] + ('000000' + str(j + 1))[-6:]
for i in ans:
    print(i)

Submission status: Wrong Answer

Solution code:
n,m = input().split()
plist = []
ylist = []
n = int(n)
m = int(m)
anslist = [0 for i in range(m)]
list = [[] for i in range(n+1)]
for i in range(m):
    p,y = input().split()
    p = int(p)
    y = int(y)
    plist.append(p)
    ylist.append(y)
for i in range(m):
    for j in range(n+1):
        if plist[i] == j + 1:
            list[j].append([ylist[i],i])
for i in range(n):
    list[i].sort()
for i in range(n):
    for j in range(len(list[i])):
        mtem = list[i][j][1]
        ans1 = str(plist[mtem])
        while len(ans1) <= 6:
            ans1 = "0" + ans1
        ans2 = str(j+1)
        while len(ans2) <= 6:
            ans2 = "0" + ans2
        anslist[mtem] = ans1 + ans2
for i in range(m):
    print(anslist[i])

Submission status: Wrong Answer

Solution code:
a,b = map(int,input().split())

da = [[] for i in range(a)]
d = []
j = [0 for i in range(a)]
for i in range(b):
    k,kk = map(int,input().split())
    da[k-1].append(kk)
    d.append([k, kk])
    j[k-1] += 1

for i in range(a):
    da[i].sort()
    j[i] = str(j[i])
    j[i] = len(j[i])
for i in range(b):
    p = da[d[i][0]-1].index(d[i][1])

    n = str(d[i][0])
    m = str(p+1)

    n = "0"*(6-j[d[i][0]-1]) + n
    m = "0"*(6-len(m)) + m

    print(n+m)

Submission status: Wrong Answer

Solution code:
n,m=map(int,input().split())
lp=[[] for i in range(n)]
ln={}
for i in range(m):
  p,y=map(int,input().split())
  lp[p-1].append(y)
  ln[i]=p*n+y

lcode={}
for i in range(n):
  p = i+1
  lp[i]=sorted(lp[i])
  for j in range(len(lp[i])):
    lcode[p*n+lp[i][j]]=format(p,'06d')+format(j+1,'06d')

for i in range(m):
  print(lcode[ln[i]])

Submission status: Wrong Answer

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

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

pp = []
for o in range(N):
    pp.append([])

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

spp = []
index = 0
for _ in range(N):
    spp.append(sorted(pp[index]))
#    spp.append((pp[o-1]))
    index = index + 1

print(clist)
print(spp)

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

Submission status: Wrong Answer

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

P = [0]*N

for x in range(M):
	p, y = list(map(int, input().split()))
	P[p-1] += 1

ans = []
for i, x in enumerate(P):
	for j in range(x):
		ans.append(str('{0:06d}'.format(i+1))+str('{0:06d}'.format(j+1)))

ans = sorted(ans)
for a in ans:
	print(a)

Submission status: Wrong Answer

Solution code:
import heapq
N, M = map(int, input().split())
P = [0 for i in range(M)]
Y = [0 for i in range(M)]
country = [[] for i in range(N+1)]
for i in range(M):
    P[i], Y[i] = map(int, input().split())
    heapq.heappush(country[P[i]], Y[i])

for i in range(M):
    cnt = list(country[P[i]])
    num = cnt.index(Y[i]) + 1
    line = str(P[i]).zfill(6) + str(num).zfill(6)
    print(line)

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())
Yx = Y  
Y.sort()
count = [1]*(N+1)
ans = [0]*M
for i in range(M):
    j = Yx.index(Y[i])
    ans[j] = str(P[j]).zfill(6) + str(count[P[j]]).zfill(6)
    count[P[j]] = count[P[j]] +1

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

Submission status: Wrong Answer

Solution code:
import numpy as np
N,M = map(int,input().split())
py = np.zeros(M*4).reshape(M,4)
for i in range(M):
    py[i][0] = i
    py[i][1],py[i][2] = map(int,input().split())

# for x in np.unique(py[:,1]):
#     py[py[:,1] == x][3] = py[py[:,1] == x][2]
for i in range(M):
    py[i][3] = np.where(np.sort(py[py[:,1] == py[i][1]][:,2]) == py[i][2])[0]+1
    print("0"*(6-(py[i][1]//10+1))+str(int(py[i][1]))+"0"*(6-(py[i][3]//10+1))+str(int(py[i][3])))

Submission status: Wrong Answer

Solution code:
N, M = (int(i) for i in input().split(' '))
py=[]
p =[]

for i in range(M):
    p = [i]
    p.extend([int(j) for j in input().split(' ')])
    py.append(p)

Npy = []
for i in range(1,N+1):
    # 県i
    pyi = [j for j in py if j[1] == i] #県iのリスト
    pyi.sort(key=lambda x: x[2]) # 市の生まれた年でソート
    l = len(pyi)
    cnt = 0
    for k in range(1,l+1):
        pyi[k-1][2] = k
    Npy.extend(pyi)

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

for t in Npy:
    print('{0:0>6}{1:0>6}'.format(t[1],t[2]))

Submission status: Wrong Answer

Solution code:
n, m = map(int, input().split())
data = [0] * m
res = [0] * m
for i in range(m):
    d = list(map(int, input().split()))
    d.append(i)
    data[i] = tuple(d)
data.sort()
city_num = data[0][0]
birth_num = 1
for item in data:
    if item[0] != city_num:
        birth_num = 1
    res[item[2]] = '{:06d}{:06d}'.format(item[0], birth_num)
    birth_num += 1
for item in res:
    print(item)

Submission status: Wrong Answer

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

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

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

nowp = 1
index = 1
for city in city_list:
	if city[1] == nowp:
		city[3] = index
		index += 1
	else:
		nowp += 1
		index = 1
		city[3] = index
		index += 1


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

for city in city_list:
	kami_str = '0' * (6 - len(str(city[1]))) + str(city[1])
	shimo_str = '0' * (6 - len(str(city[3]))) + str(city[3])
	answer = kami_str + shimo_str
	print(answer)

Submission status: Wrong Answer

Solution code:
import numpy as np
# your code goes here
def main():
	buf = input().split()
	n = int(buf[0])
	m = int(buf[1])
	
	py = np.zeros((m, 4), dtype="int")#num, p, year, num in p
	for i in range(m):
		py[i][0] = i+1#################
		buf = input().split()
		py[i][1] = int(buf[0])
		py[i][2] = int(buf[1])
		
	py = np.array(sorted(py, key=lambda x:(x[1],x[2])))
	bufp = 0
	for i in range(m):
		if(py[i][1] != bufp):
			bufp = py[i][1]
			py[i][3] = 1#1-origin
		else:
			py[i][3] = py[i-1][3]+1
	#py = np.sort(py, axis=0)
	py = py[np.argsort(py[:, 0])]
	
	print(py)
	for i in range(m):
		ans = "{0:06d}".format(py[i][1])+"{0:06d}".format(py[i][3])
		print(ans)
	
main()

Submission status: Wrong Answer

Solution code:
import numpy as np
N, M = [int(a) for a in input().split()]
P = []
Y = []

for _ in range(M):
    p, y =  [int(a) for a in input().split()]
    P.append(p)
    Y.append(y)

index = {}
id = ["" for _ in range(len(P))]

for i in np.argsort(Y):
    index[P[i]] = index.get(P[i], 0)
    id[i] = "{0:06d}".format(P[i])+"{0:06d}".format(index[P[i]])
    index[P[i]] += 1

for i in id:
    print(i)

Submission status: Wrong Answer

Solution code:
import heapq
N, M = map(int, input().split())
P = [0 for i in range(M)]
Y = [0 for i in range(M)]
country = [[] for i in range(N+1)]
for i in range(M):
    P[i], Y[i] = map(int, input().split())
    heapq.heappush(country[P[i]], Y[i])

for i in range(N+1):
    country[i] = list(country[i])
    #print(country[i])

for i in range(M):
    num = country[P[i]].index(Y[i]) + 1
    line = str(P[i]).zfill(6) + str(num).zfill(6)
    print(line)

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())))
    data[m].append(m)
data.sort(key=lambda x:x[1])

pref=0
for m in range(M):
    if data[m][0]!=pref:
        count=1
    ID=('000000'+str(data[m][0]))[-6:]+('000000'+str(count))[-6:]
    data[m].append(ID)

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

for m in range(M):
    print(data[m][3])

Submission status: Wrong Answer

Solution code:
import numpy as np
N, M = map(int, input().split())
p_dict = {}
p = [0 for i in range(M)]
y = [0 for i in range(M)]
i_in_p = [0 for i in range(M)]

for i in range(M):
    pi, yi = map(int, input().split())
    p[i], y[i] = pi, yi
    i_in_p[i] = len(p_dict)
    if pi not in p_dict:
        i_in_p[i] = 0
        p_dict[pi] = [yi]
        continue
    i_in_p[i] = len(p_dict[pi])
    p_dict[pi].append(yi)

for key in p_dict.keys():
    p_dict[key] = np.array(p_dict[key]).argsort() + 1

for i in range(M):
    print('{:06d}{:06d}'.format(p[i], p_dict[p[i]][i_in_p[i]]))

Submission status: Wrong Answer

Solution code:
import numpy as np

n, m = map(int, input().split())
py = [list(map(int, input().split())) for _ in range(m)]
p = [[] for _ in range(n)]
for _p, _y in py:
    p[_p - 1].append(_y)
# print(time.time() - start)
for i in range(n):
    p[i] = np.argsort(np.asarray(p[i]))

# print(time.time() - start)
counter = [0 for _ in range(n)]
for _p, _y in py:
    # print("{:06}{:06}".format(_p, p[_p - 1].index(_y) + 1))
    # t = "{:06}{:06}".format(_p, p[_p - 1].index(_y) + 1)
    # print(counter[_y])
    t = "{:06}{:06}".format(_p, p[_p - 1][counter[_p-1]] + 1)
    print(t)
    counter[_p - 1] += 1

Submission status: Wrong Answer

Solution code:
from operator import itemgetter

def main():
    N,M = list(map(int, input().split()))
    lst = []
    anslst = []
    for i in range(M):
        P,Y = list(map(int, input().split()))
        lst.append({'city_id':i, 'pref':P, 'year':Y})
    print(lst)
    for i in range(N):
        tmp = [ d for d in lst if d['pref'] == i+1]
        print(tmp)
        sor = sorted(tmp, key = itemgetter('year'))
        for j in range(len(sor)):
            city_id = sor[j]['city_id']
            pref = sor[j]['pref']
            year = sor[j]['year']
            id = '{0:06d}'.format(pref) + '{0:06d}'.format(j+1)
            anslst.append({'city_id':city_id, 'pref':pref, 'year':year, 'id':id})
    anslst = sorted(anslst, key = itemgetter('city_id'))
    print(anslst)
    for i in range(len(anslst)):
        print(anslst[i]['id'])

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
N,M=map(int,input().split())
list1=[[]for i in range(N)]
list2=[]
for i in range(M):
    P,Y=map(int,input().split())
    list1[P-1].append(Y)
    list2.append([P,Y])
#print(list1)
for j in range(N):
    list1[j].sort()
#print(list1)
for k in range(M):
    ansP="0"*(6-len(str(list2[k][0])))+str(list2[k][0])
    ansY="0"*(6-len(str(list1[list2[k][0]-1].index(list2[k][1]))))+str(list1[list2[k][0]-1].index(list2[k][1])+1)
    ans=ansP+ansY
    print(ans)

Submission status: Wrong Answer

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

py = []

for i in range(m):
    py.append(input().split())

mapa ={}

for i in range(m):
    if py[i][0] in mapa:
        mapa[py[i][0]][py[i][1]] = i
    else:
        mapa[py[i][0]] = {py[i][1]:i}

ans = ['' for _ in range(m)]

for i in mapa:
    pri = mapa[i]
    pri = sorted(pri.items())
    for j in range(len(pri)):
        ans[pri[j][1]] = ('000000' + i)[-6:] + ('000000' + str(j + 1))[-6:]
for i in ans:
    print(i)

Submission status: Wrong Answer

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

#ans = []
tmp = shi_sorted[0][0] #県の番号
count = 0#市の番号
for i in range(M):
  count += 1
  if tmp != shi_sorted[i][0]:
    count = 1
    tmp = shi_sorted[i][0]
#  ans.append( ("%06d"%tmp) + ("%06d"%count))
  print( ("%06d"%tmp) + ("%06d"%count))

#print(ans)

Submission status: Wrong Answer

Solution code:
nm = input().split(' ')
n = int(nm[0])
m = int(nm[1])

N = [0 for i in range(n)]
for i in range(m):
  c = input().split(' ')
  ID = '0'*(6 - int(len(c[0]))) + c[0]
  N[int(c[0])-1] += 1
  ID += '0'*(6 - int(len(str(N[int(c[0])-1])))) + str(N[int(c[0])-1])
  print(ID)

Submission status: Wrong Answer

Solution code:
N,M=map(int,input().split())
F=[False]*(N+1)
PY=[]

for _ in range(M):
    p,y=map(int,input().split())
    PY.append([p,y])
    if F[p]==False: F[p]=[y]
    else: F[p].append(y)
    
for i in range(1,N+1):
    if F[i]!=False:
        F[i].sort()
        
for i in range(M):
    PY[i][1]=F[PY[i][0]].index(PY[i][1])+1

for p,y in PY:
    print('{0:06d}{0:06d}'.format(p,y))

Submission status: Wrong Answer

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

py = []

for i in range(m):
    py.append(input().split())

mapa ={}

for i in range(m):
    if py[i][0] in mapa:
        mapa[py[i][0]][py[i][1]] = i
    else:
        mapa[py[i][0]] = {py[i][1]:i}

ans = ['' for _ in range(m)]

for i in mapa:
    pri = mapa[i]
    pri = sorted(pri.items())
    for j in range(len(pri)):
        ans[pri[j][1]] = ('00000' + i)[-5:] + ('00000' + str(j + 1))[-5:]
for i in ans:
    print(i)

Submission status: Wrong Answer

Solution code:
n,m=map(int,input().split())
p=[]
for i in range(m):
    a,b=map(int,input().split())
    p.append([i,a,b,0])
ps=sorted(p,key=lambda i:(i[1],i[2]))
cnt=1
print(ps)
for i in range(m):
    if i!=0:
        if ps[i][1]==ps[i-1][1]:
            print("aaa")
            cnt+=1
            ps[i][3]=cnt
        else:
            ps[i][3]=1
            cnt=1
    else:
        ps[i][3]=1
ps=sorted(ps,key=lambda i:i[0])
print(ps)
for i in range(m):
    print("{0:06d}".format(ps[i][1]),end='')#文末の改行取り消し
    print("{0:06d}".format(ps[i][3]))

Submission status: Wrong Answer

Solution code:
import sys,collections,math;sys.setrecursionlimit(10**7)
from operator import itemgetter;
def Is(): return [int(x) for x in sys.stdin.readline().split()]
def Ss(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def S(): return input()

N,M = Is()
lis = []
for i in range(M):
    lis.append([i]+Is())
t = sorted(lis,key=itemgetter(1,2))
x,p = 0,1
for i in range(M):
    if p == t[i][1]:
        x += 1
        t[i] += [p,x]
    else:
        p = t[i][1]
        x = 1
        t[i] += [p,x]
t = sorted(t,key=itemgetter(0))
for e in t:
    print( (6-len(str(e[3])))*"0" + str(e[3]) + (6-len(str(e[3])))*"0" + str(e[4]))

Submission status: Wrong Answer

Solution code:
#coding:utf-8
import numpy as np
N,M = list(map(int,input().split()))
P = []
Y = []
for m in range(M):
    p,y = list(map(int,input().split()))
    P.append(p)
    Y.append(y)
#print (P,Y)
ls = [ [] for _ in range(max(P))]
#print (ls)
for p,y in zip(P,Y):
    ls[p-1].append(y)
ls_dict = []
for line in ls:
    arg_line = np.argsort(line)+1
    temp_dict = dict(zip(line, arg_line))
    ls_dict.append(temp_dict)
#print (ls_dict)
for p,y in zip(P,Y):
    print (str(p).zfill(6)+str(ls_dict[p-1][y]).zfill(6))

Submission status: Wrong Answer

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

prefectureOrdering = [1] * (10 ** 5 + 1)
inputOrdering = [False] * (10 ** 5 + 1)

years.sort()

print(years)
for i in years:
    s = ""
    s += "0" * (6 - len(str(i[0]))) + str(i[0]) + "0" * (6 - len(str(prefectureOrdering[i[0]]))) + str(prefectureOrdering[i[0]])
    prefectureOrdering[i[0]] += 1
    inputOrdering[i[2]] = s

for i in range(1,M+1):
    print(inputOrdering[i])

Submission status: Wrong Answer

Solution code:
import heapq
N, M = map(int, input().split())
P = [0 for i in range(M)]
Y = [0 for i in range(M)]
country = [[] for i in range(N+1)]
for i in range(M):
    P[i], Y[i] = map(int, input().split())
    heapq.heappush(country[P[i]], Y[i])

for i in range(M):
    num = country[P[i]].index(Y[i]) + 1
    line = str(P[i]).zfill(6) + str(num).zfill(6)
    print(line)

Submission status: Wrong Answer

Solution code:
from scipy.stats import rankdata
N, M = [int(_) for _ in input().split()]
P = [M for _ in range(M)]
PY = [[100000000 for _ in range(M)] for _ in range(N)]
for i in range(M):
    p, y = [int(_) - 1 for _ in input().split()]
    P[i] = p
    PY[p][i] = y
PY2 = [[M for _ in range(M)] for _ in range(N)]
for i in range(N):
    PY2[i] = [int(_) for _ in rankdata(PY[i])]
print(P)
print(PY)
print(PY2)
for i in range(M):
    print(str(P[i] + 1).zfill(6) + str(PY2[P[i]][i]).zfill(6))

Submission status: Wrong Answer

Solution code:
n,m=map(int,input().split())
p=[[] for i in range(n)]
y=[]
nl=[]
for i in range(m):
    t1,t2=map(int,input().split())
    p[t1-1].append(t2)
for i in range(n):
    for j in range(len(p[i])):
        u=str(i+1)
        d=str(j+1)
        while len(u)<6:
            u="0"+u
        while len(d)<6:
            d="0"+d
        t=u+d
        nl.append(t)
for i in range(m):
    print(nl[i])

Submission status: Wrong Answer

Solution code:
from bisect import bisect_left

n, m = map(int, input().split())
qs = [list(map(int, input().split())) for _ in range(m)]
pys = [[] for _ in range(n)]
for q in qs:
    p, y = q
    p -= 1
    pys[p].append(y)

for i in range(n):
    pys[p] = sorted(pys[p])

for q in qs:
    p, y = q
    p -= 1
    number = bisect_left(pys[p], y) + 1

    print(str(p + 1).zfill(6) + str(number).zfill(6))

Submission status: Wrong Answer

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

number_dict = {}

for m in range(M):
    P, Y = map(int, raw_input().split())
    if P in number_dict:
        number_dict[P] += 1
    else:
        number_dict[P] = 1

number_list = list(number_dict.items())
number_list.sort(key=lambda x: x[0])

for p in number_list:
    prefix = p[0]
    for i in range(0, p[1]):
        print ('%06d' % prefix) + ('%06d' % (i+1))

Submission status: Wrong Answer

Solution code:
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)

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

for i in range(M):
    A[P[i]-1].append([i, Y[i]])
    
for i in range(N):
    A[i] = sorted(A[i], key=lambda x:x[1])

R = [[] for i in range(M)]

cc = 0
for i in range(N):
    c = 1
    for j in A[i]:
        R[cc] = str(10**12 + (i+1) * (10**6) + c)[1:]
        c += 1
        cc += 1
for r in R:
    print(r)

Submission status: Wrong Answer

Solution code:
n, m = map(int, input().split())
pli = [1 for x in range(n)]
for i in range(m):
    p, y = input().split()
    P = "0" * (6 - int(p)) + p
    Y =  "0" * (6 - len(str(pli[(int(p) - 1)]))) + str(pli[(int(p) - 1)])
    print(P + Y)
    pli[(int(p) - 1)] += 1

Submission status: Wrong Answer

Solution code:
#C - ID
import numpy as np

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

pref_dic = {}
for i in range(N):
    pref_dic[i+1] = []
for e,index in zip(py, range(M)):
    pref = e[0]
    year = e[1]
    
    pref_dic[pref].append((index, year))
        
city_num_dic = {}
for pref in pref_dic.keys():
    pref_string = str(pref)
    if len(pref_string) < 6:
        while len(pref_string) < 6:
            pref_string = "0" + pref_string
    
    in_year_list = np.array(pref_dic[pref])
    if len(in_year_list) == 0:
        continue
    
    year_ =  in_year_list[:, 1]
    city_ = in_year_list[:, 0]
    
    hayaijun_ind = np.argsort(year_)
    for index, i in zip(hayaijun_ind, range(len(hayaijun_ind))):
        city_name = city_[index]
        num = str(i+1)
        if len(num) < 7:
            while len(num) < 7:
                num = "0" + num
        city_num_dic[city_name] = pref_string + num


for city in np.sort(list(city_num_dic.keys())):
    print(city_num_dic[city])

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
from collections import defaultdict


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

p, y = [], []
dic = {}
for _ in range(m):
    pi, yi = map(int, input().split())
    dic[yi] = pi

d = defaultdict(int)

for _, pi in sorted(dic.items()):
    d[pi] += 1
    print('{:0>6}{:0>6}'.format(pi, d[pi]))