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: Accepted

Solution code:
n, m = map(int, input().split())
py = [list(map(int, input().split()))+[i+1] for i in range(m)]
py = sorted(py, key = lambda x: x[1])

ans = [0]*m
prefecs = [1]*(n+1)
for i, (p, y, j) in enumerate(py):
    top = p
    under = prefecs[p]
    ans[i] = (str(top).zfill(6)+str(under).zfill(6), j)
    prefecs[p] += 1

ans = sorted(ans, key = lambda x: x[1])
for i in range(m):
    print(ans[i][0])

Submission status: Accepted

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

memo = [list() for _ in range(N)]

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

for l in memo:
  l.sort()

result = [None]*M

for p,l in enumerate(memo):
  for i,(_,orig) in enumerate(l):
    result[orig] = '%06d%06d' % (p+1,i+1)

for s in result:
  print(s)

Submission status: Accepted

Solution code:
N, M = map(int, input().split())
PY = [tuple([int(x) for x in input().split()]) for _ in range(M)]

d = dict()
cp = 0
n = 1
for p,y in sorted(PY):
    if p != cp:
        cp = p
        n = 1
    d[(p, y)] = n
    n += 1

for p, y in PY:
    print("%06d%06d" % (p, d[(p,y)]))

Submission status: Accepted

Solution code:
import sys
fin = sys.stdin.readline
from collections import defaultdict


N, M = [int(elem) for elem in fin().split()]
pref_years = [[int(elem) for elem in fin().split()] for _ in range(M)]
formatter = lambda x: "{:06}".format(x)

# sort by year in ascending order
sorted_pref_years = sorted(pref_years, key=lambda x: x[1])
number_cities_per_city = defaultdict(int)
identity_numbers = {}
for pref, year in sorted_pref_years:
    number_cities_per_city[pref] += 1
    identity_numbers[year] = formatter(pref) \
                           + formatter(number_cities_per_city[pref])

for _, year in pref_years:
    print(identity_numbers[year])

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n, m = map(int, input().split())
pref = [[] for _ in range(n)]
p_list = [[] for _ in range(m)]
y_to_num = dict()
for i in range(m):
	p, y = map(int, input().split())
	pref[p-1].append([y, i])
	p_list[i] = [p, y]
for i in range(n):
	pref[i] = sorted(pref[i])
#ans = [[] for _ in range(m)]

for i in range(n):
	for j in range(len(pref[i])):
		y_to_num[pref[i][j][0]] = j+1

for i in range(m):
	print(str(10 ** 12 + (10 ** 6) * p_list[i][0] + y_to_num[p_list[i][1]])[1:])

Submission status: Accepted

Solution code:
from operator import itemgetter

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

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

PY.sort()

#print(PY)

no=1
PY[0][1]=1
no=2
for i in range(1,m):
    if PY[i-1][0]!=PY[i][0] :
        no=1
    PY[i][1]=no
    no+=1

PY.sort(key=itemgetter(2))

#print(PY)

for i in range(m):
    aa=str('%06d'%PY[i][0])
    bb=str('%06d'%PY[i][1])
    print(aa+bb)

Submission status: Accepted

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

A = []
for i in range(M):
  A.append([i] + list(map(int, input().split())) + ["x"])

A.sort(key=itemgetter(1,2))

keynum, count = 0, 1
for i in range(M):
  if keynum != A[i][1]:
    keynum = A[i][1]
    count = 1
  else:
    count += 1
    
  A[i][3] = str(keynum).zfill(6) + str(count).zfill(6)
  
A.sort(key=itemgetter(0))
for i in range(M):
  print(A[i][3])

Submission status: Accepted

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

B = A[:]
A.sort()
cnt = 0
prev = 0
ans = dict()

for p, y in A:
    if prev != p:
        cnt = 1
        prev = p
    ans[(p, y)] = '{0:06d}{1:06d}'.format(p, cnt)
    cnt += 1

for p, y in B:
    print(ans[(p, y)])

Submission status: Accepted

Solution code:
from bisect import bisect
from collections import defaultdict
N, M = map(int, input().split())
Y = defaultdict(list)
P = set()
PY = []
for i in range(M):
    Pi, Yi = map(int, input().split())
    Y[Pi].append(Yi)
    P.add(Pi)
    PY.append([Pi,Yi])

for p in P:
    Y[p].sort()


