Problem:


Score: 300 points

Problem Statement

In Republic of Atcoder, there are N prefectures, and a total of M cities that belong to those prefectures.

City i is established in year Y_i and belongs to Prefecture P_i.

You can assume that there are no multiple cities that are established in the same year.

It is decided to allocate a 12-digit ID number to each city.

If City i is the x-th established city among the cities that belong to Prefecture i, the first six digits of the ID number of City i is P_i, and the last six digits of the ID number is x.

Here, if P_i or x (or both) has less than six digits, zeros are added to the left until it has six digits.

Find the ID numbers for all the cities.

Note that there can be a prefecture with no cities.

Constraints

1 \leq N \leq 10^5

1 \leq M \leq 10^5

1 \leq P_i \leq N

1 \leq Y_i \leq 10^9

Y_i are all different.

All values in input are integers.

Input

Input is given from Standard Input in the following format:

N M
P_1 Y_1
:
P_M Y_M

Output

Print the ID numbers for all the cities, in ascending order of indices (City 1, City 2, ...).

Sample Input 1

2 3
1 32
2 63
1 12

Sample Output 1

000001000002
000002000001
000001000001

As City 1 is the second established city among the cities that belong to Prefecture 1, its ID number is 000001000002.

As City 2 is the first established city among the cities that belong to Prefecture 2, its ID number is 000002000001.

As City 3 is the first established city among the cities that belong to Prefecture 1, its ID number is 000001000001.

Sample Input 2

2 3
2 55
2 77
2 99

Sample Output 2

000002000001
000002000002
000002000003



Sample input:
2 3
1 32
2 63
1 12


Sample output:
000001000002
000002000001
000001000001

Submission status: Wrong Answer

Solution code:
n,m=map(int,input().split())
ken=[0 for i in range(n)]
for i in range(m):
    p,y=map(int,input().split())
    ken[p-1]+=1
ken0=[]
for i in range(n):
    for j in range(ken[i]):
        mae=str(i+1)
        ato=str(j+1)
        while len(mae)<6:
            mae='0'+mae
        while len(ato)<6:
            ato='0'+ato
        ken0.append(mae+ato)
for i in ken0:
    print(i)

Submission status: Wrong Answer

Solution code:
from operator import itemgetter
pres = []
numbers = []
N,M = map(int, input().split())

for i in range(M):
    numbers.append('')

for i in range(N):
    pres.append([])

i = 0
for t in range(M):
    p,y = map(int,input().split())
    pres[p-1].append((y,i))
    i+=1

i = 0
for p in pres:
    if p==[]:
        continue
    i+=1
    front = '00000' + str(i)
    front = front[-6:]
    temp_p = p
    temp_p.sort(key=itemgetter(0))
    j = 0
    for city in temp_p:
        j+=1
        back = '00000' + str(j)
        back = back[-6:]
        numbers[city[1]] = front+back
        
for num in numbers:
    print(num)

Submission status: Wrong Answer

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

#l = [[]] * n リストが参照で作られるからNG
l = [[] for i in range(n)]

for i in range(m):
    p, y = map(int, input().split())
    print('p:{} y:{} i:{}'.format(p, y, i))
    l[ p - 1 ].append(y)
    
for i in range(len(l)):
    for j in range(len(l[i])):
        print('{ken:06}{shi:06}'.format(ken=i+1, shi=j+1))

Submission status: Wrong Answer

Solution code:
n,m = map(int,input().split())
city = [[] for i in range(n)]
def f(s):
    s = str(s)
    t  = 6 - len(s)
    s = "0"*t + s
    return s
for i in range(m):
    ken,year = map(int,input().split())
    city[ken-1].append(year)
for i in range(n):
    city[i].sort()
    for j in range(len(city[i])):
        ans = f(i+1) + f(j+1)
        print(ans)

Submission status: Wrong Answer

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

sort_P_Y = []

for i in range(N):
	tem_sort = []
	for j in range(M):
		if P_Y[j][0] == i+1:
			tem_sort.append(P_Y[j][1])
	tem_sort.sort()
	sort_P_Y.append(tem_sort)

for i in range(M):
	Pre = P_Y[i][0]
	num = sort_P_Y[Pre-1].index(P_Y[i][1])
	if Pre < 10 and num < 10:
		print("00000"+str(Pre)+"00000"+str(num+1))

Submission status: Wrong Answer

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

sort_P_Y = []

