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

Solution (Python):


n, m = map(int, input().split())
data = [list(map(int, input().split()))+[i] for i in range(m)]
dic = {}
for p, y, i in data:
    if p not in dic:
        dic[p] = [(y, i)]
    else:
        dic[p].append((y, i))
ans = []
for pre, cities in dic.items():
    cities.sort(key=lambda x: x[0])
    for i in range(len(cities)):
        ans.append(('{:0=6}{:0=6}'.format(pre, i+1), cities[i][1]))
ans.sort(key=lambda x: x[1])
for line in ans:
    print(line[0])

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

cities = []
prefecture_count = [0 for _ in range(N)]
result = []

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

for c in sorted(cities, key=lambda x: x[2]):
    i, p, y = c
    prefecture_count[p-1] += 1
    count = prefecture_count[p-1]
    code = '{0:06d}{1:06d}'.format(p, count)
    result.append((i, code))

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

Solution (Python):
n,m=map(int, input().split())
a=[0]*(n+1)
b=[list(map(int, input().split()))+[i]+[0] for i in range(m)]
b.sort(key=lambda x:x[1])
for i,(x,y,l,z) in enumerate(b):
    a[x-1]+=1
    b[i][3]=a[x-1]
b.sort(key=lambda x:x[2])
for x,y,l,z in b:
    print('{0:06d}{1:06d}'.format(x,z))

Solution (Python):
import bisect
n,m = map(int,input().split())

def c(x):
    x += 1000000
    x = list(str(x))
    del x[0]
    return x

x = [[] for i in range(n)]
jkl = []

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

for i in range(m):
    p = jkl[i][0]
    y = jkl[i][1]
    k = bisect.bisect(x[p-1],y)
    ass = ''
    r = c(p)
    q = c(k)
    for i in range(6):
        ass += r[i]
    for i in range(6):
        ass += q[i]
    print(ass)

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

arr.sort()
ans = {}
prev = None
tmp = None
for p, y, i in arr:
  if prev == None or p != prev:
    tmp = 1
  ans[i] = '%06d%06d' % (p, tmp)
  tmp += 1
  prev = p

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

Solution (Python):

def main():
    buf = input()
    buflist = buf.split()
    N = int(buflist[0])
    M = int(buflist[1])
    P = []
    Y = []
    for i in range(M):
        buf = input()
        buflist = buf.split()
        P.append(int(buflist[0]))
        Y.append(int(buflist[1]))
    citylist = []
    for i in range(len(P)):
        citylist.append([i,P[i],Y[i]])
    citylist = list(sorted(citylist, key=lambda x:x[2]))
    citycount = []
    for i in range(100000):
        citycount.append(1)
    for i in range(len(citylist)):
        citylist[i].append(citycount[citylist[i][1]-1])
        citycount[citylist[i][1]-1] += 1
    citylist = list(sorted(citylist, key=lambda x:x[0]))
    for i in range(len(citylist)):
        print("{:06}".format(citylist[i][1])+"{:06}".format(citylist[i][3]))


if __name__ == '__main__':
    main()

Solution (Python):

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

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

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


ken = [1]*N
answer = []
for i in range(M):
    ue6 = "{0:06d}".format(PY[i][1])
    sita6 = "{0:06d}".format(ken[PY[i][1]-1])
    ken[PY[i][1]-1] += 1
    answer.append([PY[i][0], ue6+sita6])

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

Solution (Python):
import sys
from collections import deque
import copy

def get_read_func(fileobject):
    if fileobject == None :
        return raw_input
    else:
        return fileobject.readline


def main():
    if len(sys.argv) > 1:
        f = open(sys.argv[1])
    else:
        f = None
    read_func = get_read_func(f);
    input_raw = read_func().strip().split()
    [N, M] = [long(input_raw[0]), long(input_raw[1])]
    city = []
    city_num = {}
    for i in range(M):
        input_raw = read_func().strip().split()
        [P, Y] = [long(input_raw[0]), long(input_raw[1])]
        city.append((Y, P, i))
        city_num[P] = 0

    city.sort()
    numbers = []
    for i in range(M):
        C_number = city_num[city[i][1]] + 1
        city_num[city[i][1]] += 1
        P_number = city[i][1]
        numbers.append((city[i][2], "%06d%06d" %(P_number, C_number)))

    numbers.sort()

    for num in numbers:
        print num[1]

if __name__ == '__main__':
    main()

Solution (Python):

import bisect
import heapq
import math
import random
import sys
from collections import Counter, defaultdict, deque
from decimal import ROUND_CEILING, ROUND_HALF_UP, Decimal
from functools import lru_cache, reduce
from itertools import combinations, combinations_with_replacement, product, permutations
from operator import add, mul, sub

sys.setrecursionlimit(10000)


def read_int():
    return int(input())


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


def read_float():
    return float(input())


def read_float_n():
    return list(map(float, input().split()))


def read_str():
    return input().strip()


def read_str_n():
    return list(map(str, input().split()))


def error_print(*args):
    print(*args, file=sys.stderr)


def mt(f):
    import time

    def wrap(*args, **kwargs):
        s = time.time()
        ret = f(*args, **kwargs)
        e = time.time()

        error_print(e - s, 'sec')
        return ret

    return wrap


