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
from collections import deque
stdin = sys.stdin

ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline().rstrip()  # ignore trailing spaces

n, m = na()
buf = [None] * m
cnt = {k: [] for k in range(n + 1)}
for i in range(m):
    p, y = na()
    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:
import sys
from collections import deque
stdin = sys.stdin

ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline().rstrip()  # ignore trailing spaces

n, m = na()
buf = [None] * m
cnt = {k: [] for k in range(n + 1)}
for i in range(m):
    p, y = na()
    cnt[p].append((y, i))
print(cnt)
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:
import numpy as np
N,A= [int(i) for i in input().split()]
n=[]
for i in range(A):
	n.append([int(x) for x in input().split()])
n =np.array(n)
c=n[:,1:].reshape([A]).argsort(axis = 0)
d=np.zeros(N)
e=np.zeros(A)
for i in range(A):
	e[i] = d[n[i][0]-1]+1 		
	d[n[i][0]-1] += 1
for i in range(A):
	print(str(n[i][0]).zfill(6)+str(int(e[c[i]])).zfill(6))

Submission status: Wrong Answer

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

l = []
for i in range(m):
    l.append([int(i) for i in  input().split()])
sort_list = sorted(l,key = lambda x:(x[1],x[0]))

num = 1
cnt = 0
l2 = []
for i in sort_list:
    if i[0] == num:
        cnt += 1
        i.append(cnt)
    else:
        num += 1
        cnt = 1
        i.append(cnt)
        

for j in l:
    for k in sort_list:
        if j[0] == k[0] and j[1] == k[1]:
            print(str(k[0]).zfill(6) + str(k[2]).zfill(6))
        else:
            pass

Submission status: Wrong Answer

Solution code:
n,m=map(int,input().split())
l=[]
for i in range(m):
  p,y=map(int,input().split())
  l.append([y,i,p])
l=sorted(l)
l1=[0 for i in range(n+1)] #県
l2=[[] for i in range(m)] #shi
for i in range(m):
  l1[l[i][2]]+=1
  l2[l[i][1]]=[l1[l[i][2]],l[i][2]]#何番めかとどの市か
for i in range(m):
  w=""
  w+="0"*(6-len(str(l[i][1])))+str(l2[i][1])+"0"*(6-len(str(l[i][0])))+str(l2[i][0])
  print(w)

Submission status: Wrong Answer

Solution code:

import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**6)
##############################

from collections import defaultdict
import heapq

N, M = map(int, input().split())
P = [0] * M
Y = [0] * M
dd = defaultdict(list)

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

    heapq.heappush(dd[p], y)

for i in range(M):
    p = P[i]
    y = Y[i]

    print('{0:06d}'.format(p), end='')
    x = dd[p].index(y) +1
    print('{0:06d}'.format(x))

Submission status: Wrong Answer

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

n, m = list(map(int, input().split()))
py_list = []

for _ in range(m):
    p, y = list(map(int, input().split()))
    py_list.append((p, y))

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

p_no = py_list[0][0]
y_index = 1
no_list = []

for i, py in enumerate(py_list):
    p, y = py

    if p != p_no:
        p_no = p
        y_index = 1

    no = str(p).zfill(6) + str(y_index).zfill(6)
    no_list.append(no)
    y_index += 1


ans = '\n'.join(no_list)
print(ans)

Submission status: Wrong Answer

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

n, m = list(map(int, input().split()))
py_list = []

for _ in range(m):
    p, y = list(map(int, input().split()))
    py_list.append((p, y))

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

p_no = py_list[0][0]
p_index = 1
y_index = 1
no_list = []

for i, py in enumerate(py_list):
    p, y = py

    if p != p_no:
        p_no = p
        p_index += 1
        y_index = 1

    no = str(p_index).zfill(6) + str(y_index).zfill(6)
    no_list.append(no)
    y_index += 1


ans = '\n'.join(no_list)
print(ans)

Submission status: Wrong Answer

Solution code:
import bisect

n, m = map(int, input().split())
py_dict = {}
cityi_by_year = []
for i in range(m):
  p, y = map(int, input().split())
  if p not in py_dict:py_dict[p] = [y]
  else:py_dict[p].append(y)
  cityi_by_year.append([p,y])

for p, y in cityi_by_year:
  idx = bisect.bisect_left(py_dict[p],y)
  print('0'*(6-len(str(p))) + str(p) + '0'*(6-len(str(idx+1))) + str(idx+1))

Submission status: Wrong Answer

Solution code:
N,M = map(int,input().split())
S = []
d = {}

for i in range(M):
    p,y = map(str,input().split())
    s = "0"*(6-len(p)) + p + "0"*(10-len(y)) + y
    S.append(s)


for i in range(M):
    l = str(i+1)
    s = S[i][:6]
    if s in d:
        d[s] += 1
    else:
        d[s] = 0
    S[i] = s + "0"*(6-len(l)) + str(d[s]+1)

for i in range(M):
    l = str(i+1)
    s = S[i][:6]
    if s in d:
        S[i] = s + "0"*(6-len(l)) + str(d[s]+1)
        d[s] -= 1
    print(S[i])