for i in range(N):
	tem_sort = []
	for j in range(M):
		if P_Y[j][0] == i+1:
			tem_sort.append(P_Y[j][1])
	tem_sort.sort()
	sort_P_Y.append(tem_sort)

for i in range(M):
	Pre = P_Y[i][0]
	num = sort_P_Y[Pre-1].index(P_Y[i][1])
	if Pre < 10 and num < 10:
		print("00000"+str(Pre)+"00000"+str(num+1))
	elif Pre < 100 and num < 10:
		print("0000"+str(Pre)+"00000"+str(num+1))
	elif Pre < 10 and num < 100:
		print("00000"+str(Pre)+"0000"+str(num+1))
	else:
		print("0000"+str(Pre)+"0000"+str(num+1))

Submission status: Wrong Answer

Solution code:
N, M = [int(i) for i in input().split()]
data = list()
for i in range(M):
    p, y = [int(i) for i in input().split()]
    data.append([i, p, y])
data.sort(key=lambda x:(x[1],x[2]))
ind = 1
for j, (i, p, y) in enumerate(data):
    if data[j-1][1] != p and j > 1:
        ind = 1
    data[j].append(ind)
    ind += 1
data.sort(key=lambda x:x[0])
for i, p, y, j in data:
    print(str(p).zfill(6) + str(j).zfill(6))

Submission status: Wrong Answer

Solution code:
N, M = [int(i) for i in input().split()]
data = list()
data_dict = dict()
ind = 1
for i in range(M):
    p, y = [int(i) for i in input().split()]
    data.append([i,p,y])
data.sort(key=lambda x: (x[1], x[2]))
ranked_data = list()
for j, (i, p, y) in enumerate(data):
    if data[j-1][1] != p and j > 1:
        ind = 1
    ranked_data.append([i, p, y] + [ind])
    ind += 1

def num2str(num, len_str=6):
    return "0" * (len_str - len(str(num))) + str(num)

ranked_data.sort(key=lambda x:x[0])
for i, p, y, rank in ranked_data:
    print(num2str(p) + num2str(rank))

Submission status: Wrong Answer

Solution code:
n, m = [int(i) for i in input().split(" ")]
ps = []
pc = [0 for i in range(0, n + 1)]

for i in range(0, m):
    ps.append([i] + [int(i) for i in input().split(" ")] + [""])

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

for i in range(0, m):
    pc[ps[i][1]] += 1
    ps[i][3] = str(ps[i][1]).zfill(6) + str(pc[ps[i][1]]).zfill(6)

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

for i in range(0, m):
    print(ps[i])

Submission status: Wrong Answer

Solution code:
n, m = [int(i) for i in input().split(" ")]
ps = []
pc = [0 for i in range(0, n + 1)]

for i in range(0, m):
    ps.append([i] + [int(i) for i in input().split(" ")] + [""])

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

for i in range(0, m):
    pc[ps[i][1]] += 1
    ps[i][3] = str(ps[i][1]).zfill(6) + str(pc[ps[i][1]]).zfill(6)

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

for i in range(0, m):
    print(ps[i][3])

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())))
for j in range(M):
  L[j].append(j)
L.sort()
print(L)
l = L[0][0]
cnt = 0
for k in range(M):
  if l == L[k][0]:
    cnt += 1
    L[k].append(cnt)
  else:
    l = L[k][0]
    cnt = 1
    L[k].append(cnt)
print(L)
L = sorted(L, key = lambda x:x[2])
for i in range(M):
  print('0'*(6-len(str(L[i][0])))+str(L[i][0])+'0'*(6-len(str(L[i][3])))+str(L[i][3]))

Submission status: Wrong Answer

Solution code:
N,M=map(int,input().split())
prefecture = [0]*N
city = []
for i in range(M):
    P,Y = map(int,input().split())
    prefecture[P-1] += 1
    city+=["0"*(6-len(str(P)))+str(P)+"0"*(6-len(str(prefecture[P-1]))) +str(prefecture[P-1])]

for i in city:
    print(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())))
for j in range(M):
  L[j].append(j)
L.sort()
l = L[0][0]
cnt = 0
for k in range(M):
  if l == L[k][0]:
    L[k].append(cnt)
    cnt += 1
  else:
    l = L[k][0]
    cnt = 0
    L[k].append(cnt)
L = sorted(L, key = lambda x:x[2])
for i in range(M):
  print('0'*(6-len(str(L[i][0])))+str(L[i][0])+'0'*(6-len(str(L[i][3]+1)))+str(L[i][3]+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())))
