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())
p = [[] for i in range(M)]
counter = [0] * N
ans = [""] * M

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

p.sort(key=lambda x:x[1])
for k, y, i in p:
    counter[k-1] += 1
    ans[i] = "{:06d}{:06d}".format(k, counter[k-1])

for i in ans:
    print(i)

Submission status: Accepted

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


def main():
    from collections import OrderedDict

    n, m = map(int, input().split())
    d = OrderedDict()
    ans = OrderedDict()

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

    prev_pref = 0
    order = 1

    for key, value in sorted(d.items(), key=lambda x: x[1]):
        pref, year = value

        if pref == prev_pref:
            order += 1
        else:
            prev_pref = pref
            order = 1

        ans[key] = '{:0=6}'.format(pref) + '{:0=6}'.format(order)

    for key, value in sorted(ans.items(), key=lambda x: x[0]):
        print(value)


if __name__ == '__main__':
    main()

Submission status: Accepted

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

A = [0]*N
C = [0]*M

B = [0]*M
for i in range(M):
    B[i] = Y[i]*100000+i

B.sort()

for i in range(M):
    d = B[i] % 100000
    k = P[d] - 1

    C[d] = A[k]
    A[k] += 1

for i in range(M):
    print('%06d%06d' % (P[i],C[i]+1))

Submission status: Accepted

Solution code:
N, M = [int(i) for i in input().split()]
PY = []
for i in range(M):
    PY.append([int(j) for j in input().split()] + [i] + [str(0) * 12])

PY.sort(key=lambda x: x[1] + x[0] * 10 ** 10)

count = 0
pre = PY[0][0]
for i in PY:
    count += 1
    if pre != i[0]:
        count = 1
        pre = i[0]
    i[3] = str(pre).zfill(6) + str(count).zfill(6)

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

Submission status: Accepted

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

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

I = [[0, 0] for i in range(M)]
Num = [0]*N

for i in range(M):
    P = C[i][1]
    Num[P-1] += 1
    I[i] = [C[i][0], "%06d%06d" % (P, Num[P-1])]

I.sort(key=lambda x: x[0])
for i in range(M):
    print(I[i][1])

Submission status: Accepted

Solution code:
n, m = map(int, input().split())
ipy_pairs = [tuple(map(int, (("%d " % i) + input()).split())) for i in range(m)]
ipy_pairs.sort(key=(lambda ipy: ipy[1]))

ret = []
current_p_idx = 0
current_p = ipy_pairs[current_p_idx][1]
for idx in range(m):
    p = ipy_pairs[idx][1]
    if p != current_p:
        current_ipy_pairs = ipy_pairs[current_p_idx:idx]
        current_ipy_pairs.sort(key=lambda ipy: ipy[2])
        for _idx_, ipy in enumerate(current_ipy_pairs):
            ret.append((ipy[0], "%06d" % current_p + "%06d" % (_idx_+1)))
        current_p_idx = idx
        current_p = ipy_pairs[current_p_idx][1]
else:
    current_ipy_pairs = ipy_pairs[current_p_idx:]
    current_ipy_pairs.sort(key=lambda ipy: ipy[2])
    for _idx_, ipy in enumerate(current_ipy_pairs):
        ret.append((ipy[0], ("%06d" % current_p + "%06d" % (_idx_+1))))

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

Submission status: Accepted

Solution code:
n,m=map(int,input().split())
l=[list(map(int,input().split())) for i in range(m)]
s=[]
for i in enumerate(l):
    s.append(i)
s=sorted(s,key=lambda x:(x[1][0],x[1][1]))
a=0
for i in range(m):
    if s[i][1][0]==0:
       a=1     
    elif s[i][1][0]==s[i-1][1][0]:
        a+=1
    elif s[i][1][0]!=s[i-1][1][0]:
        a=1
    s[i][1][1]=a
s = sorted(s,key=lambda x:x[0])
for i in s:
    print('%06d'%i[1][0]+'%06d'%i[1][1])

Submission status: Accepted

Solution code:
n,m=map(int,input().split())
l=[list(map(int,input().split())) for i in range(m)]
s=[]
for i in enumerate(l):
    s.append(i)
