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:
from numpy import array
n,m = map(int,input().split())
py = []
for i in range(m):
    py.append(list(map(int,input().split())))
py = array(py)
y = py[:,1]
py.sort()
py2 = list(py[:,1])
check = 0
nums = []
an = 0
for i in range(m):
    if check != py[i][0]:
        an = 1
        check = py[i][0]
        nums.append(an)
    else:
        an += 1
        nums.append(an)
for i in y:
    a = py2.index(i)
    b = nums[a]
    c = py[a][0]
    print('{:0=6}'.format(c),end = '')
    print('{:0=6}'.format(b))

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()

for p in range(1,n+1):
    cnt = 1
    for x in xs:
        if x[0] == p:
            x[3] = cnt
            cnt += 1
        else:
            p += 1


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:
n,m=map(int,input().split())
py=[]
ken=[]
number=[]
for i in range(m):
    py.append(list(map(int,input().split())))
for j in range(n):
    ken.append([])
    number.append([])
for k in py:
    ken[k[0]-1].append(k[1])
for l in ken:
    for q in range(len(l)):
        number[ken.index(l)-1].append(q+1)
for r in number:
    for s in range(len(r)):
        r[s]=str(r[s])
        while len(r[s])<6:
            r[s]='0'+r[s]
number1=[t+1 for t in range(n)]
for u in range(n):
    number1[u]=str(number1[u])
    while len(number1[u])<6:
        number1[u]='0'+number1[u]
for v in range(n):
    for w in number[v]:
        print(number1[v]+w)

Submission status: Wrong Answer

Solution code:
import math

def gcd(a,b):
    """Compute the greatest common divisor of a and b"""
    while b > 0:
        a, b = b, a % b
    return a

def lcm(a, b):
    """Compute the lowest common multiple of a and b"""
    return a * b / gcd(a, b)


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

ans = []

Ps = {}

for i in range(M):
	P,Y = list(map(int, input().split(' ')))

	if P in Ps:
		last = True
		jb = 1
		tp = 0
		for j  in range (len(Ps[P])):
			if Y < Ps[P][j][0]:
				Ps[P].insert(j, [Y, i])
				ans.append([P,jb])
				last = False
				tp = j
				continue
			else:
				jb += 1
				

		if last:
			Ps[P].append([Y, i])
			ans.append([P,jb])
		else:
			for k in range(tp+1,len(Ps[P])):
				ans[Ps[P][k][1]][1] += 1

	else:
		Ps[P] = [[Y,i]]
		ans.append([P,1])


# {1: [[12, 2], [32, 0]], 2: [[63, 1]]}
print(Ps)

for elem in ans:
	print(str(elem[0]).zfill(6)+str(elem[1]).zfill(6))

Submission status: Wrong Answer

Solution code:
n,m=map(int,input().split())
p=[[0 for i in range(1)] for j in range(100005)]
x=[0]*m;y=[0]*m
for i in range(m):
    x[i],y[i]=map(int,input().split())
    p[x[i]].append(y[i])
for i in range(1,n+1):
    p[i].sort()
for i in range(1,n+1):
    for j in range(1,len(p[i])):
        print('%06d'%i,end="")
        print('%06d'%(j))

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)
        d=str(tl.index(j)+1)
        u="0"*(6-len(u))+u
        d="0"*(6-len(d))+d
        print(u+d)

Submission status: Wrong Answer

Solution code:
def year(x):
    return Y[x]

N, M = [int(s) for s in input().rstrip().split()]
P = []
Y = []
for m in range(M):
    input_line = [int(s) for s in input().rstrip().split()]
    P.append(input_line[0])
    Y.append(input_line[1])

pref = [[] for _ in range(N)]
for m in range(M):
    pref[P[m]-1].append(m)

for n in range(N):
    if pref[n]:
        pref[n].sort(key = year)
    
id = []
for m in range(M):
    str1 = '{0:06d}'.format(P[m])
    for i in range(len(pref[P[m]-1])):
        if i == m:
            str2 = '{0:06d}'.format(i+1)
    id.append(str1 + str2)

for m in range(M):
    print(id[m])

Submission status: Wrong Answer

Solution code:

import collections
import scipy.misc
import sys
import numpy as np
import math
from operator import itemgetter

def prime_decomposition(n):
  i = 2
  table = []
  while i * i <= n:
    while n % i == 0:
      n /= i
      table.append(int(i))
    i += 1
  if n > 1:
    table.append(int(n))
  return table   