for j in range(M):
  L[j].append(j)
L.sort()
l = L[0][0]
cnt = 0
for k in range(M):
  if l == L[k][0]:
    L[k].append(cnt)
    cnt += 1
  else:
    l = L[k][0]
    cnt = 0
    L[k].append(cnt)
L = sorted(L, key = lambda x:x[2])
print(L)
for i in range(M):
  print('0'*(6-len(str(L[i][0])))+str(L[i][0])+'0'*(6-len(str(L[i][3]+1)))+str(L[i][3]+1))

Submission status: Wrong Answer

Solution code:
def read():
    return int(input())

def reads():
    return list(map(int, input().split()))

n,m = reads()
cnt = {k:[] for k in range(n+1)}
buf = [None]*m
for i in range(m):
    p,y = reads()
    cnt[p].append((y,i))
for p,l in cnt.items():
    if not l:
        continue
    l.sort()
    print(l)
    for j,(y,i) in enumerate(l):
        buf[i] = '{:06d}{:06d}'.format(p,j+1)

print('\n'.join(buf))

Submission status: Wrong Answer

Solution code:
def read():
    return int(input())

def reads():
    return list(map(int, input().split()))

n,m = reads()
cnt = {k:[] for k in range(n+1)}
buf = [0]*m
for i in range(m):
    p,y = reads()
    cnt[p].append((y,i))
for p,l in cnt.items():
    if not l:
        continue
    l.sort()
    print(l)
    for j,(y,i) in enumerate(l):
        buf[i] = '{:06d}{:06d}'.format(p,j+1)
        
print('\n'.join(buf))

Submission status: Wrong Answer

Solution code:
N, M = map(int, input().split(' '))
cities = []
pref_index = {}

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

for c in cities:
  pref_index[c[0]] = pref_index.get(c[0], 1) + 1
  c.append(pref_index[c[0]])
  
cities = sorted(cities, key = lambda x:x[2])

for c in cities:
  print("%06d%06d" % (c[0], c[3]))

Submission status: Wrong Answer

Solution code:
# https://atcoder.jp/contests/abc113/tasks/abc113_c

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

dict = {}

for c in c_l:
    if c[0] in dict:
        dict[c[0]].append(c[1])
    else:
        dict[c[0]] = [c[1]]


for k, v in dict.items():
    v.sort()

print(dict)

for c in c_l:
    idx = dict[c[0]].index(c[1]) + 1
    print("{:06}{:06}".format(c[0], idx))

Submission status: Wrong Answer

Solution code:
import numpy as np

N,M = map(int, input().split())
X = [list(map(int, input().split()))+[1] for _ in range(M)]
X = np.array(X, dtype=int)
for i in range(1,N+1):
    a = X[:,0]==i
    X[a, 2] = np.argsort(X[a, 1])+1
for x in X:
    print('{:06}{:06}'.format(x[0], x[2]))

Submission status: Wrong Answer

Solution code:
import numpy as np

N,M = map(int, input().split())
X = np.ones((M,3), dtype=int)
for i in range(M):
    X[i, 0], X[i, 1] = map(int, input().split())
for i in range(1,N+1):
    a = X[:,0]==i
    X[a, 2] = np.argsort(X[a, 1])+1
for i in range(M):
    print('{:06}{:06}'.format(X[i,0], X[i,2]))

Submission status: Wrong Answer

Solution code:
import numpy as np

N,M = map(int, input().split())
X = np.ones((M,3), dtype=int)
for i in range(M):
    X[i, 0], X[i, 1] = map(int, input().split())
for i in range(N):
    print(np.argsort(X[X[:,0]==i, 1]))
    X[X[:,0]==i, 2] = np.argsort(X[X[:,0]==i, 1])+1
for i in range(M):
    print('{:06}{:06}'.format(X[i,0], X[i,2]))

Submission status: Wrong Answer

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

ken = [(i,) + tuple(map(int,input().split())) for i in range(m)]

def func(elem):
    return elem[1:3]
ken.sort(key=func)

currKen = ken[0][1]
cnt = 1
for i in range(len(ken)):
    if ken[i][1] == currKen:
        ken[i] +=(cnt,)
        cnt += 1
    else:
        currKen = ken[i][1]
        cnt = 1
        ken[i] +=(cnt,)


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

for k in ken:
    print("%.6d%.6d"%(k[1],k[3]))

Submission status: Wrong Answer