for pi, yi in PY:
    i = bisect(Y[pi],yi)
    id = '%06d%06d'%(pi,i)
    print(id)

Submission status: Accepted

Solution code:
n,m = (int(i) for i in input().split())
x,v,z = [],[0]*n,[None]*m
for i in range(m):
	p,y = (int(i) for i in input().split())
	x.append([p-1,y,i])
x.sort()
for i in range(m):
	s,t = len(str(x[i][0]+1)),len(str(v[x[i][0]]+1))
	z[x[i][2]] = "0"*(6-s)+str(x[i][0]+1)+"0"*(6-t)+str(v[x[i][0]]+1)
	v[x[i][0]]+=1
for i in z: print(i)

Submission status: Accepted

Solution code:
n,m = map(int,raw_input().split())
ind = [[] for i in range(n+1)]
ans = [0]*(m+1)
for i in range(m):
	a,b = map(int,raw_input().split())
	ind[a].append((b,i+1))
# print ind[:4]
for i in range(1,n+1):
	ind[i].sort()
	for j in range(len(ind[i])):
		aa = str(i)
		bb = str(j+1)
		val = "0"*(6-len(aa))+aa+"0"*(6-len(bb))+bb
		ans[ind[i][j][1]] = val
for i in range(1,m+1):
	print ans[i]

Submission status: Accepted

Solution code:
from sys import stdin, stdout

n, m = map(int, raw_input().strip().split())
inp = stdin.readlines()
out = [0 for i in xrange(m)]

pos = {}
dos = [[] for i in xrange(n + 1)]
for i in xrange(m):
    p, y = map(int, inp[i].strip().split())
    pos[(p, y)] = i
    dos[p].append(y)

for i in xrange(n + 1):
    if dos[i]: dos[i].sort()

for i in xrange(n + 1):
    for j in xrange(len(dos[i])):
        pre = str(i).zfill(6)
        suf = str(j + 1).zfill(6)
        sad = pre + suf
        out[pos[(i, dos[i][j])]] = sad

stdout.write("\n".join(out))

Submission status: Accepted

Solution code:
n,m=map(int,input().split())
dict1={}
dict2={}
for i in range(m):
    x,y=map(int,input().split())
    try:
        dict1[x].append([y,i+1])
    except:
        KeyError
        dict1[x]=[[y,i+1]]
ansarr=["0"]*m
for i in dict1.keys():
    dict1[i].sort()
    s1=(6-len(str(i)))*'0'+str(i)
    for j in range(len(dict1[i])):
        s2=(6-len(str(j+1)))*'0'+str(j+1)
        #print(dict1[i][j][1])
        ansarr[dict1[i][j][1]-1]=s1+s2
for i in range(m):
    print(ansarr[i])

Submission status: Accepted

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

PYI=[PY[i]+[i] for i in range(M)]

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

Nu=[1]*(N+1)
ANS=[None]*M

for p,y,i in PYI:
    ANS[i]=(p,Nu[p])
    Nu[p]+=1

#print(ANS)

def numb(x,y):
    x=str(x)
    y=str(y)
    l=len(x)
    m=len(y)

    return (6-l)*"0"+x+(6-m)*"0"+y

for a,b in ANS:
    print(numb(a,b))

Submission status: Accepted

Solution code:
#! /usr/bin/env python
# -*- coding: utf-8 -*-
# vim:fenc=utf-8
#

"""
abc113 C
"""

# from collections import defaultdict

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

perflist = [[] for i in range(n+1)]
ans = ["" for i in range(m+1)]

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

for i in range(1, n+1):
    perflist[i].sort(key=lambda x: x[1])

for p in range(1, n+1):
    for i, (c, _) in enumerate(perflist[p]):
        ans[c] = '{0:06d}'.format(p) + '{0:06d}'.format(i+1)

for c in range(1, m+1):
    print(ans[c])

Submission status: Accepted

Solution code:
import bisect

def main():
    n, m = map(int, input().split())
    cities = []
    bucket = [[] for _ in range(n + 1)]

    for _ in range(m):
        p, y = map(int, input().split())
        bucket[p].append(y)
        cities.append((p, y))

    for i in range(1, n + 1):
        bucket[i].sort()

    for p, y in cities:
        n = bisect.bisect_left(bucket[p], y) + 1
        print('%06d%06d' % (p, n))