s=sorted(s,key=lambda x:(x[1][0],x[1][1]))
#print(s)
a=1
for i in range(m):
    if i==0:
        s[0][1][1]=1
    elif s[i][1][0]==s[i-1][1][0]:
        a+=1
        s[i][1][1]=a
    elif s[i][1][0]!=s[i-1][1][0]:
        a=1
        s[i][1][1]=a
#print(s)
s=sorted(s,key=lambda x:x[0])
#print(s)
for i in s:
    print('%06d'%i[1][0]+'%06d'%i[1][1])

Submission status: Accepted

Solution code:
from operator import itemgetter
n,m= map(int,input().split())
city = []
for i in range(m):
    city.append([int(i) for i in input().split()])
per = []
for i in range(n):
    per.append([])

for i,c in enumerate(city):
    per[c[0] - 1].append([i, c[1]])
per_id = 1
for p in per:
    per_id_str = str(per_id)
    while len(per_id_str) < 6:
        per_id_str = "0" + per_id_str
    sort = sorted(p,key = itemgetter(1))
    city_id = 1
    for s_city in sort:
        city_id_str = str(city_id)
        while len(city_id_str) < 6:
            city_id_str = "0" + city_id_str
        city[s_city[0]].append(per_id_str + city_id_str)
        city_id += 1
    per_id += 1
for i in range(m):
    print(city[i][2])

Submission status: Accepted

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

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

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

for p in range(1, n + 1):
    t = sorted(pys[p], key=lambda x: x[0])
    for j, [y, i] in enumerate(t, 1):
        # ans[i] = f'{p:06}{j:06}'
        ans[i] = '{:06d}{:06d}'.format(p, j)
print('\n'.join(ans))

Submission status: Accepted

Solution code:
N, M = map(int, input().split())
data = [[] for i in range(M)]
ans = [""] * M
num = [0] * N
for i in range(M):
    ken, year = map(int, input().split())
    data[i] = [ken, year, i]
    
data.sort(key=lambda x:x[1])

for p, y, i in data:
    num[p-1] += 1
    ans[i] = str(p).zfill(6) + str(num[p-1]).zfill(6)

for i in ans:
    print(i)

Submission status: Accepted

Solution code:
N, M = map(int, raw_input().split())
pyi = {}
for i in range(M):
  pi, yi = map(int, raw_input().split())
  if pi not in pyi:
    pyi[pi] = []
  pyi[pi].append((yi,i))
ix = [0]*M
for p in pyi:
  pyi[p].sort()
  j = 1
  for y, i in pyi[p]:
    ix[i] = "%06d%06d" % (p, j)
    j += 1
for x in ix:
  print x

Submission status: Accepted

Solution code:
ken_shi_list = input().split()
ken_num = int(ken_shi_list[0])
shi_num = int(ken_shi_list[1])
 
shi_list = []
nen_list = [[] for i in range(ken_num) ]
 
for i in range(shi_num):
    shi_list.append(input().split())
    nen_list[int(shi_list[i][0])-1].append( int(shi_list[i][1]) )
 
 
checker = {}
for i in range(ken_num):
   nen_list[i].sort()
   for j in range(len(nen_list[i])):
        checker[nen_list[i][j]] = j+1


for i in range(shi_num):
    ken = int(shi_list[i][0])
    nen = int(shi_list[i][1])
    print( str(ken).zfill(6) + str(checker[nen]).zfill(6) )

Submission status: Accepted

Solution code:
from operator import itemgetter

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

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

a=sorted(a,key=itemgetter(2))
a=sorted(a,key=itemgetter(1))

ans=[]
p_id=a[0][1]
count_id = 1
ans.append([a[0][0],str(a[0][1]).zfill(6)+str(count_id).zfill(6)])

for i in range(1,M):
    if a[i][1]==a[i-1][1]:
        count_id += 1
    else:
        count_id = 1

    id_set = str(a[i][1]).zfill(6)+str(count_id).zfill(6)

    ans.append([a[i][0],id_set])


ans = sorted(ans,key=itemgetter(0))

for j in range(M):
    print(ans[j][1])

Submission status: Accepted

Solution code:
N,M=map(int,input().split())
PY=[list(map(int,input().split()))+[i] for i in range(M)] #定義終了
 