Solution code:
N,M = map(int,input().split())
L = []
for i in range(M):
    l = list(map(int,input().split()))+[i]
    L.append(l)
cnt = 0
tmp = []
M = sorted(L,key = lambda x: (x[0],x[1]))
for x in M:
    if tmp == x[0]:
        x.append(cnt+1)
        cnt += 1
    else:
        tmp = x[0]
        cnt = 0
        x.append(cnt)
M = sorted(L,key = lambda x:x[2])
#print(M)
for x in M:
    st = str(x[0]).zfill(5)
    st += str(x[3]+1).zfill(5)
    print(st)

Submission status: Wrong Answer

Solution code:
N,M = map(int,input().split())
L = []
for i in range(M):
    l = list(map(int,input().split()))+[i]
    L.append(l)
cnt = 0
tmp = []
M = sorted(L,key = lambda x: (x[0],x[1]))
for x in M:
    if tmp == x[0]:
        x.append(cnt+1)
        cnt += 1
    else:
        tmp = x[0]
        cnt = 0
        x.append(cnt)
M = sorted(L,key = lambda x:x[2])
print(M)
for x in M:
    st = str(x[0]).zfill(5)
    st += str(x[3]+1).zfill(5)
    print(st)

Submission status: Wrong Answer

Solution code:
N, M = map(int, input().split())
shi = [[0]]*N
# for i in range(N):
#     shi.append([0])
# print(shi)

data = []
for i in range(M):
    data.append(list(map(int, input().split())))

for each in data:
    shi[each[0]-1].append(each[1])

for i in range(N):
    shi[i].sort()
    # shi[i] = sorted(shi[i])

# print(shi)
for each in data:
    print(str(each[0]).zfill(6)+str(shi[each[0]-1].index(each[1])).zfill(6))

Submission status: Wrong Answer

Solution code:
N, M = map(int, input().split())
L = [list(map(int, input().split())) for _ in range(M)]
Y = sorted([(i, (p, y)) for i, (p, y) in enumerate(L)], key=lambda x: x[1][1])
result = [""] * M
x = 0
before_p = 0
for i, (p, y) in Y:
    if before_p != p:
        x = 0
        before_p = p
    x += 1
    result[i] = "{:06}{:06}".format(p, x)
for r in result:
    print(r)

Submission status: Wrong Answer

Solution code:
from bisect import bisect_left
n,m=map(int,input().split())
ls=[[] for i in range(n)]
py=[]
for i in range(m):
  p,y=map(int,input().split())
  ls[p-1].append(y)
  py.append([p,y])
lscopy=ls[:]
ls=list(map(lambda x:sorted(x),ls))
for i in range(m):
  p,y=py[i]
  index= bisect_left(ls[p-1],y)
  print(str(p).zfill(7-len(str(p)))+str(index+1).zfill(7-len(str(index+1))))

Submission status: Wrong Answer

Solution code:
import numpy as np

n, m = (int(i) for i in input().split())
p = []
y = []
for i in range(m):
    p_tmp, y_tmp = (int(i) for i in input().split())
    p.append(p_tmp)
    y.append(y_tmp)
p = np.array(p)
y = np.array(y)

#print(str(p[0]).zfill(6) + str(p[0]).zfill(6))

y_rank = np.zeros((m)).astype(int)
for i in range(1,n+1, 1):
    pos = np.where(p==i)[0]
    order = np.argsort(y[pos]+1)
    y_rank[pos] = order+1

for i in range(m):
    print(str(p[i]).zfill(6) + str(y_rank[i]).zfill(6))

Submission status: Wrong Answer

Solution code:
import bisect

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

cities = {}
prefs = []

for i in range(1, M + 1):
  p, y = list(map(int, input().split()))
  
  pref = {"city": p, "year": y}
  prefs.append(pref)

  if p not in cities:
    cities[p] = [pref]
  else:
    cities[p].append(pref)
print(cities)
for city in cities.values():
  city.sort(key=lambda p: p['year'])
  for idx, pref in enumerate(city):
    pref['pref_id'] = str(idx + 1).zfill(6)

[print("%s%s" % (
  str(int(pref['city'])).zfill(6), 
  pref['pref_id'])) for pref in prefs]

Submission status: Wrong Answer

Solution code:
n, m = list(map(int, input().split()))
li = []
yli = []
for _ in range(m):
    p, y = list(map(int, input().split()))
    li.append((y, p))
    yli.append(y)