@mt
def slv(N, M, PY):
    PY = [(p, y, i) for i, (p, y) in enumerate(PY)]
    PY.sort(key=lambda x: x[1])

    id = []
    pc = Counter()
    for p, y, i in PY:
        pc[p] += 1
        id.append(("%06d%06d" % (p, pc[p]), i))

    id.sort(key=lambda x: x[1])
    for s, _ in id:
        print(s)


def main():
    N, M = read_int_n()
    PY = [read_int_n() for _ in range(M)]
    slv(N, M, PY)


if __name__ == '__main__':
    main()

Solution (Python):
N, M = map( int, input().split())
X = [(0,0,0)]*M
Y = [1]*(N+1)
for i in range(M):
    p,y = map( int, input().split())
    X[i] = (y,p,i)
X.sort()
ANS = ['']*M
for i in range(M):
    y, p, j = X[i]
    ans = '%06d'%p + '%06d'%Y[p]
    ANS[j] = ans
    Y[p] += 1
for i in range(M):
    print(ANS[i])

Solution (Python):
N, M = tuple(int(i) for i in input().split())
PY = [tuple(int(i) for i in input().split()) for j in range(M)]

iPY = [(i+1, p, y) for i, (p, y) in enumerate(PY)]
iPY.sort(key=lambda x: x[2])

def f(iPY):
    c = [0] * N
    for i, p, _y in iPY:
        c[p-1] += 1
        yield i, "{:06d}{:06d}".format(p, c[p-1])

for i, d in  sorted(list(f(iPY)), key=lambda x: x[0]):
    print(d)

Solution (Python):
N,M=list(map(int,input().split()))
pref=[[] for i in range(N)]
for i in range(M):
    P,Y=list(map(int,input().split()))
    pref[P-1].append((i+1,Y))
    
ans=['' for i in range(M)]
for i in range(N):
    arr=sorted(pref[i],key=lambda x:x[1])
    for j,x in enumerate(arr):
        ans[x[0]-1]='{0:06d}{1:06d}'.format(i+1,j+1)
for x in ans:
    print(x)

Solution (Python):
from collections import defaultdict as dd

d=dd(int)
n,m=map(int,input().split())
l=[[i]+list(map(int,input().split()))+[0] for i in range(m)]

o=sorted(l,key=lambda x:x[2])
for i,j in enumerate(o):
  d[j[1]]+=1
  o[i][3]=d[j[1]]

for i in sorted(o):
  print('{0:06d}'.format(i[1])+'{0:06d}'.format(i[3]))

Solution (Python):
from numpy import *
from scipy import *
from sys import *


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

d = [list() for i in range(n+1)]

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

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

res = list()
for i in range(1, n+1):
    for j, x in enumerate(d[i]):
        y, id = x
        res.append((id, '{0:06d}{1:06d}'.format(i, j+1)))

res.sort()
for x in res:
    print(x[1])

Solution (Python):
def printNum(n):
    s = str(n)
    return("0"*(6-len(s))+s)
N,M=map(int,input().split())
id = [[] for i in range(N)]
for i in range(M):
    P,Y = map(int,input().split())
    id[P-1].append((Y,i))
for p in range(N):
    id[p].sort(key=lambda x: x[0])
answerlist = []
for p in range(N):
    for j in range(len(id[p])):
        year,i = id[p][j]
        answerlist.append((i,printNum(p+1)+printNum(j+1)))
answerlist.sort(key=lambda x: x[0])
for i,ans in answerlist:
    print(ans)

Solution (Python):
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])

Solution (Python):
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)

Solution (Python):
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)]))

Solution (Python):
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)


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

Solution (Python):
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)

Solution (Python):
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])


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

Solution (Python):
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()



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



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

Solution (Python):
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])

Solution (Python):
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)])

Solution (Python):
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)

Solution (Python):
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)

Solution (Python):
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))

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]

Solution (Python):
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))

Solution (Python):
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)
        
        ansarr[dict1[i][j][1]-1]=s1+s2
for i in range(m):
    print(ansarr[i])

Solution (Python):
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



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

Solution (Python):





"""
abc113 C
"""



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

Solution (Python):
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()

Solution (Python):
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)

Solution (Python):
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

Solution (Python):
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)

Solution (Python):
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)

Solution (Python):

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

Solution (Python):
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)

Solution (Python):
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))

Solution (Python):
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]))

Solution (Python):
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)

Solution (Python):
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)

Solution (Python):
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'))

Solution (Python):
N,M=map(int,input().split())
P=[0 for i in range(M)]
Y=[0 for i in range(M)]
for i in range(M):
    P[i],Y[i]=map(int,input().split())
X=sorted([(Y[i],P[i],i) for i in range(M)])
Z=[(0,0) for i in range(M)]
T=[0 for i in range(N)]
for i in range(M):
    T[X[i][1]-1]+=1
    Z[X[i][2]]=(X[i][1],T[X[i][1]-1])
for seq in Z:
    a=max(0,6-len(str(seq[0])))
    b=max(0,6-len(str(seq[1])))
    print("0"*a+str(seq[0])+"0"*b+str(seq[1]))

Solution (Python):
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))

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

Solution (Python):
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')

Solution (Python):
import sys

stdin = sys.stdin

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

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

Solution (Python):
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