Submission status: Wrong Answer

Solution code:
N,M = map(int,input().split())
S = []
d = {}

for i in range(M):
    p,y = map(str,input().split())
    s = "0"*(6-len(p)) + p + "0"*(10-len(y)) + y
    S.append(s)

for i in range(M):
    l = str(i+1)
    s = S[i][:6]
    if s in d:
        d[s] += 1
    else:
        d[s] = 0
    S[i] = s + "0"*(6-len(l)) + str(d[s]+1)
    print(S[i])

Submission status: Wrong Answer

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

for i in range(M):
    p,y = map(str,input().split())
    s = "0"*(6-len(p)) + p + "0"*(10-len(y)) + y
    S.append(s)

S.sort()

for i in range(M):
    l = str(i+1)
    S[i] = S[i][:6] + "0"*(6-len(l)) + l
    print(S[i])

Submission status: Wrong Answer

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

for i in range(M):
    p,y = map(str,input().split())
    s = "0"*(6-len(p)) + p + "0"*(6-len(y)) + y
    S.append(s)

S.sort()

for i in range(M):
    l = str(i+1)
    S[i] = S[i][:6] + "0"*(6-len(l)) + l
    print(S[i])

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
n,m=map(int,input().split())
lst=[]
for i in range(m):
  P,Y=map(int,input().split())
  lst.append([P,Y])
lst.sort(key=lambda x:(x[0],x[1]))
lst[0][1]=1
for j in range(m-1):
  if lst[j][0]==lst[j+1][0]:
    lst[j+1][1]=lst[j][1]+1
  else:
    lst[j+1][1]=1

for k in range(m):
  print(str(lst[k][0])+str(lst[k][1]))

Submission status: Wrong Answer

Solution code:
# 見かけたのでやる
# やるだけ
# インプットの順番をidで保存しておいてpでソートしてyでソートしてidでソートして復元
n, m = map(int, input().split())
arr = []
for i in range(m):
    p, y = map(int, input().split())
    arr.append([i, p, y])

arr = list(sorted(arr, key=lambda x: x[1]))
arr = list(sorted(arr, key=lambda x: x[2]))
flag = -1
count = 1
for a in arr:
    if a[1] != flag:
        flag = a[1]
        count = 1
    a[2] = "%06d" % count
    a[1] = "%06d" % a[1]
    count += 1
arr = list(sorted(arr, key=lambda x: x[0]))
for a in arr:
    print("{}{}".format(a[1], a[2]))

Submission status: Wrong Answer

Solution code:
"""
2 3
1 32
2 63
1 12

000001000002
000002000001
000001000001



2 3
2 55
2 77
2 99

000002000001
000002000002
000002000003
"""


first = list(map(int, input().split()))
ken_shi_dict = {}
c = 0
for i in range(first[1]):
    c += 1
    ken_year = input().split()
    ken = ken_year[0]
    year = ken_year[1]
    if ken in ken_shi_dict:
        ken_shi_dict[ken].append([year, c])
    else:
        ken_shi_dict[ken] = [[year, c]]

answer_dict = {}
sorted_ken = sorted(ken_shi_dict.keys())
for i in sorted_ken:
    count = 1
    ken_number = str(i).zfill(6)
    ken_shi_dict[i].sort(key=lambda x: x[0])
    for j in ken_shi_dict[i]:
        year_number = str(count).zfill(6)
        count += 1
        print_str = ken_number + year_number
        answer_dict[j[1]] = print_str

for i in sorted(answer_dict.keys()):
    print(answer_dict[i])

Submission status: Wrong Answer

Solution code:
from collections import defaultdict
n,m = map(int,input().split())
d = defaultdict(list)
for i in range(m):
  p,y = map(str,input().split())
  p = '0' * (6-len(p)) + p
  d[p].append([y,i])
ans = [0] * m
for p in d:
  c = 0
  dp = d[p]
  for t in sorted(dp):
    c += 1
    ans[t[1]] = p + '0' * (6-len(str(c))) + str(c)
print('\n'.join(ans))

Submission status: Wrong Answer

Solution code:
n, m = map(int, input().split())
py_array = [[int(x) for x in input().split()] for y in range(m)]
py_dict = {x: y for x, y in enumerate(py_array, 1)}
py = sorted(py_dict.items(), key=lambda x: x[1][1])
ans = {}
now = min([x[0] for x in py_array])
index = 0
for key, value in py:
    if now != value[0]:
        index = 1
    else:
        index += 1
    ken = str(value[0])
    si = str(index)
    ans[key] = ken.zfill(6) + si.zfill(6)
for key, value in ans.items():
    print(value)

Submission status: Wrong Answer

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

for i in range(len(pLst)):
    pLst[i].append(i)
nLst = [''] * N

for i in range(N):
    nLst[i] = str(i + 1).zfill(6)
tLst = sorted(pLst, key=lambda x: (x[0], x[1]))
ansLst = [''] * M
tmp = nLst[tLst[0][0] - 1]
index = 1
for i in range(M):
    if tmp == nLst[tLst[i][0] - 1]:
        ansLst[tLst[i][2]] = nLst[tLst[i][0] - 1] + str(index).zfill(6)
        index += 1
    else:
        index = 1
        tmp == nLst[tLst[i][0] - 1]
        ansLst[tLst[i][2]] = nLst[tLst[i][0] - 1] + str(index).zfill(6)
        index += 1