import numpy as np
idx = np.argsort(yli).argsort()
srt = sorted(li)
ans = []
from collections import Counter
pcnt = Counter()
for p, y in srt:
    pcnt[p] += 1    
    ans.append('{:06}{:06}'.format(p, pcnt[p]))

for i in idx:
    print(ans[i])

Submission status: Wrong Answer

Solution code:
n, m = list(map(int, input().split()))
li = []
yli = []
for _ in range(m):
    p, y = list(map(int, input().split()))
    li.append((y, p))
    yli.append(y)

import numpy as np
idx = np.argsort(yli)
srt = sorted(li)
ans = []
from collections import Counter
pcnt = Counter()
for p, y in srt:
    pcnt[p] += 1    
    ans.append('{:06}{:06}'.format(p, pcnt[p]))

for i in idx:
    print(ans[i])

Submission status: Wrong Answer

Solution code:
a,b=map(int,input().split())
L=[[] for i in range(a)]
l=[]
ll=[]
u=0
for i in range(b):
    u+=1
    c=list(map(int,input().split()))
    c.append(u)
    L[int(c[0])-1].append(c)
    print(c,L)
for i in L:
    i.sort(key=lambda x:x[1])
for i in L:
    e=0
    for j in i:
        e+=1
        j.append(e)
print(L)
q=[]
for w in L:
   q.extend(w) 
q.sort(key=lambda x:x[2])
for r in range(b):
        print('0'*(6-len(str(q[r][0])))+str(q[r][0])+'0'*(6-len(str(q[r][3])))+str(q[r][3]))

Submission status: Wrong Answer

Solution code:
a,b=map(int,input().split())
L=[]
l=[]
ll=[]
u=0
for i in range(b):
    u+=1
    c=list(map(int,input().split()))
    c.append(u)
    L.append(c)
L.sort(key=lambda x:x[0])
for i in range(1,a+1):
    lll=[]
    for j in L:
        if j[0]==i:
            lll.append(j)
    ll.append(lll)
for i in ll:
    e=0
    for j in i:
        e+=1
        j.append(e)
q=[]
for w in ll:
   q.extend(w) 
q.sort(key=lambda x:x[2])
for r in range(b):
        print('0'*(6-len(str(q[r][0])))+str(q[r][0])+'0'*(6-len(str(q[r][3])))+str(q[r][3]))

Submission status: Wrong Answer

Solution code:
from heapq import heappush, heappop

class City(object):
    def __init__(self, i, year):
        self.i = i
        self.year = year
        self.id = None

    def __lt__(self, other):
        return self.year < other.year

    def __eq__(self, other):
        return self.year == other.year

    def __gt__(self, other):
        return self.year > other.year


class Solver(object):
    def __init__(self):
        self.n, self.m = list(map(int, input().split(" ")))
        self.prefectures = [[] for _ in range(self.n)]
        self.cities = []
        for i in range(self.m):
            p, y = list(map(int, input().split(" ")))
            city = City(i+1, y)
            self.cities.append(city)
            heappush(self.prefectures[p-1], city)

    def solve(self):
        for i in range(self.n):
            for j, city in enumerate(self.prefectures[i]):
                city.id = "{:06d}{:06d}".format(i+1, j+1)
        for city in self.cities:
            print(city.id)


if __name__ == "__main__":
    s = Solver()
    s.solve()

Submission status: Wrong Answer

Solution code:
N, M = map(int, input().split())
order = []
result = {}
city = {}
for i in range(M):
    P, Y = map(int, input().split())
    order.append(Y)
    if P in city:
        city[P].append(Y)
    else:
        city[P] = [Y]

s_city = dict(sorted(city.items()))
for v in s_city.values():
    v.sort()

for k, v in city.items():
    i = 1
    for e in v:
        order[order.index(e)] = str(k).zfill(8) + str(i).zfill(8)
        i += 1

for r in order:
    print(r)

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
# -*- coding:utf-8 -*-

def main():
  n, m = map(int, input().split())
  ipy = [(i+1, )+(tuple(map(int, input().split()))) for i in range(m)]
  ipy.sort(key=lambda x:x[2])
  kens = set([p for i,p,y in ipy])
  di = {ken:0 for ken in kens}

  ans = []
  print(ipy)
  for i,p,y in ipy:
    di[p] += 1
    number = ('%06d%06d' % (p, di[p]))
    ans += [(i, number)]
  ans.sort(key=lambda x:x[0])

  for _, number in ans:
    print(number)
  pass

if __name__=='__main__':
  main()

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
# -*- coding:utf-8 -*-