"""
N, X = map(int, input().split())

x = [0]*N
x[:] = map(int, input().split())
"""


N, M = map(int, input().split())
P = [0]*M
Y = [0]*M
for m in range(M):
    P[m], Y[m] = map(int, input().split())
city_list = [[0, 0, 0, 0, 0]]*M
for m in range(M):
    city_list[m] = [P[m], Y[m], 0, 0, m]
city_list.sort()
i = 1
city_id = [0]*M
cnt = 1
for m in range(M):
    if city_list[m][0] == i:
        city_id[m] = cnt
        cnt += 1
    else:
        i += 1
        cnt = 1
        city_id[m] = cnt
        cnt += 1
    city_list[m][2] = city_id[m]
    city_list[m][3] = int(math.log10(city_list[m][0]) + 1)    
    
city_list.sort(key=itemgetter(4), reverse=False)
ID = ["000000000000"]*M
for m in range(M):
    tmpID = 10**6*city_list[m][0]+city_list[m][2]
    ID[m] = "0"*(6-city_list[m][3])  + str(tmpID)

print(ID)

Submission status: Wrong Answer

Solution code:
import numpy as np
N, M = [int(_) for _ in input().split()]
PN = [[] for _ in range(M)]
Y = [[] for _ in range(N)]
P = [0 for _ in range(N)]
for i in range(M):
    p, y = [int(_) - 1 for _ in input().split()]
    PN[i] = [p, P[p]]
    Y[p].append(y)
    P[p] += 1
Y_rank = [np.argsort(_) for _ in Y]
print(PN)
print(Y)
print(Y_rank)
for i in range(M):
    print(str(PN[i][0] + 1).zfill(6) + str(Y_rank[PN[i][0]][PN[i][1]] + 1).zfill(6))

Submission status: Wrong Answer

Solution code:
N, M = map(int, raw_input().split())
D = []
SD = {}
for i in range(M):
	p, y = map(int, raw_input().split())
	D.append([p, y, i])
	if not p in SD.keys():
		SD[p] = []
	SD[p].append([y, i])
C = [1] * (M + 1)
P = {}
for pref in SD.keys():
	for year, city in SD[pref]:
		if not pref in P.keys():
			P[pref] = 1
		else:
			P[pref] += 1
		C[city] = P[pref]
for i in range(M):
	print "%06d%06d" % (D[i][0], C[i])

Submission status: Wrong Answer

Solution code:
from collections import defaultdict
N, M = map(int, input().split())
py_dict = defaultdict(list)
for i in range(0,M):
    P, Y = map(int, input().split())
    py_dict[P].append(Y)
sorted(py_dict.items())
for n in range(0,N):
    P = n+1
    py_dict
    for y in py_dict[n+1]:
        print(str(P)+"-"+str(y))

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])


ans = [[]]*m
p = 1
for i in range(m):
    count = 1
    ans[i] = [l[i][0], str(p).zfill(6) + str(count).zfill(6)]
    count = count + 1

    if i != m-1 and l[i+1][1] != l[i][1]:
        p = p + 1
        count = 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 = []

Indexs = []
Syuturyoku = []


for j in range(N):
	P.append([0])


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

	P[p-1].append(y)
	Indexs.append(y)
	Syuturyoku.append(("0","0"))

for i in range(len(P)):
	P[i].sort()
	P[i] = list(map(str,P[i]))


for i in range(len(P)):
	if(len(P[i])>1):
		for j in range(len(P[i])-1):
			atai = P[i][j+1]
			si = i+1
			si = str(si)
			x = j+1
			x = str(x)
			bangou = list(map(str,si))
			bangou_len = int(len(bangou))
			bangou_ushiro = list(map(str,x))
			bangou_ushiro_len = int(len(bangou_ushiro))
			if(len(bangou)<6):
				for zero in range(6-bangou_len):
					bangou.insert(0,'0')
			if(len(bangou_ushiro)<6):
				for zero in range(6-bangou_ushiro_len):
					bangou_ushiro.insert(0,'0')

			mojiretsu = ''
			for k in bangou:
				mojiretsu += k
			mojiretsu2 = ''
			for k2 in bangou_ushiro:
				mojiretsu2 += k2

			a = Indexs.index(int(atai))
			Syuturyoku[a] = (mojiretsu,mojiretsu2)