for i in ansLst:
    print(i)

Submission status: Wrong Answer

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

for i in range(len(pLst)):
    pLst[i].append(i)
nLst = [''] * N

for i in range(N):
    nLst[i] = str(i + 1).zfill(6)
tLst = sorted(pLst, key=lambda x: (x[0], x[1]))
ansLst = [''] * M
tmp = nLst[tLst[0][0] - 1]
index = 1
for i in range(M):
    if tmp == nLst[tLst[i][0] - 1]:
        ansLst[tLst[i][2]] = nLst[tLst[i][0] - 1] + str(index).zfill(6)
        index += 1
    else:
        index = 1
        tmp == nLst[tLst[i][0] - 1]
        ansLst[tLst[i][2]] = nLst[tLst[i][0] - 1] + str(index).zfill(6)

for i in ansLst:
    print(i)

Submission status: Wrong Answer

Solution code:
pre_n, city_n = map(int, input().split())
cities = [list(map(int, input().split())) for x in range(city_n)]

history = {}

A = {}

print(sorted(cities))

for x in sorted(cities):
    pref = str(x[0])
    if pref not in history:
        history[pref] = '1'

    A.setdefault(str(x), '0'*(6-len(pref)) + pref + '0'*(6-len(history[pref])) + history[pref])

    history[pref] = str(int(history[pref]) + 1)

for x in cities:
    print(A[str(x)])

Submission status: Wrong Answer

Solution code:
pre_n, city_n = map(int, input().split())
cities = [list(map(str, input().split())) for x in range(city_n)]

history = {}

A = {}

for x in sorted(cities):
    pref = x[0]
    if pref not in history:
        history[pref] = '1'

    A.setdefault(str(x), '0'*(6-len(pref)) + pref + '0'*(6-len(history[pref])) + history[pref])

    history[pref] = str(int(history[pref]) + 1)

for x in cities:
    print(A[str(x)])

Submission status: Wrong Answer

Solution code:
n, m = map(int, input().split())
p, y = [0] * m, [0] * m
sort_year = [0] * m
initial_index, count_city = [0] * n, [0] * n
tmp_counter = [0] * n 
for i in range(m):
    p[i], y[i] = map(int, input().split())
    count_city[p[i] - 1] += 1
for j in range(1, n):
  	initial_index[j] = initial_index[j - 1] + count_city[j - 1]
for i in range(m):
    sort_year[initial_index[p[i] - 1] + tmp_counter[p[i] - 1]] = y[i]
    tmp_counter[p[i] - 1] += 1
for j in range(n):
    sort_year[initial_index[j] : initial_index[j] + count_city[j - 1]] = sorted(sort_year[initial_index[j] : initial_index[j] + count_city[j - 1]])
for i in range(m):
    x = sort_year.index(y[i]) - initial_index[p[i] - 1] + 1
    print(str(p[i]).zfill(6) + str(x).zfill(6))

Submission status: Wrong Answer

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

city = [[] for _ in range(n+1)]
arr = []

for i in range(m):
    s,t = map(int,input().split())
    city[s].append(t)
    arr.append((s,t))
    
for i in range(m):
    x = str(arr[i][0])
    y = str(city[int(x)].index(arr[i][1]))
    print(x.rjust(6, "0") + y.rjust(6,"0"))

Submission status: Wrong Answer

Solution code:
N,M = map(int,input().split())
prefecture = [[] for i in range(N+1)]
ans = []
for i in range(M):
    p,y = map(int,input().split())
    prefecture[p].append([y,i])
    prefecture[p].sort()
for i in range(1,N+1):#iは県の番号
    tmp_p = str(i)
    while(len(tmp_p)!=6):
         tmp_p = '0'+tmp_p
    for j in range(1,len(prefecture[i])+1):#jは何番目か，すなわちx
        tmp_x = str(j)
        while (len(tmp_x)!=6):
            tmp_x = '0'+tmp_x
        ans.append([prefecture[i][j-1][1],tmp_p+tmp_x])
ans.sort()
print(prefecture)
print(ans)
for i in range(len(ans)):
    print(ans[i][1])

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline
N, Q = map(int, input().split())
town = [[] for _ in range(N)]
for i in range(Q):
    place, year = map(int, input().split())
    tmp = [0,0]
    tmp[0] = year
    tmp[1] = i
    town[place-1].append(tmp)

print(town)

ans = []

for item in town:
    index = town.index(item)
    print(item)
    item.sort()
    index += 1
    index = str(index)
    while len(index) < 6:
        index = '0' + index
    for i in range(len(item)):
        num = i + 1
        num = str(num)
        while len(num) < 6:
            num = '0' + num
        xxx = index + num
        tmp = []
        tmp.append(item[i][1])
        tmp.append(xxx)
        ans.append(tmp)

ans.sort()
for item in ans:
    print(item[1])