def main():
  n, m = map(int, input().split())
  ipy = [(i+1, )+(tuple(map(int, input().split()))) for i in range(m)]
  kens = set([p for i,p,y in ipy])
  di = {ken:0 for ken in kens}

  ans = []
  for i,p,y in ipy:
    di[p] += 1
    number = ('%06d%06d' % (p, di[p]))
    ans += [(i, number)]
  ans.sort(key=lambda x:x[0])

  for _, number in ans:
    print(number)
  pass

if __name__=='__main__':
  main()

Submission status: Wrong Answer

Solution code:
import numpy as np
import math
from collections import defaultdict

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

P = [int(p) for p in P]
Y = [int(y) for y in Y]

print(P)
print(Y)

sorted = defaultdict(list)

for i in range(m):
	sorted[P[i]].append(Y[i])

for k in sorted.keys():
	sorted[k].sort()

for i in range(m):
	print("{0:06}{1:06}".format(P[i], sorted[P[i]].index(Y[i])+1))

Submission status: Wrong Answer

Solution code:
# https://qiita.com/_-_-_-_-_/items/34f933adc7be875e61d0
# abcde	s=input()	s='abcde'
# abcde	s=list(input())	s=['a', 'b', 'c', 'd', 'e']
# 5(1つだけ)	a=int(input())	a=5
# 1 2	x,y = map(int,input().split())	x=1,y=2
# 1 2 3 4 5 ... n 　	li = input().split()	li=['1','2','3',...,'n']
# 1 2 3 4 5 ... n 　	li = list(map(int,input().split()))	li=[1,2,3,4,5,...,n]
# FFFTFTTFF 　	li = input().split('T')	li=['FFF', 'F', '', 'FF']

# 3
# hoge
# foo
# bar
# n=int(input())
# string_list=[input() for i in range(n)]
# N, M = map(int,input().split())

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

N, M = map(int, input().split())
py = {}
all_py = []
for _ in range(M):
  p, y = map(int, input().split())
  if not p in py:
    py[p] = []
  py[p].append(y)
  all_py.append([p, y])

sort_p = {}
for k, v in all_py:
  if not k in sort_p:
    sort_p[k] = sorted(py[k])
  print("{}{}".format(str(k).zfill(8), str((sort_p[k]).index(v)+1).zfill(8)))

Submission status: Wrong Answer

Solution code:
# https://qiita.com/_-_-_-_-_/items/34f933adc7be875e61d0
# abcde	s=input()	s='abcde'
# abcde	s=list(input())	s=['a', 'b', 'c', 'd', 'e']
# 5(1つだけ)	a=int(input())	a=5
# 1 2	x,y = map(int,input().split())	x=1,y=2
# 1 2 3 4 5 ... n 　	li = input().split()	li=['1','2','3',...,'n']
# 1 2 3 4 5 ... n 　	li = list(map(int,input().split()))	li=[1,2,3,4,5,...,n]
# FFFTFTTFF 　	li = input().split('T')	li=['FFF', 'F', '', 'FF']

# 3
# hoge
# foo
# bar
# n=int(input())
# string_list=[input() for i in range(n)]
# N, M = map(int,input().split())

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

N, M = map(int, input().split())
py = {}
for _ in range(M):
  p, y = map(int, input().split())
  if not p in py:
    py[p] = []
  py[p].append(y)

for i in py:
  sort_p = sorted(py[i])
  for j in py[i]:
    print("{}{}".format(str(i).zfill(8), str(sort_p.index(j)+1).zfill(8)))

Submission status: Wrong Answer

Solution code:
n,m=map(int,input().split())
city=[]
for i in range(m):
    a=i
    b,c=map(int,input().split())
    city.append([a,b,c])
city=sorted(city,key=lambda x:(x[1],x[2]))
print(city)
city[0].append(1)
for i in range(1,m):
    if city[i][1]!=city[i-1][1]:
        city[i].append(1)
    else:
        city[i].append(city[i-1][3]+1)
print(city)
for i in range(m):
    city[i].append(str(city[i][1]).zfill(6)+str(city[i][3]).zfill(6))
city=sorted(city,key=lambda x:(x[0]))
for i in range(m):
    print(city[i][4])

Submission status: Wrong Answer

Solution code:
n,m=map(int,input().split())
city=[]
for i in range(m):
    a=i
    b,c=map(int,input().split())
    city.append([a,b,c])