for i in range(M):
	print(Syuturyoku[i][0],Syuturyoku[i][1])

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(p):
    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:
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()))

for i, j in mat:
	sub_mat = mat[mat[:, 0]== i]
	#print(sub_mat)
	idx = sub_mat[:, 1].argsort()[sub_mat[:, 1] == j]
	#print(i, idx)
	print('{0:06d}{1:06d}'.format(int(i), int(idx)+1))

Submission status: Wrong Answer

Solution code:
N, M = [int(x) for x in input().split()]
prefectures = {}
for i in range(N):
    prefectures[i+1] = []

historys = []
for _ in range(M):
    historys.append([int(x) for x in input().split()])
print(historys)

for P, Y in historys:
    prefectures[P].append(Y)
print(prefectures)

sort_prefectues={}
for key, value in prefectures.items():
    sort_prefectues[key]=sorted(value)
    
print(sort_prefectues)

for P, Y in historys:
    idx = sort_prefectues[P].index(Y)
    print("{:06d}{:06d}".format(P, idx+1))

Submission status: Wrong Answer

Solution code:
from operator import itemgetter

def main():
    N,M = list(map(int, input().split()))
    lst = [[] for i in range(N)]
    anslst = []

    for i in range(M):
        P,Y = list(map(int, input().split()))
        lst[P-1].append({'city_id':i, 'pref':P, 'year':Y})

    for i in range(N):
        tmp = lst[i]
        for j in range(len(tmp)):
            city_id = tmp[j]['city_id']
            pref = tmp[j]['pref']
            year = tmp[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'))
    for i in range(len(anslst)):
        print(anslst[i]['id'])

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import copy

read_line = input().split()
N = int(read_line[0])
M = int(read_line[1])

pref_city_list = []

for i in range(M) :
	pref_city_list.append(input())

list = copy.deepcopy(pref_city_list)
list.sort()

city_pref_id_dic = {}


prev_pref_id = list[0].split()[0]
city_count = 0

for i in range(len(list)) :
	factors = list[i].split()
	pref_id = factors[0]
	if (prev_pref_id != pref_id) :
		prev_pref_id = pref_id
		city_count = 0
	
	city_count = city_count + 1
	city_pref_id_dic[list[i]] = str(pref_id).zfill(6) + str(city_count).zfill(6)


for i in range(len(pref_city_list)) :
	print(city_pref_id_dic[pref_city_list[i]])

Submission status: Wrong Answer

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

list_p = [[] for i in range(1, N + 1)]
order = []

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

# list_p2 = [sorted(k) for k in list_p]
for k in list_p:
    k = sorted(k)

for p, y in order:
    # prefecture = '{:0=6}'.format(p)
    # city = '{:0=6}'.format(dic_p[p].index(y) + 1)
    print('{:0=6}'.format(p) + '{:0=6}'.format(list_p[p-1].index(y) + 1))

Submission status: Wrong Answer

Solution code:
def year(x):
    return Y[x]

N, M = [int(s) for s in input().rstrip().split()]
P = []
Y = []
for m in range(M):
    input_line = [int(s) for s in input().rstrip().split()]
    P.append(input_line[0])
    Y.append(input_line[1])

pref = [[] for _ in range(N)]
for m in range(M):
    pref[P[m]-1].append(m)

for n in range(N):
    pref[n].sort(key = year)
    
id = []
for m in range(M):
    str1 = '{0:06d}'.format(P[m])
    for i in range(len(pref[P[m]-1])):
        if i == m:
            str2 = '{0:06d}'.format(i+1)
    id.append(str1 + str2)

for m in range(M):
    print(id[m])

Submission status: Wrong Answer

Solution code:
# coding: UTF-8
import sys
#sys.setrecursionlimit(n)
import heapq
import re
import bisect
import random
import math
import itertools
from collections import defaultdict, deque
from copy import deepcopy
from decimal import *

n, m = map(int, input().split())
p = defaultdict(lambda :defaultdict(int))
e = [[int(i) for i in input().split()] for i in range(m)] 
p_index = [0] * (100001)
for i in e:
    pp, yy = i[0], i[1]
    p_index[pp] += 1
    p[pp][yy] = p_index[pp]

for i in e:
    print("{:0=6}".format(i[0]) + "{:0=6}".format(p[i[0]][i[1]]))

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):
    p[i], y[i] = map(int, input().split())
    if p[i] not in p_dict:
        i_in_p[i] = 0
        p_dict[p[i]] = [y[i]]
        continue
    i_in_p[i] = len(p_dict[p[i]])
    p_dict[p[i]].append(y[i])