main()

Submission status: Accepted

Solution code:
N, M = map(int, input().split())
P = [1] * N
C = [''] * M
PY = [[] for i in range(M)]
for i in range(M):
  p, y = map(int, input().split())
  PY[i] = [y, p, i]
PY.sort()
for y, p, i in PY:
  C[i] = ('0' * 6 + str(p))[-6:] + ('0' * 6 + str(P[p - 1]))[-6:]
  P[p - 1] += 1
for c in C:
  print(c)

Submission status: Accepted

Solution code:
n,m = map(int,raw_input().split())
pre = [[] for i in xrange(n)]
ans = ['' for i in xrange(m)]
for i in xrange(m):
	p,y = map(int,raw_input().split())
	p -= 1
	pre[p].append((y,i))
for i in xrange(n):
	pre[i].sort()
	s = str(i+1)
	s = '0'*(6-len(s)) + s
	for j in xrange(len(pre[i])):
		x = str(j+1)
		x = (6-len(x))*'0' + x
		ans[pre[i][j][1]] = s+x
for a in ans:
	print a

Submission status: Accepted

Solution code:
import sys
stdin = sys.stdin

sys.setrecursionlimit(10**5)

def li(): return map(int, stdin.readline().split())
def li_(): return map(lambda x: int(x)-1, stdin.readline().split())
def lf(): return map(float, stdin.readline().split())
def ls(): return stdin.readline().split()
def ns(): return stdin.readline().rstrip()
def lc(): return list(ns())
def ni(): return int(stdin.readline())
def nf(): return float(stdin.readline())

n,m = li()
py = []
for _ in range(m):
    py.append(list(li()))

order = [{} for _ in range(n+1)]
cnt = [0]*(n+1)

for p,y in sorted(py, key=lambda x:x[1]):
    order[p].update({y: cnt[p]})
    cnt[p] += 1


for p,y in py:
    cnt[p] += 1
    ans = str(p).zfill(6) + str(order[p][y]+1).zfill(6)
    print(ans)

Submission status: Accepted

Solution code:
N, M = map(int, input().split())
ken = [[] for _ in range(N)]
for i in range(1, M + 1):
    p, y = map(int, input().split())
    ken[p - 1].append((y, i))
ans = [0] * M
for k, li in enumerate(ken, 1):
    for i, (_, p) in enumerate(sorted(li), 1):
        ans[p - 1] = str(k).zfill(6) + str(i).zfill(6)
for x in ans:
    print(x)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
from collections import defaultdict
def inpl(): return list(map(int, input().split()))
N, M = inpl()
A = [""]*M
P = [[] for _ in range(N+1)]
for i in range(M):
    p, y = inpl()
    P[p].append((y, i))

for p, prefecture in enumerate(P):
    prefecture = sorted(prefecture, key=lambda x: x[0])
    for j, (y, i) in enumerate(prefecture):
        A[i] = "{}{}".format(str(p).zfill(6), str(j+1).zfill(6))

print(*A, sep="\n")

Submission status: Accepted

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

ans = [""] * M
for i in range(N):
    G[i] = sorted(G[i])
    j = 1
    for y, k in G[i]:
        ans[k] = "0" * (6 - len(str(i + 1))) + str(i + 1) + "0" * (6 - len(str(j))) + str(j)
        j += 1

for k in ans:
    print(k)

Submission status: Accepted

Solution code:
from collections import defaultdict

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

ken_dict = defaultdict(list)

for _ in range(m):
    p, y = list(map(int, input().split()))
    ps.append(p)
    ys.append(y)
    ken_dict[p].append(y)

n_dict = {}

for key in ken_dict:
    ken_dict[key].sort()
    for i, value in enumerate(ken_dict[key]):
        n_dict[(key, value)] = 1 + i

for i in range(m):
    print(str(ps[i]).zfill(6) + str(n_dict[ps[i], ys[i]]).zfill(6))

Submission status: Accepted

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

nums = [1] * (N + 1)
PY.sort(key=lambda x:x[2])

for row in PY:
    y = row[1]
    row[3] = nums[y]
    nums[y] += 1

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

for row in PY:
    print("%06d%06d" % (row[1], row[3]))

Submission status: Accepted