PY.sort(key= lambda x:x[1])
num=[0]*N
w=[""]*M
 
for p,y,i in PY:
	num[p-1]+=1
	w[i]=str(p).zfill(6)+str(num[p-1]).zfill(6)

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

Submission status: Accepted

Solution code:
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools

sys.setrecursionlimit(10**7)
inf = 10**20
eps = 1.0 / 10**13
mod = 10**9+7
dd = [(-1,0),(0,1),(1,0),(0,-1)]
ddn = [(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def pf(s): return print(s, flush=True)


def main():
    n,m = LI()
    py = sorted([LI() + [i] for i in range(m)], key=lambda x: [x[1], x])
    d = collections.defaultdict(int)
    rd = {}
    for p,y,i in py:
        d[p] += 1
        rd[i] = '{:06d}{:06d}'.format(p,d[p])

    return '\n'.join(map(lambda x: rd[x], range(m)))


print(main())

Submission status: Accepted

Solution code:
N, M = [int(i) for i in input().split()]
idx = 0
ipyList = []
for i in range(M):
    idx += 1
    ipy = [int(i) for i in input().split()]
    ipy.insert(0, idx)
    ipyList.append(ipy)

ipyList = sorted(ipyList, key=lambda ipy: ipy[2])
cityMap = {}
for ipy in ipyList:
    if ipy[1] in cityMap.keys():
        cityMap[ipy[1]] += 1
    else:
        cityMap[ipy[1]] = 1
    ipy[2] = cityMap[ipy[1]]

ipyList = sorted(ipyList, key=lambda ipy: ipy[0])
for ipy in ipyList:
    print(str(ipy[1]).zfill(6) + str(ipy[2]).zfill(6))

Submission status: Accepted

Solution code:
from bisect import bisect_left

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

P = []
Y = []
PY = [[] for _ in range(N+1)]

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

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

for i in range(M):
    x = bisect_left(PY[P[i]], Y[i]) + 1
    print("%06d%06d" % (P[i], x))

Submission status: Accepted

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

same_id = sorted_P_Y_list[0][0]
counter = 1

for element_list in sorted_P_Y_list:
    if same_id != element_list[0]:
        counter = 1
        same_id = element_list[0]

    element_list[1] = str(counter)
    counter += 1

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

for id in sorted_P_Y_list:
    print("%012d"%int(str(id[0]).zfill(6) + id[1].zfill(6)))

Submission status: Accepted

Solution code:
N,M=map(int,input().split())
PY=[list(map(int,input().split()))+[i] for i in range(M)] #定義終了

PY.sort(key= lambda x:x[1])
num=[0]*N
w=[""]*M

for p,y,i in PY:
	num[p-1]+=1
	w[i]=str(p).zfill(6)+str(num[p-1]).zfill(6)

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

Submission status: Accepted

Solution code:
n, m = map(int, input().split())
p = [[] for _ in range(n)]
for i in range(m):
    j, y = map(int, input().split())
    p[j-1].append((y, i))
for i in range(n):
    p[i].sort()
r = [None]*m
for j in range(n):
    for x, (_, i) in enumerate(p[j]):
        r[i] = str(j+1).zfill(6) + str(x+1).zfill(6)
for s in r:
    print(s)

Submission status: Accepted

Solution code:
import sys
import collections
import itertools
import math
import re
from collections import Counter
from collections import deque

MOD = 10 ** 9 + 7

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

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

PYC = sorted(PYC)

city = {}

pCount = 1
preP = -1
for p, y, c in PYC:
    if preP != p:
        pCount = 1
    city[c] = (p, pCount)
    pCount += 1
    preP = p

for i in range(M):
    print("{:06d}{:06d}".format(city[i][0], city[i][1]))


sys.exit(0)

Submission status: Accepted

Solution code:
import numpy as np

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

Y_arg=np.argsort(Y)

Ans=[0 for j in range(M)]
count=[0 for k in range(N)]

for ya in Y_arg:
    p_id_6='{0:06d}'.format(P[ya])
    c_id=count[(P[ya]-1)]+1
    count[P[ya]-1]+=1
    c_id_6='{0:06d}'.format(c_id)
    Ans[ya]=str(p_id_6)+str(c_id_6)

for a in Ans:
    print(a)

Submission status: Accepted

Solution code:
n, m = (int(i) for i in input().split())
#print(n,m)
data = [[int(i) for i in input().split()] for i in range(m)]
#print(data)
#n,m=2,3
#data=[[1, 32], [2, 63], [1, 12]]#[ken_city,year]
#print(len(data))
id=[]
for i in range(m):
    id.append(i+1)

#print(id)
    
dataid=list(zip(data,id))
#print(dataid)
dataid.sort()
#print(dataid)

listz=[]
ken=0

for i in range(m):
    if dataid[i][0][0]==ken:
        kazu+=1        
        y=[dataid[i][1],dataid[i][0][0],kazu]
        listz.append(y)
    else:
        kazu=1
        ken=dataid[i][0][0]
        y=[dataid[i][1],dataid[i][0][0],kazu]
        listz.append(y)
        
#print(z)

listz.sort()
#print(listz)

for i in range(m):
    print(str(listz[i][1]).zfill(6)+str(listz[i][2]).zfill(6))

Submission status: Accepted

Solution code:
# coding: utf-8
# N : 県の数, M: 市の数
import bisect

N, M = map(int, input().split())
ps, ys = [], []

v = [ [] for _ in range(N+1) ]

for i in range(M):
    p, y = map(int, input().split())
    ps += [p]; ys += [y];
    v[p].append(y)

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


for i in range(M):
    print("{:06d}".format(ps[i]), end="")
    print("{:06d}".format(bisect.bisect_left(v[ps[i]], ys[i])+1))

Submission status: Accepted

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

def prefecturesort(i):
    return i[0]

def yearsort(i):
    return i[1]

W=[0 for i in range(n)]
Z=[]

for i in range(m):
    P[i].append(i)
    W[P[i][0]-1]+=1

P.sort(key=prefecturesort)
P_c=[]
sum=0
for i in range(n):
    c=W[i]
    if c==0:
        P_c.append([])
    else:
        P_c.append(P[sum:c+sum])
    sum+=c
    P_c[i].sort(key=yearsort)
for x in P_c:
    for j in range(len(x)):
        X=str("{0:06d}".format(x[j][0]))
        Y=str("{0:06d}".format(j+1))
        Z.append([X+Y,x[j][2]])
Z.sort(key=yearsort)
for i in range(m):
    print(Z[i][0])

Submission status: Accepted

Solution code:
Data = list(map(int, input().split()))
N = Data[0]
M = Data[1]
del(Data)
Data = []
for i in range(M):
  Data.append(list(map(int, input().split())))
  Data[i].append(i)
Data.sort()
Cnt = 0
Num = 0
for i in range(M):
  if Num == Data[i][0]:
    Cnt += 1
  else:
    Cnt = 1
    Num = Data[i][0]
  Data[i].append(Cnt)
Data.sort(key=lambda x:x[2])

for i in range(M):
  print(str(Data[i][0]).zfill(6) + str(Data[i][3]).zfill(6))

Submission status: Accepted

Solution code:
# import sys
 
# N:県, M:市
N, M = list(map(int, input().split()))

A = {}
# {ken: [(city_no, city_year)],...}

res = [None] * M

L = [tuple(map(int, input().split())) for _ in range(M)]

for i in range(M):
  k, y = L[i]
  if k in A.keys():
    A[k].append((i, y))
  else:
    A[k] = [(i, y)]

# print(A)
# A: {県番号: {市1の年:市1のindex, 市2の年:市2のindex}}

for k, v in A.items():
  # sort by year
  c_list = sorted(v, key=lambda x: x[1])
  counter = 1
  for c in c_list:
    res[c[0]] = (k, counter)
    counter += 1

for x in res:
  print("{:0>6}{:0>6}".format(x[0], x[1]))

Submission status: Accepted

Solution code:

from collections import defaultdict

def tostring(p,j):
    p = str(p+1)
    j = str(j+1)
    return (6 - len(p))*"0" + p + (6-len(j)) *"0" + j


if __name__ == "__main__":
    N, M = map(int, input().split())

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

    dat = [tuple(map(int, input().split())) for _ in range(M)]

    for i in range(M):
        p,y = dat[i]
        py[p-1].append((y,i))
    
    for p in range(N):
        py[p] = sorted(py[p])
    
    answer = M * [None]

    for p in range(N):
        for j in range(len(py[p])):
            y,i = py[p][j]
            answer[i]= tostring(p,j)
    
    for a in answer:
        print(a)

Submission status: Accepted

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

for i in range(m):
    p, y = list(map(int, input().split()))
    if city_dict.get(p) == None:
        city_dict[p] = [[y, i]]
    else:
        city_dict[p].append([y, i])

ID = []

for ken, city_and_id in city_dict.items():
    city_and_id.sort()
    for j, city in enumerate(city_and_id):
       num_padded = '%06d' % (j+1)
       ken_padded = '%06d' % ken
       ID.append([str(ken_padded)+str(num_padded), city[1]])

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

for city_id in ID:
    print(city_id[0])

Submission status: Accepted

Solution code:
def solve(N, M, PYs):
    Ys = {i + 1: 1 for i in range(N)}
    ret = {}
    for p, y in sorted(PYs, key=lambda x: x[1]):
        ret[(p, y)] = "{:06d}{:06d}".format(p, Ys[p])
        Ys[p] += 1
    return [ret[(p, y)] for (p, y) in PYs]

if __name__ == "__main__":
    N, M = tuple(map(int, input().split(" ")))
    PYs = [tuple(map(int, input().split(" "))) for _ in range(M)]
    print("\n".join(solve(N, M, PYs)))

Submission status: Accepted

Solution code:
N, M = map(int, input().split())
li = [[] for _ in range(N+1)]
for i in range(M):
    p, y = map(int, input().split())
    li[p].append([i, y])
ans = [0 for _ in range(M)]
for i in range(1, N+1):
    iy = li[i]
    iy.sort(key=lambda x: x[1])
    for j in range(len(iy)):
        ans[iy[j][0]] = (i, j+1)
for shi in ans:
    print('{:06d}{:06d}'.format(shi[0], shi[1]))

Submission status: Accepted

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

C = []
for i in range(N+1) :
    C.append([])

for i, (p,y) in enumerate(L) :
    C[p].append([y,i])

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

Submission status: Accepted

Solution code:
from collections import defaultdict, Counter
from itertools import product, groupby, count, permutations, combinations
from math import pi, sqrt
from collections import deque
from bisect import bisect, bisect_left, bisect_right
from string import ascii_lowercase
from functools import lru_cache
import sys
sys.setrecursionlimit(10000)
INF = float("inf")
YES, Yes, yes, NO, No, no = "YES", "Yes", "yes", "NO", "No", "no"
dy4, dx4 = [0, 1, 0, -1], [1, 0, -1, 0]
dy8, dx8 = [0, -1, 0, 1, 1, -1, -1, 1], [1, 0, -1, 0, 1, 1, -1, -1]


def inside(y, x, H, W):
    return 0 <= y < H and 0 <= x < W


def ceil(a, b):
    return (a + b - 1) // b


# aとbの最大公約数
def gcd(a, b):
    if b == 0:
        return a
    return gcd(b, a % b)


# aとbの最小公倍数
def lcm(a, b):
    g = gcd(a, b)
    return a / g * b


def main():
    N, M = map(int, input().split())
    d = defaultdict(list)

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

    d2 = {}
    for p in d.keys():
        d[p].sort()
        d3 = {}
        for i, y in enumerate(d[p], start=1):
            d3[y] = i
        d2[p] = d3

    for p, y in py:
        print(str(p).zfill(6) + str(d2[p][y]).zfill(6))


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
n = input().split()
l1 = []
for i in range(int(n[1])):
    l1.append(input().split())

for i in range(int(n[1])):
    for j in range(2):
        l1[i][j] = int(l1[i][j])


m = 0
for k in l1:
    k.append(m)
    m += 1


l3 = sorted(l1)


l3[0][1] = 1
for i in range(1,len(l3)):
    if l3[i][0]==l3[i-1][0]:
        l3[i][1]=l3[i-1][1]+1
    else:
        l3[i][1]=1

for i in range(len(l3)):
    l3[i][2],l3[i][0]=l3[i][0],l3[i][2]
for i in range(len(l3)):
    l3[i][1],l3[i][2]=l3[i][2],l3[i][1]
l3.sort()


for i in range(int(n[1])):
    for j in range(2):
        l3[i][j] = str(l3[i][j])

for i in range(len(l3)):
    print(str(l3[i][1]).zfill(6)+str(l3[i][2]).zfill(6))

Submission status: Accepted

Solution code:
N,M = map(int,input().split())
l = []
for i in range(M):
	p,y = map(int,input().split())
	l.append([p,y,i])
l.sort()
p = -1
n = 1
for i in range(M):
	if l[i][0] == p:
		n += 1
		l[i][1] = n
	else:
		n = 1
		l[i][1] = n
	p = l[i][0]
for i in range(M):
	l[i][0],l[i][1],l[i][2]=l[i][2],l[i][0],l[i][1]
l.sort()
for i in range(M):
	print('0'*(6-len(str(l[i][1])))+str(l[i][1])+'0'*(6-len(str(l[i][2])))+str(l[i][2]))

Submission status: Accepted

Solution code:
#abc113c

n,m=map(int,raw_input().split())
py=[]
for i in xrange(m):
 p,y=map(int,raw_input().split())
 py.append([i,p,y])
py=sorted(py,key=lambda x:(x[1],x[2]))
pn=[0]*(n+1)
res=[""]*m
for j in range(m):
 i,p,y=py[j]
 pn[p]+=1
 res[i]="%06d%06d"%(p,pn[p])
for x in res:
 print x

Submission status: Accepted

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

import sys

def solve(n, m, ls_py):
    # Uncomment the following if you want to check the input.
    # print('n =', n)
    # print('m =', m)
    # print('ls_py =', ls_py)
    perP = [[] for i in range(n+1)]
    for (i,[p,y]) in enumerate(ls_py):
        perP[p].append((y,i))
    seqs = []
    for p in range(n+1):
        perP[p].sort()
        for (o, (_, i)) in enumerate(perP[p], start=1):
            seq = '{:06d}{:06d}'.format(p, o)
            seqs.append((i,seq))
    return '\n'.join([seq for (i,seq) in sorted(seqs)])


def readQuestion():
    ws = sys.stdin.readline().strip().split()
    n = int(ws[0])
    m = int(ws[1])
    ls_py = [list(map(int, sys.stdin.readline().strip().split())) for j in range(m)]
    return (n, m, ls_py)

def main():
    print(solve(*readQuestion()))

# Uncomment before submission
main()

Submission status: Accepted

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

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

ans = {}
for k,v in P.items():
  v.sort(key=lambda x: x[0])
  for n in range(len(v)):
    y, i = v[n]
    ans[i] = "{p:06d}{n:06d}".format(p=k, n=n+1)

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

Submission status: Accepted

Solution code:
N,M=map(int,input().strip().split())
P,Y=[0]*M,[0]*M
all=[]
for i in range(M):
    P[i],Y[i]=map(int,input().strip().split())
    all.append([P[i],Y[i],i])
x=1
all.sort()
for i in range(M):
    if all[i][0]==all[i-1][0]:
        x+=1
        all[i][1]=x
    else:
        x=1
        all[i][1]=x
x=1
for i in range(M):
    if all[0][0]==all[i][0]:
        all[i][1]=x
        x+=1
    else:
        break
all.sort(key=lambda x: x[2])
for i in range(M):
    print((str(all[i][0]).rjust(6,'0')+str(all[i][1]).rjust(6,'0')))

Submission status: Accepted

Solution code:
import math

def Show(n):
	s = str(n)
	m = len(s)
	for i in range(6 - m):
		print("0",end = "")
	print("{0}".format(n),end = "")

class city:
	year = 0
	p = 0
	number = 0
	def __init__(self,y,pi,n):
		self.year = y
		self.p = pi
		self.number = n

s = input().split()
n = int(s[0])
m = int(s[1])
cities = []
for i in range(m):
	s = input().split()
	p = int(s[0])
	y = int(s[1])
	cities.append(city(y,p,i))
x = [[] for i in range(n)]
for i in range(m):
	x[cities[i].p - 1].append(cities[i])
for i in range(n):
	x[i].sort(key = lambda x : x.year)
ans = []
for i in range(m):
	ans.append([0,0])
for i in range(n):
	for j in range(len(x[i])):
		ans[x[i][j].number][0] = x[i][j].p
		ans[x[i][j].number][1] = j + 1
for i in range(m):
	Show(ans[i][0])
	Show(ans[i][1])
	print()

Submission status: Accepted

Solution code:
N, M = map(int, input().split())
PY = [list(map(int, input().split())) for i in range(M)]
for i in range(M):
    PY[i].append(int(i))
PY.sort(key=lambda x: (x[0], x[1]))
ID = [[] for i in range(M)]
k = 1
for i in range(M):
    ID[i].append(str(PY[i][0]).zfill(6))
    ID[i].append(str(k).zfill(6))
    ID[i].append(PY[i][2])
    if i+1 == M:
        break
    if PY[i+1][0] > PY[i][0]:
        k = 1
    else:
        k += 1
ID.sort(key=lambda x: (x[2]))
for i in range(M):
    print(ID[i][0] + ID[i][1])

Submission status: Accepted

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

mlist = []
for i in range(M):
    a, b = list(map(int, input().split()))
    ken[a - 1].append(b)
    mlist.append((a, b,))

for v in ken:
    v.sort()


def search(v, lst):
    l, r = 0, len(lst) - 1
    while l <= r:
        m = (l + r) // 2
        if lst[m] == v:
            return m

        if lst[m] < v:
            l = m + 1
        else:
            r = m - 1
    return None


for a, b in mlist:
    print("{:06d}{:06d}".format(a, search(b,ken[a - 1]) + 1))

Submission status: Accepted

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

N = [[] for i in range(N)]
for i in range(M):
    aidu = [int(i) for i in input().split()]
    N[aidu[0]-1].append([i, aidu[1]])

for i in N:
    i.sort(key=lambda x:x[1])

aidudu = []
for i, n in enumerate(N):
    for j, m in enumerate(n):

        pref_num = i+1
        pref_keta = 0
        while(int(pref_num / 10)):
            pref_num = int(pref_num / 10)
            pref_keta += 1
        pref_moji = "0" * (5 - pref_keta) + str(i+1)

        city_num = j+1
        city_keta = 0;
        while(int(city_num / 10)):
            city_num = int(city_num / 10)
            city_keta += 1
        city_moji = "0" * (5 - city_keta) + str(j+1)

        m = [m[0], pref_moji+city_moji]

        aidudu.append(m)

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

for i in aidudu:
    print(i[1])

Submission status: Accepted

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

for j in range(m):
    p, y = map(int, input().split())
    pre[p - 1].append((y, j))

inums = [0] * m
for k in range(n):
    if len(pre[k]) == 0:
        pass
    else:
        sorted_y = sorted(pre[k])
        for l in range(len(sorted_y)):
            s1 = str(k + 1).zfill(6)
            s2 = str(l + 1).zfill(6)
            inums[sorted_y[l][1]] = s1 + s2

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

Submission status: Accepted

Solution code:
list1 = input().split()
n = int(list1[0])
m = int(list1[1])
pre = [[] for i in range(n)]

for j in range(m):
    data = input().split()
    p = int(data[0])
    y = int(data[1])
    pre[p - 1].append((j, y))

inums = [0 for z in range(m)]
for k in range(n):
    if len(pre[k]) == 0:
        pass
    else:
        sorted_y = sorted(pre[k], key = lambda x:x[1])
        for l in range(len(sorted_y)):
            s1 = str(k + 1).zfill(6)
            s2 = str(l + 1).zfill(6)
            inums[sorted_y[l][0]] = s1 + s2

for h in range(m):
    print(inums[h])

Submission status: Accepted

Solution code:
list1 = input().split()
n = int(list1[0])
m = int(list1[1])
pre = [[] for i in range(n)]

for j in range(m):
    data = input().split()
    p = int(data[0])
    y = int(data[1])
    pre[p - 1].append((j, y))

inums = []
for k in range(n):
    if len(pre[k]) == 0:
        pass
    else:
        sorted_y = sorted(pre[k], key = lambda x:x[1])
        for l in range(len(sorted_y)):
            s1 = str(k + 1).zfill(6)
            s2 = str(l + 1).zfill(6)
            inums.append((sorted_y[l][0], s1 + s2))

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

Submission status: Accepted

Solution code:
import bisect

n, m = [int(_) for _ in input().split(' ')]

p, y = [], []
for _ in range(m):
    temp = [int(_) for _ in input().split(' ')]
    p.append(temp[0])
    y.append(temp[1])
ys = dict()
for i in range(m):
    if not(p[i] in ys):
        ys[p[i]] = []
    ys[p[i]].append(y[i])

for j in ys.keys():
    ys[j].sort()

for i in range(m):
    print('{0}{1}'.format(str(p[i]).zfill(6), str(bisect.bisect(ys[p[i]], y[i])).zfill(6)))

Submission status: Accepted

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

l1 = [[] for i in range(n)]
l2 = []

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

dic = {}

for p in range(n):
    l1[p].sort()
    for i in range(len(l1[p])):
        dic[l1[p][i]] = i+1
        

for i in range(m):
    p = l2[i][0]
    k = dic[l2[i][1]]
    p = str(p)
    k = str(k)
    ans = "0"*(6-len(p))+p+"0"*(6-len(k))+k
    print(ans)

Submission status: Accepted

Solution code:
import sys
readline = sys.stdin.readline
from collections import defaultdict
n, m = map(int, input().split())
ans = [""] * m
li = []
for i in range(m):
    p, y = map(int, readline().split())
    li.append((p, y, i))
li.sort()
cnt = 1
ans[li[0][2]] = "{:06}{:06}".format(li[0][0], cnt)
for i in range(1, m):
    cnt = cnt + 1 if li[i - 1][0] == li[i][0] else 1
    ans[li[i][2]] = "{:06}{:06}".format(li[i][0], cnt)
print(*ans, sep="\n")

Submission status: Accepted

Solution code:
n, m = map(int, input().split())
ans = [""] * m
li = []
for i in range(m):
    p, y = map(int, input().split())
    li.append((p, y, i))
li.sort()
cnt = 1
ans[li[0][2]] = "{:06}{:06}".format(li[0][0], cnt)
for i in range(1, m):
    cnt = cnt + 1 if li[i - 1][0] == li[i][0] else 1
    ans[li[i][2]] = "{:06}{:06}".format(li[i][0], cnt)
print(*ans, sep="\n")

Submission status: Accepted

Solution code:
n, m = map(int, raw_input().split())
arr = []
for i in range(m):
    pi, yi = map(int, raw_input().split())
    arr.append([pi, yi, i+1])

def six_digit(n):
    if len(str(n)) < 6:
        n = "0"*(6-len(str(n)))+str(n)
    else:
        n=str(n)
    return n
arr.sort()
cp = 1
num = 0
for lst in arr:
    if lst[0]!=cp:
        cp=lst[0]
        num = 1
    else:
        num += 1
    lst.reverse()
    id = six_digit(cp)+six_digit(num)
    lst.append(id)

arr.sort()
for lst in arr:
    print lst[3]

Submission status: Accepted

Solution code:
from operator import itemgetter
n,m = map(int,input().split())
lis = []
ans = [0 for i in range(m)]
num = [0 for i in range(n)]
for i in range(m):
  a,b = map(int,input().split())
  lis.append([i,a,b])
lis.sort(key=itemgetter(2))
for i in range(m):
  num[lis[i][1]-1] += 1
  cou = max(0,5-(lis[i][1] // 10))
  co = max(0,5-(num[lis[i][1]-1] // 10))
  ans[lis[i][0]] = format(lis[i][1],'06d') + format(num[lis[i][1]-1],'06d')
for i in range(m):print(ans[i])

Submission status: Accepted

Solution code:
import sys
input=sys.stdin.readline

N,M=[int(n) for n in input().split()]
lis=[[i]+[int(n) for n in input().split()] for i in range(M)]
#print(lis)
l_2=sorted(lis, key=lambda x: x[2])
dic={}
for k,i,j in l_2:
    dic[i]=dic.get(i,0)+1
    lis[k]='{:0=6}{:0=6}'.format(i,dic[i])
for i in lis:print(i)