city=sorted(city,key=lambda x:(x[1],x[2]))
judge=1
count=1
for i in range(m):
    if city[i][1]==judge:
        city[i].append(count)
        count+=1
    else:
        city[i].append(1)
        judge+=1
        count=2
for i in range(m):
    city[i].append(str(city[i][1]).zfill(6)+str(city[i][3]).zfill(6))
city=sorted(city,key=lambda x:x[0])
for i in range(m):
    print(city[i][4])

Submission status: Wrong Answer

Solution code:
n,m=map(int, input().split())
l=[input().split() for i in range(m)]
m={}
lab={}
for j in range(len(l)):
    if l[j][0] not in m.keys():
        m[l[j][0]]=[]
    m[l[j][0]].append(l[j][1])
for k in m.keys():
    m[k].sort()
    p='0'*(6-len(k))+k
    for h in range(len(m[k])):
        q='0'*(6-len(str(h+1)))+str(h+1)
        key=l.index([k,m[k][h]])
        lab[key]=p+q
for k,v in sorted(lab.items()):
    print(v)

Submission status: Wrong Answer

Solution code:
n,m=map(int, input().split())
l=[input().split() for i in range(m)]
m,m_sort={},{}
lab={}
for j in range(len(l)):
    if l[j][0] not in m.keys():
        m[l[j][0]],m_sort[l[j][0]]=[],[]
    m[l[j][0]].append(l[j][1])
    m_sort[l[j][0]].append(l[j][1])
    m_sort[l[j][0]].sort()
for k in m.keys():
    p='0'*(6-len(k))+k
    for h in range(len(m[k])):
        q='0'*(6-len(str(h+1)))+str(h+1)
        key=l.index([k,m[k][h]])
        lab[key]=p+q
for k,v in sorted(lab.items()):
    print(v)

Submission status: Wrong Answer

Solution code:
N, M = map(int,input().split())
PY = [list(map(int,input().split())) + [0] for _ in range(M)]
PY = sorted(PY, key = lambda x: (x[0], x[1]))
d = {}
for py in PY:
  if(py[0] not in d):
    d[py[0]] = 1
  else:
    d[py[0]] += 1
  py[2] = d[py[0]]
for py in PY:
  print(str(py[0]).zfill(6) + str(py[2]).zfill(6))

Submission status: Wrong Answer

Solution code:
import numpy as np

N,M=map(int,input().split())
P=[]
Y=[]
for _ in range(M):
    data=[int(_) for _ in input().split()]
    P.append(data[0])
    Y.append(data[1])

y=[]
for x in range(1,N+1):
    for m in range(M):
        if P[m]==x:
            y.append(Y[m])

    ind=np.array(y)
    ind=ind.argsort()
    for i,k in enumerate(y):
        Y[Y.index(k)]=ind[i]+1
    y=[]

for x in range(M):
    ans=P[x]*1000000+Y[x]
    print("{0:012d}".format(ans))

Submission status: Wrong Answer

Solution code:
import numpy as np

N,M=map(int,input().split())
P=[]
Y=[]
for _ in range(M):
    data=[int(_) for _ in input().split()]
    P.append(data[0])
    Y.append(data[1])

y=[]
for x in range(1,N+1):
    for m in range(M):
        if P[m]==x:
            y.append(Y[m])

    ind=np.array(y)
    ind=ind.argsort()
    for i,k in enumerate(y):
        Y[Y.index(k)]=ind[i]+1
    y=[]

for x in range(M):
    xx=str(P[x])
    yy=str(Y[x])
    print(xx.zfill(6)+yy.zfill(6))

Submission status: Wrong Answer

Solution code:
import numpy

N,M=map(int,input().split())
P=[]
Y=[]
for _ in range(M):
    data=[int(_) for _ in input().split()]
    P.append(data[0])
    Y.append(data[1])

y=[]
for x in range(1,N+1):
    for m in range(M):
        if P[m]==x:
            y.append(Y[m])

    ind=numpy.array(y)
    ind=ind.argsort()
    print(ind)
    for i,k in enumerate(y):
        Y[Y.index(k)]=ind[i]+1
    y=[]

for x in range(M):
    xx=str(P[x])
    yy=str(Y[x])
    print(xx.zfill(6)+yy.zfill(6))

Submission status: Wrong Answer

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

for _ in range(m):
    x,c=(int(i) for i in input().split())
    a[x-1].append(c)
    s.append((x,c))
print(a)
print(s)
[a[i].sort() for i in range(n)]
print(a)
for x,c in s:
    print("{:06}{:06}".format(x, bisect.bisect_left(a[x-1],c)+1))