Solution code:
n,m=map(int,input().split())
py=[list(map(int,input().split())) for _ in range(m)]
res=[[] for _ in range(n)]
for i in range(m):
    res[py[i][0]-1].append(py[i][1])
for i in range(n):
    res[i].sort()
import bisect
for p,y in py:
    t=bisect.bisect_left(res[p-1],y)
    ans=str(1000000+p)[1::]+str(1000000+t+1)[1::]
    print(ans)

Submission status: Accepted

Solution code:
N, M = map(int, input().split())
PY = [list(map(int, input().split())) + [i] for i in range(M)]
PY = sorted(PY, key=lambda x: x[1])
ans = []
cnt = [0]*N
for p, y, i in PY:
    ans.append(["%06d%06d" % (p, cnt[p - 1] + 1), i])
    cnt[p - 1] += 1
ans = sorted(ans, key=lambda x: x[1])
for a, i in ans:
    print(a)

Submission status: Accepted

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

cities = [[] for i in range(N+1)]
for i,(p,y) in enumerate(src):
    cities[p].append((y,i))

anss = [None]*M
for p in range(N+1):
    for i,(y,_) in enumerate(sorted(cities[p])):
        ans = str(p).zfill(6) + str(i+1).zfill(6)
        anss[_] = ans

print(*anss, sep=('\n'))

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
#!/usr/bin/env python

from collections import deque
import itertools as it
import sys
import math

sys.setrecursionlimit(1000000)

INF = 10 ** 18
MOD = 10 ** 9 + 7

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

ls = []
for i in range(M):
    P, Y = map(int, raw_input().split())
    ls.append((P, Y, i))

ans = [0] * M

ls.sort()

P_pre = -1
cnt = 1
for P, Y, i in ls:
    if P == P_pre:
        cnt += 1
    else:
        cnt = 1
    S1 = '%06d' % P
    S2 = '%06d' % cnt
    ans[i] = S1 + S2
    P_pre = P

for S in ans:
    print S

Submission status: Accepted

Solution code:
N, M = map(int, input().split())
D = [[] for i in range(N)]
for i in range(M):
    p, y = map(int, input().split())
    D[p-1].append((y, i))
ans = [None]*M
for i, d in enumerate(D):
    d.sort()
    for k, (y, j) in enumerate(d):
        ans[j] = "%06d%06d" % (i+1, k+1)
print(*ans, sep='\n')

Submission status: Accepted

Solution code:
import sys

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()
pys = []
for i in range(m):
    x = na()
    x = [x[0], x[1], i]
    pys.append(x)

pys.sort()
pp = -1
lid = 0
ans = [0] * m
for i in range(m):
    if pys[i][0] == pp:
        lid += 1
    else:
        lid = 1
    ans[pys[i][2]] = pys[i][0] * 1000000 + lid
    pp = pys[i][0]
for v in ans:
    print("{:012d}".format(v))

Submission status: Accepted

Solution code:
N,M = map(int, raw_input().split())
YP = [None]*M
for i in range(M):
  P, Y = map(int, raw_input().split())
  YP[i] = (Y,P,i)
YP.sort()
C = [0]*(N+1)
code = [""]*M
for j in range(M):
  Y,P,i = YP[j]
  C[P] += 1
  code[i] = "%06d%06d"%(P, C[P])
for c in code:
  print c

Submission status: Runtime Error

Solution code:
import collections
import bisect
n,m=map(int,input().split())
p = [map(int,input().splilt()) for i in range(m)]
a=collections.defaultdict(list)
for x,y in sorted(p):
    a[x]+=[y]
for x,y in p:
    z=bisect.bisect(a[x],y)
    print("%06d%06d"%(x,z))

Submission status: Runtime Error

Solution code:
import collections
import bisect
n,m=map(int,input().split())
p = [list(map(int,input().splilt())) for i in range(m)]
a=collections.defaultdict(list)
for x,y in sorted(p):
    a[x]+=[y]
for x,y in p:
    z=bisect.bisect(a[x],y)
    print("%06d%06d"%(x,z))

Submission status: Runtime Error

Solution code:
import collections
import bisect
n,m = map(int,input().split())
p = [list(map(int,input().splilt())) for i in range(m)]
a = collections.defaultdict(list)
for x,y in sorted(p):
  a[x]+=[y]
for x,y in p:
  z = bisect.bisect(a[x],y)
  print("%06d%06d"%(x,z))