for key in p_dict.keys():
    p_dict[key] = list(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:
from operator import itemgetter

def main():
    N,M = list(map(int, input().split()))
    lst = [[] for i in range(N+1)]
    anslst = []

    for i in range(M):
        P,Y = list(map(int, input().split()))
        lst[P].append({'city_id':i, 'pref':P, 'year':Y})

    for i in range(N):
        tmp = lst[i+1]
        for j in range(len(tmp)):
            city_id = tmp[j]['city_id']
            pref = tmp[j]['pref']
            year = tmp[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'))
    for i in range(len(anslst)):
        print(anslst[i]['id'])

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import numpy as np
N,M = map(int,input().split())
prefs = np.zeros([M,3])
for i in range(M):
  P,Y = map(int,input().split())
  prefs[i,:] = [P,Y,0]
#print(prefs)
srts = []
for i in range(1,N+1):
  target = prefs[prefs[:,0]==i]
  #print(target)
  junind = np.argsort(target[:,1])
  #junnum = np.zeros(target.shape[0])
  #for k,x in enumerate(junind):
   # junnum[x] = k
  srts.append(junind)
#print(srts)
ks = np.zeros(N)
for i in range(M):
  p = prefs[i,0] - 1
  prefs[i,2] = int(srts[int(p)][int(ks[p])] + 1)
  ks[p] += 1
  print("{:>06d}".format(int(prefs[i,0]))+"{:>06d}".format(int(prefs[i,2])))
#print(prefs)

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""Describe
"""
import numpy as np
from operator import itemgetter

def main():
    n, m = map(int, input().split())
    data = None
    for i in range(m):
        p, y = map(int, input().split())
        if data is None:
            data = np.array([[p, y]])
        else:
            data = np.append(data, [[p, y]], axis=0)
    # print(np.array(data)) 
    data = data.tolist()# np.transpose(data).tolist()
    data = sorted(data, key=itemgetter(0, 1))
    # print(data)

    p, y = 0, 0
    p_prev = 0 
    x = 1 # initialize
    for p, y in data:
        # initialize if new prefecture, increment if not
        if p != p_prev:
            x = 1
        else:
            x += 1
        code = '{:06d}{:06d}'.format(p, x)
        print(code) 
        p_prev = p
        
        

#     print(np.array(data))
#     dtypes = np.dtype([('p', 'int'), ('y', 'int')])
#     data = np.array(data, dtype=dtypes)
#     for i in range(len(data)):
#         print(i, data[i])
#         for j in range(len(data[i])):
#             print(data[i][j])
# 
main()

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()))+[i])
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],i[2],str(i[0]).rjust(6,'0')+str(state).rjust(6,'0')])
    else:
        state+=1
        triple.append([i[0],i[1],i[2],str(i[0]).rjust(6,'0')+str(state).rjust(6,'0')])

triple.sort(key=lambda x:x[2])
for i in triple:
    print(i[3])

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)]
Ncount = [0 for i in range(N+1)]
Num = ["000000000000" for i in range(M)]
Jisho = {}
for i in range(M):
	P[i],Y[i] = map(int,input().split())
	Ncount[P[i]] = Ncount[P[i]] + 1
	pre = str(P[i]).zfill(6)

	if Ncount[P[i]] == 1:
		Num[i] = pre+"000001"
		Jisho[Num[i]] = [i,Y[i]]
	else:
		flug = 0
		for j in range(1,Ncount[P[i]]-1):
			numb = pre+str(j).zfill(6)

			if Jisho[numb][1] > Y[i]:
				for k in range(Ncount[P[i]],j,-1):
					nn = pre + str(k).zfill(6)
					nnn = pre + str(k-1).zfill(6)
					Jisho[nn] = Jisho[nnn]
					Num[Jisho[nn][0]] = nn
				Num[i] = numb
				Jisho[Num[i]] = [i,Y[i]]
				flug = 1
				break
		if flug == 0:
			numb = pre+str(Ncount[P[i]]).zfill(6)
			Num[i] = numb
			Jisho[Num[i]] = [i,Y[i]]
			
for i in range(M):
	print(Num[i])

Submission status: Wrong Answer

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

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

sorted_city = {p:sorted(P[p]) for p in P}

print(sorted_city)
for p, cities in  sorted(sorted_city.items()):
    for i,city in enumerate(cities):
        print('{0:06d}{1:06d}'.format(p,i+1))

Submission status: Wrong Answer

Solution code:
N,M = map(int,input().split())
P = []
Y = []
arr = [[]for j in range(10**5+1)]
for i in range(M):
  listA = list(map(int,input().split()))
  P.append(listA[0])
  Y.append(listA[1])
  arr[listA[0]].append(listA[1])
for i in range(N):
  arr[i].sort()
for i in range(M):
  #二部探索
  left = 0
  right = len(arr[P[i]])-1
  while left <= right:
    mid = (left+right)//2
    if arr[P[i]][mid] == Y[i]:
      k = mid
      break
    elif arr[P[i]][mid] > Y[i]:
      right = mid-1
    else:
      left = mid+1
  print(str(P[i]).rjust(6,'0')+str(k+1).rjust(6,'0'))

Submission status: Wrong Answer

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

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):
    lis[i,0:2] = [int(x) for x in input().strip('\n').split(' ')]
for i in set(lis[:,0]):
    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:
n, m = list(map(int, input().split()))
city_list = [[] for i in range(n)]
numbers = []

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

for i in range(n):
    city_list[i].sort()
    for j in range(len(city_list[i])):
        print("{:0=6}{:0=6}".format(i+1, j+1))

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])

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

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

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

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
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] = list(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:
def sixprint(s):
    l = len(str(s))

    return str(0)*(6-l) + str(s)

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

l = []
for i in range(M):
    pp,yy = map(int,input().split())
    lis = [i,pp,yy]
    l.append(lis)


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


x1 = lll[0][1]
lll[0].append(1)
cnt = 2
for i in range(1,M):
    if x1 == lll[i][1]:
        lll[i].append(cnt)
        cnt += 1
    else:
        x1 = lll[i][1]
        cnt = 1
        lll[i].append(cnt)
        cnt += 1


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

for i in range(M):
    print(sixprint(llll[i][1]) + sixprint(llll[i][-1]))

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()

for p in range(1,n+1):
    cnt = 1
    for x in xs:
        if x[0] == p:
            x[3] = cnt
            cnt += 1
        else:
            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:
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)]
print(l)

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())
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
count=0
for m in range(M):
    count+=1
    if data[m][0]!=pref:
        count=1
    pref=data[m][0]
    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:
# coding: utf-8
N, M = map(int, input().split())

li_origin = []
for _ in range(M):
    i = input().replace(" ","")
    li_origin.append(i)
li_sorted = sorted(li_origin)


dic = {}
tmp = ""
cnt = 1
for s in li_sorted:
    if tmp != s[0]:
        cnt = 1
        tmp = s[0]
        p = tmp.zfill(6)
        x = "{0:06d}".format(cnt)
    else:
        cnt += 1
        p = tmp.zfill(6)
        x = "{0:06d}".format(cnt)
    id_s = p+x
    dic.update({s:p+x})

for k in li_origin:
    print(dic[k])

Submission status: Wrong Answer

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

number_dict = {}

for i, m in enumerate(range(M)):
    P, Y = map(int, raw_input().split())

    if P in number_dict:
        number_dict[P].append([i+1, Y])
    else:
        number_dict[P] = [[i+1, Y]]

L = list(number_dict.items())

L.sort(key=lambda l: l[0])

result = []

for l in L:
    prefix = '%06d' % l[0]
    for i, city in enumerate(l[1]):
        number = '%06d' % (i+1)
        order = city[0]
        result.append([order, prefix+number])

result.sort(key=lambda x: x[0])
for r in result:
    print r[1]

Submission status: Wrong Answer

Solution code:
from operator import itemgetter

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()

for p in range(1,n+1):
    cnt = 1
    for x in xs:
        if x[0] == p:
            x[3] = cnt
            cnt += 1
        else:
            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:
"""
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)
    p = []
    y = []
    ken = np.ones(shape=(n, 2), dtype=int)
    shi = np.zeros(shape=(m, 4), dtype=int)

    for i in range(m):
        tp,ty = simple_input()
        shi[i,0] = i
        shi[i,1] = tp
        shi[i,2] = ty

    #年順に並び替え
    shi = shi[ shi[:,2].argsort(), :]    #年
    shi = shi[ shi[:,1].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:
from operator import itemgetter

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

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

for i in range(M):
    jj=Pk[PY[i][0]-1]
    for j in range(jj):
        if i==P[PY[i][0]-1][j][0]:
            a=format(PY[i][0],'06x')
            b=format(j+1,'06x')
            print(a+b)

Submission status: Wrong Answer

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

for i in range(n):
    pli[i].sort()

for i in range(m):
    print("0" * (6 - len(str(py[i][0]))) + str(py[i][0]) + "0" * (6 - len(str(pli[py[i][0]-1].index(py[i][1])))) + str(pli[py[i][0]-1].index(py[i][1]) + 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].zfill(6) 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)]
print(l)

y = [str(l[int(list[i][0])-1].index(list[i][1])+1).zfill(6) for i in range(m)]

for i in range(m):
    print(list2[i]+y[i])

Submission status: Wrong Answer

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

P=[0]
Y=[0]
A=[]

for i in range(M):
	p, y = map(int, input().split())		# 5 7
	P.append(p)
	Y.append(y)
	A.append([i,p,y,p*1000000 + y])

#print(N,M)
#print(*P)
#print(*Y)
#print(*A)

A = sorted(A, key=lambda x: x[3])

#print(*A)

p0=0
no=0
for i in range(len(A)):
	a=A[i]
	p=a[1]
	y=a[2]
#	print(i,a,p,y)
	
	if(p!=p0):no=0
	no+=1
	A[i].append(no)
	
	p0=p

#print(*A)

A = sorted(A, key=lambda x: x[0])
#print(*A)

for a in A:
	p = "000000" + str(a[1])
	i = "000000" + str(a[4])
	print(p[-6:]+i[-6:])

Submission status: Wrong Answer

Solution code:
import numpy as np

n, m = map(int, input().split())
ps = list()
ys = list()
for i in range(m):
    p, y = map(int, input().split())
    ps.append(p)
    ys.append(y)

# N ken, M shi
# yi : i-shi の誕生年
# pi : i-shiが属する県
# 同じ年に誕生したshiは唯一に定まる

# i-shiがpiに属するshiのなかでx番目に誕生したshiの時，i-shiの認識番号の
# 上６桁はpi,下6桁はxとなる
# ただし，6桁に満たない場合は0を左に追加する

# 全ての市の認識番号を求めよ
# ただし，shiが一つも属さない県もある

# pごとのリストを作る
pp = list()
res = list()
for i in range(max(ps)):
    pp.append(np.array([]))
    res.append([])
# 並べ替え
for p, y in zip(ps, ys):
    pp[p-1] = np.append(pp[p-1], y)

num = [np.argsort(l) for l in pp]
for i in range(len(num)):
    for e in num[i]:
        res[i].append(('0'*(6-len(str(i))) + str(i+1) + '0'*(6-len(str(e+1))) + str(e+1)))

for p in ps:
    if len(res[p-1]) > 0:
        print(res[p-1].pop(0))

Submission status: Wrong Answer

Solution code:
import numpy as np

nm = input()
n,m = nm.split()
n = int(n)
m = int(m)
cities = [i for i in range(m)]
prefs = [[] for i in range(n)]

for i in range(m):
    temp = input()
    temp = temp.split()
    temp[0] = int(temp[0])
    temp[1] = int(temp[1])
    prefs[temp[0]-1].append(temp[1])
    cities[i] = temp

for i in range(len(prefs)):
     prefs[i] = np.argsort(prefs[i])

count = [0 for i in range(n)]

for i in range(len(cities)):
    ids = 1000000000000 + 1000000*cities[i][0] + prefs[cities[i][0]-1][count[cities[i][0]-1]]+1
    count[cities[i][0]-1] = count[cities[i][0]-1] + 1
    ids = str(ids)
    print(ids[1:])

Submission status: Wrong Answer

Solution code:
ls = input().strip().split(' ')
N = int(ls[0])
M = int(ls[1])
ls = []
for i in range(M):
    ln = input().strip().split(' ')
    ls.append((ln, i))
ls.sort()
result = []
x = 1
lst = -1
for i in ls:
    if i[0][0] == lst:    x += 1
    else:    x = 1
    result.append((i[1], '{:06d}{:06d}'.format(int(i[0][0]), x)))
    lst = i[0][0]
result.sort()
for i in result:
    print(i[1])