Submission status: Wrong Answer

Solution code:
# coding:utf-8

def gen_id(n):
    id = ""
    hokan = 6 - len(str(n))
    for _ in range(hokan):
        id += "0"
    id += str(n)
    return id

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

DIC = dict()
NUM_DIC = dict()
for pi in range(1, N+1):
    DIC[pi] = []
    NUM_DIC[pi] = 0

for _ in range(M):
    pi, yi = map(int, input().split())
    DIC[pi].append(yi)
    NUM_DIC[pi] += 1


for pi in range(1, N+1):
    DIC[pi].sort(reverse=True)

counter = 1000000
while True:
    flg = False
    for pi in range(N, 0, -1):
        if NUM_DIC[pi] >= counter:
            flg = True
            id = gen_id(pi) + gen_id(counter)
            print(id)
    counter -= 1
    if counter == 0:
        break

Submission status: Wrong Answer

Solution code:
# coding:utf-8

def gen_id(n):
    id = ""
    hokan = 6 - len(str(n))
    for _ in range(hokan):
        id += "0"
    id += str(n)
    return id

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

DIC = dict()
NUM_DIC = dict()
for pi in range(1, N+1):
    DIC[pi] = []
    NUM_DIC[pi] = 0

for _ in range(M):
    pi, yi = map(int, input().split())
    DIC[pi].append(yi)
    NUM_DIC[pi] += 1


for pi in range(1, N+1):
    DIC[pi].sort(reverse=True)

counter = 1
while True:
    flg = False
    for pi in range(1, N+1):
        if NUM_DIC[pi] >= counter:
            flg = True
            DIC[pi]
            id = gen_id(pi) + gen_id(counter)
            print(id)
    counter += 1
    if flg != True:
        break

Submission status: Wrong Answer

Solution code:
n,m=map(int,input().split())
a=[list(map(int,input().split())) for _ in range(m)]
s=sorted(a,key=lambda x:(x[0],x[1]))
f=s[0][0]
d=1
for i in range(m):
    if s[i][0]==f:
        s[i][1]==d
        d+=1
    else:
        f=s[i][0]
        d=1
        s[i][1]=d
        d+=1

for i in range(m):
    z=str(a[i][0])
    x=str(a[i][1])
    n="0"*(6-len(z)) + z + "0"*(6-len(x)) + x 
    print(n)

Submission status: Wrong Answer

Solution code:
N,M = map(int,input().split())
info = [list(map(int,input().split())) for i in range(M)]
info_new = sorted(info,key=lambda x:(x[0],x[1]))
note = info_new[0][0]
cnt = 1
for i in range(M):
    if info_new[i][0] == note:
        info_new[i][1] = cnt
        cnt += 1
    else:
        note = info_new[i][0]
        cnt = 1
        info_new[i][1] = cnt

for i in range(M):
    pri = str(info[i][0])
    bir = str(info[i][1])
    number = "0"*(6-len(pri)) + pri + "0"*(6-len(bir)) + bir
    print(number)

Submission status: Wrong Answer

Solution code:
N,M = map(int,input().split())
info = [list(map(int,input().split())) for i in range(M)]
info_new = sorted(info,key=lambda x:(x[0],x[1]))
note = info[0][0]
cnt = 1
for i in range(M):
    if info_new[i][0] == note:
        info_new[i][1] = cnt
        cnt += 1
    else:
        note = info_new[i][0]
        cnt = 1
        info_new[i][1] = cnt

for i in range(M):
    pri = str(info[i][0])
    bir = str(info[i][1])
    number = "0"*(6-len(pri)) + pri + "0"*(6-len(bir)) + bir
    print(number)

Submission status: Wrong Answer

Solution code:
N,M = map(int,input().split())
info = [list(map(int,input().split())) for i in range(M)]
info_new = sorted(info,key=lambda x:(x[0],x[1]))
note = 1
cnt = 1
for i in range(M):
    if info_new[i][0] == note:
        info_new[i][1] = cnt
        cnt += 1
    else:
        note = info_new[i][0]
        cnt = 1
        info_new[i][1] = cnt
for i in range(M):
    pri = str(info[i][0])
    bir = str(info[i][1])
    number = "0"*(6-len(pri)) + pri + "0"*(6-len(bir)) + bir
    print(number)

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 n == 0 or (prefec_num != city_lst[n-1][1]):
        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:
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 n == 0 or (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])