Submission status: Runtime Error

Solution code:
import collections
import bisect
n,m = map(int,input().split())
p = [list(map(int,input().splilt())) for i in range(m)]
a = collections.deefaultdict(list)
for x,y in sorted(p):
  a[x]+=[y]
for x,y in p:
  z = bisect.bisect(a[x],y)
  print("%06d%06d"%(x,z))

Submission status: Runtime Error

Solution code:
def mapt(fn, *args):
    return tuple(map(fn, *args))


def Input():
    return mapt(int, input().split(" "))
  

def main():
    n, m = Input()
    YP = [None] * m
    for i in range(m):
        p, y = Input()
        YP[i] = (y, p, i)
    YP.sort()
    counter = [0] * m
    result = [""] * m

    for y, p, i in YP:
        counter[p] += 1
        result[i] = f"{p:06d}{counter[p]:06d}"

    for i in result:
        print(i)
        
        
main()

Submission status: Runtime Error

Solution code:
n,m = map(int, input().split())
p = []*m
y = []*m
for i in range(m):
    p[i],y[i] = int(input().split())
py = []*m
for i in range(m):
    py[i] = [i,p[i],[y[i]]]
pysort = sorted(py, key = lambda py:py[2])
code = []*m
c = []*n
for j in range(m):
    i, p, y = py[j]
    c[p] += 1
    code[i] = "%06d%06d"%(p,c[p])
for i in range(m):
    print(code[i])

Submission status: Runtime Error

Solution code:
# coding=utf-8
from math import floor, ceil, sqrt, factorial, log, gcd
from itertools import accumulate, permutations, combinations, product, combinations_with_replacement
from bisect import bisect_left, bisect_right
from collections import Counter, defaultdict
from heapq import heappop, heappush, heappushpop, heapify
import copy
import numpy as np
import sys
INF = float('inf')
mod = 10**9+7
sys.setrecursionlimit(10 ** 6)


def lcm(a, b): return a * b / gcd(a, b)

# 1 2 3
# a, b, c = LI()


def LI(): return list(map(int, sys.stdin.buffer.readline().split()))

# a = I()


def I(): return int(sys.stdin.buffer.readline())

# abc def
# a, b = LS()


def LS(): return sys.stdin.buffer.readline().rstrip().decode('utf-8').split()

# a = S()


def S(): return sys.stdin.buffer.readline().rstrip().decode('utf-8')

# 2
# 1
# 2
# [1, 2]


def IR(n): return [I() for i in range(n)]

# 2
# 1 2 3
# 4 5 6
# [[1,2,3], [4,5,6]]


def LIR(n): return [LI() for i in range(n)]

# 2
# abc
# def
# [abc, def]


def SR(n): return [S() for i in range(n)]

# 2
# abc def
# ghi jkl
# [[abc,def], [ghi,jkl]]


def LSR(n): return [LS() for i in range(n)]

# 2
# abcd
# efgh
# [[a,b,c,d], [e,f,g,h]]


def SRL(n): return [list(S()) for i in range(n)]


def main():
    n, m = LI()
    # py = LIR(m)
    lst = [[] for i in range(n)]
    for i in range(m):
        p, y = map(int, input().split())
        lst[p - 1].append(y)

    for i in range(n):
        if len(lst[i]) > 1:
            lst[i].sort()

    for pair in py:
        print(str(pair[0]*1000000+lst[pair[0]-1].index(pair[1])+1).zfill(12))


if __name__ == "__main__":
    main()

Submission status: Runtime Error

Solution code:
N, M = map(int, input().split())
P = [[0, 0] for _ in range(M)] 
Y = [0] * M
for i in range(M):
  P[i][:] = map(int, input().split())

indices = [*range(M)]
sorted_indices = sorted(indices, key=lambda i: P[1])
P = [P[i] for i in sorted_indices]

order = [0] * N
Number = [0] * M

def fill(n):
  n_str = str(n)
  return '0' * (6 - len(n_str)) + n_str 
  
for i in range(M):
  order[P[i][0] - 1] += 1
  Number[i] = fill(P[i][0]) + fill(order[P[i][0] - 1])

Number = sorted(Number, key=lambda i: sorted_indices)
for i in range(M):
  print(Number[i])

Submission status: Runtime Error

Solution code:

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

res = [""] * M
ctr = [0] * (M + 1)
for i, (p, y) in sorted(enumerate(X), key=lambda x: (x[1][0], x[1][1])):
    ctr[p] += 1
    res[i] = "{:0>6}{:0>6}".format(p, ctr[p])

print(*res, sep="\n")

Submission status: Runtime Error

Solution code:
N = int(input())
T, A = map(int, input().split())
H = list(map(int, input().split()))
ans = 0
m = A
for i in range(N):
  if m > abs(0.1 * T - H[i] * 0.006 - 0.1 * A):
    m = abs(0.1 * T - H[i] * 0.006 - 0.1 * A)
    ans = i + 1
print(ans)

Submission status: Runtime Error

Solution code:
from collections import defaultdict
from bisect import bisect
n,m=map(int,input().split())
l=[list(map(int,input().split()) for _ in range(m))]
a=defaultdict(list)
for x,y in sorted(l):
    a[x]+=[y]

for x,y in l:
    z=bisect(a[x],y)
    print('%06d%06d'%(x,z))

Submission status: Runtime Error

Solution code:
from operator import itemgetter

n, m = map(int, input().split())
yp = []
for i in range(m):
  p_, y_ = map(int, input().split())
  yp.append([y_, p_, i+1])
py = sorted(yp)
ken = [0]*m
res = []
for i in range(m):
  ken[py[i][1]] += 1
  p, q, r = py[i][1], ken[py[i][1]], py[i][2]
  res.append([p, q, r])
#print(yp)
#print(py)

res.sort(key=itemgetter(2))
#print(res)
for i in range(m):
  ans1 = [0]*(6-len(str(res[i][0])))
  ans1.append(res[i][0])
  ans2 = [0]*(6-len(str(res[i][1])))
  ans2.append(res[i][1])
  print(*ans1, *ans2, sep='')

Submission status: Runtime Error

Solution code:
n,m=map(int,input().split())
x=[]
y=[]
for i in range(m):
    a,b=map(int,input().split())
    x.append([a,b,i])
x.sort()
s=1
for i in range(m):
    c=x[i][0]
    if len(str(x[i][0]))<6:
        a=6-len(str(x[i][0]))
        b=["0"]*a
        for j in range(len(str(x[i][0]))):
            b.append(str(x[i][0])[j])
        x[i][0]="".join(b)
    if len(str(s))<6:
        a=6-len(str(s))
        b=["0"]*a
        for j in range(len(str(s))):
            b.append(str(s)[j])
        x[i].append("".join(b))
    if i<m-1:
        if c==x[i+1][0]:
            s+=1
        else:
            s=1
for i in range(m):
    y.append([x[i][2],x[i][0],x[i][3]])
y.sort()
for i in range(m):
    print(y[i][1]+y[i][2])

Submission status: Runtime Error

Solution code:

NN, MM = list(map(int,input().split()))
nofcity = 0
data = [[0,0]]*MM
pref = [[100001]*MM for i in range(NN)]
prefindex = [0] * NN
while True:
    try:
        i = list(map(int, input().split()))
        data[nofcity] = i
        pref[i[0] - 1][prefindex[i[0]-1]] = i[1]
        prefindex[i[0]-1] += 1
        nofcity += 1
    except EOFError:
        break

for j in range(NN):
    pref[j].sort()

for k in range(len(data)):
    print("{:06d}".format(int(data[k][0])),"{:06d}".format(pref[data[k][0]-1].index(data[k][1])+1),sep="")

#print(pref)

Submission status: Runtime Error

Solution code:
n,m=map(int,input().split())
py=[]
for i in range(m):
    py.append(list(map(int,input().split()))+[i+1])
py.sort()
number_list=[]
number_list.append([str(0)]*(6-(len(list(str(py[0][0])))))+list(str(py[0][0]))+[str(0)]*(6-(len(list(str(1)))))+list(str(1))+[str(py[0][-1])])
k=2
for j in range(1,m):
    if py[j][0]==py[j-1][0]:
        number_list.append([str(0)]*(6-(len(list(str(py[j][0])))))+list(str(py[j][0]))+[str(0)]*(6-(len(list(str(k)))))+list(str(k))+[str(py[j][-1])])    
        k+=1
    else:
        k=1
        number_list.append([str(0)]*(6-(len(list(str(py[j][0])))))+list(str(py[j][0]))+[str(0)]*(6-(len(list(str(k)))))+list(str(k))+[str(py[j][-1])])
        k+=1
number_list_sort=sorted(number_list,key=lambda x:x[-1])
for l in range(m):
    print(''.join(number_list_sort[l][:-1])

Submission status: Runtime Error

Solution code:
# 初期入力
import sys
input = sys.stdin.readline  #文字列では使わない
Ken_n,City_n = (int(i) for i in input().split())
city ={i:[] for i in range(1,City_n+1)}
for i in range(1,City_n+1):
    p,y = (int(i) for i in input().split())
    city[p].append((y,i))

city_ID ={i:0 for i in range(1,City_n +1)}
for i in range(1,Ken_n +1):
    city[i].sort()
    for j in range(len(city[i])):
        city_ID[city[i][j][1]] = "{0:06d}".format(i) +"{0:06d}".format(j+1)

for i in range(1,City_n +1):
    print(city_ID[i])

Submission status: Runtime Error

Solution code:
n,m=map(int,input().split())
p=[]
pp=[1]
pp*=n
ans=[]
for i in range(n):
    p.append([])
for i in range(m):
    pi,yi=map(int,input().split())
    p[pi-1].append([yi,pp[pi-1]])
    ans.append([pi-1,pp[pi-1]])
    pp[pi-1]+=1
    print(p)
for i in range(n):
    p[i].sort()
for i in range(m):
    b=len(p[ans[i][0]])
    for j in range(b):
        if ans[i][1]==p[ans[i][0]][j][1]:
            print('{0:06d}{1:06d}'.format(ans[i][0]+1,j+1))
            break

Submission status: Runtime Error

Solution code:
import numpy as np

N,M=map(int,input().split())
F=np.zeros((N+1,10**9+1),dtype=bool)
PY=[]
 
for _ in range(M):
    p,y=map(int,input().split())
    PY.append([p,y])
    F[p][y]=True

for [p,y] in PY:
    print('{0:06d}'.format(p)+'{0:06d}'.format(F[p,:y].sum()+1))

Submission status: Runtime Error

Solution code:
N, M = map(int, input().split())
G = [[] for _ in range(M)]
res = [""] * M
for i in range(M):
    p, y = map(int, input().split())
    G[p - 1].append((y, i))

G = list(map(sorted, G))
for p in range(N):
    for m, (y, i) in enumerate(G[p], 1):
        res[i] = 10 ** 12 + (p + 1) * 10 ** 6 + m

for r in res:
    print(str(r)[1:])

Submission status: Runtime Error

Solution code:
N, M = map(int, input().split())
G = [[] for _ in range(M)]
res = [""] * M
for i in range(M):
    p, y = map(int, input().split())
    G[p - 1].append((y, i))

for i, g in enumerate(G):
    l = len(str(i + 1))
    g.sort()
    for j, gg in enumerate(g):
        ll = len(str(j + 1))
        res[gg[1]] = "0" * (6 - l) + str(i + 1) + "0" * (6 - ll) + str(j + 1)

print("\n".join(res))

Submission status: Runtime Error

Solution code:
N,M = map(int,input().split())
digit = 'zero padding: {:0=6}'
dic = [[] for _ in range(N+1)]

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

for p in dic:
    p.sort()

ans = [None for _ in range(M)]
for k in range(M):
    p = dic[k]
    for j in range(len(p)):
        i = p[j][1]
        ID = str(k).zfill(6)+str(j+1).zfill(6)
        ans[i] = ID

for a in ans:
    print(a)

Submission status: Runtime Error

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

a = {p: [] for p, _ in py}
for p, y in py:
    a[p].append(y)

for p, _ in py:
    a[p].sort()

for p, y in py:
    t = a[p].index(y) + 1
    print(f"{p:06}{t:06}")

Submission status: Runtime Error

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

PY = []
PYd = {i:[] for i in range(1, N+1)}

for i in range(M):
    x, y = [int(i) for i in input().split()]
    PYd[x].append(y)
    PY.append((x,y))
    
for i in PYd.keys():
    PYd[i].sort()
    
for p,y in PY:
    str_p = str(p).zfill(6)
    index = str(bisect.bisect(PYd[p], y)).zfill(6)
    print(str_p+index)

Submission status: Runtime Error

Solution code:
(n,m),*a=[[*map(int,i.split())]for i in open(0)]
c=[0]*-~n
id={}
for p,y in sorted(a,key=lambda x:x[1]):
    c[p]+=1
    id[y]=format(p,"06")+format(c[p],"06")
for _,y in a:
    print(id[y])

Submission status: Runtime Error

Solution code:
(n,m),*a=[[*map(int,i.split())]for i in open(0)]
c=[0]*-~n
id={}
for p,y in sorted(a,key=lambda x:x[1]):
    c[p]+=1
    id[y]=str(p).zfill(6)+str(c[p]).zfill(6)
for _,y in a:
    print(id[y])

Submission status: Runtime Error

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

x = {}
y = [None] * M
for i in range(M):
    P, Y = map(int, input().split())
    if P in x:
        x[P] += [Y]
    else:
        x[P] = [Y]
    y[i] = (P, Y)

for i in range(N):
    x[i+1].sort()

for i in range(M):
    P, Y = y[i]
    print('{}{}'.format(str(P).zfill(6), str(x[P].index(Y) + 1).zfill(6)))

Submission status: Runtime Error

Solution code:
import bisect
n,m = map(int,input().split())
data = []
for i in range(m):
    data.append(list(map(int,input().split())))
r = sorted(data,key= lambda x:(x[0],x[1]))
o = [[] for _ in range(100000)]

for i in range(m):
    o[r[i][0]].append(r[i][1])

for i in range(m):
    print("0"*(6-len(str(data[i][0]))),end="")
    print(data[i][0],end="")
    num = bisect.bisect_left(o[data[i][0]],data[i][1])+1
    print("0"*(6-len(str(num))),end="")
    print(num)

Submission status: Runtime Error

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

for j in range(n):
  for t in len(l[j]):
    pre='0'*(6-len(str(l[j][t])))+str(l[j][t])
    y='0'*(6-len(str(t+1)))+str(t+1)
    print(pre+str)

Submission status: Runtime Error

Solution code:
def resolve():
    n,m=map(int,input().split())
    py=[[0]*3 for _ in range(m)]
    for i in range(m):
        p,y=map(int,input().split())
        py[i][0],py[i][1],py[i][2]=p,y,i
    py.sort()
    ans=[[''] for _ in range(m)]
    cnt=[0]*n
    for p,y,i in py:
        cnt[p]+=1
        ans[i]='0'*(6-len(str(p)))+str(p)+'0'*(6-len(str(cnt[p])))+str(cnt[p])
    for i in ans:
        print(i)


if __name__ == '__main__':
    resolve()

Submission status: Runtime Error

Solution code:
def c_id():
    from collections import defaultdict
    N, M = [int(i) for i in input().split()]
    Cities = [[int(i) for i in input().split()] for j in range(M)]

    dic = defaultdict(list)
    # 県毎に市をまとめる
    for p, y in Cities:
        dic[p].append(y)
    # 市の認識番号を (座標) 圧縮
    for p, lst in dic.items():
        dic[p] = {v: k for k, v in enumerate(sorted(lst), 1)}
    return '\n'.join([f'{p:06d}{dic[p][y]:06d}' for p, y in Cities])

print(c_id())

Submission status: Runtime Error

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

for p in range(1,n+1):
    x[p].sort()
    for j in range(len(x[p])):
        ans[x[p][j][1]]=str(p).zfill(6)+str(j+1).zfill(6)

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

Submission status: Runtime Error

Solution code:
N,M=list(map(int,input().split()))
import sys
l=[list(map(int,_.rstrip().split())) for _ in sys.stdin.readlines()]
n=sorted(l,key=lambda x:x[1])
dic={}
mem=[0]*M
for i,j in n:
   mem[i-1]+=1
   dic[i,j]=str(i).zfill(6)+str(mem[i-1]).zfill(6)
for i,j in l:
   print(dic[i,j])

Submission status: Runtime Error

Solution code:
import copy
n, m = map(int, input().split())
p = [list(map(int, input().split())) for i in range(m)]
dic = {}
q = p.copy()
q.sort(key=lambda x: x[1])
cnt = [0 for i in range(n+1)]
for i in range(m):
    cnt[q[i][0]] += 1
    dic[q[i][1]] = cnt[q[i][0]]
for i in range(m):
    print(str(p[i][0]).zfill(6)+str(dic[p[i][1]]).zfill(6))