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: Time Limit Exceeded

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

for _ in range(M):
    P, Y = map(int,input().split())
    newCity += [[P, Y]]
    pref[P] += [Y]

for i in pref:
    pref[i] = sorted(pref[i])

for j in newCity:
     print("0" * (6 - len(str(j[0]))),
           str(j[0]),
           "0" * (6 - len(str(pref[j[0]].index(j[1])))),
           pref[j[0]].index(j[1]),
           sep=""
           )

Submission status: Time Limit Exceeded

Solution code:
def pypri(p,y):print(str(p).zfill(6)+str(y).zfill(6))
n,m=map(int,input().split())
a=[[]for _ in range(n)]
b=[]
for i in range(m):
  p,y=map(int,input().split())
  b.append(p-1)
  a[p-1].append([y,len(a[p-1])+1])
for i in range(n):
  a[i].sort()
  for j in range(len(a[i])):
    a[i][j]=[a[i][j][1],j]
    a[i].sort()
for i in b:
  pypri(i+1,a[i][0][1]+1)
  del a[i][0]

Submission status: Time Limit Exceeded

Solution code:
def pypri(p,y):print(str(p).zfill(6)+str(y).zfill(6))
n,m=map(int,input().split())
a=[[]for _ in range(n)]
b=[]
for i in range(m):
  p,y=map(int,input().split())
  b.append(p-1)
  a[p-1].append([y,len(a[p-1])+1])
for i in range(n):
  a[i].sort()
  for j in range(len(a[i])):
    a[i][j]=[a[i][j][1],j]
    a[i].sort()
for i in b:
  pypri(i+1,a[i][0][1]+1)
  del a[i][0]

Submission status: Time Limit Exceeded

Solution code:
n,m = map(int, input().split())
from collections import defaultdict
a = []
l = [[] for _ in range(n)]
for i in range(m):
    p,y = map(int, input().split())
    l[p-1].append(y)
    a.append([p,y])
l = list(map(sorted, l))
for p, y in a:
    print("{:0>6}{:0>6}".format(p,l[p-1].index(y)+1))

Submission status: Time Limit Exceeded

Solution code:
a, b = map(int, input().split())
c = []
h = []
for i in range(b):
    d, e = map(int, input().split())
    c.append([e, d, 0])
    h.append([e, d, 0])
h.sort()
for i in range(a):
    g = 1
    for j in range(b):
        if h[j][1] == i + 1:
            h[j][2] = g
            g += 1
for i in range(b):
    for j in range(b):
        if c[i][0] == h[j][0] and c[i][1] == h[j][1]:
            print(("000000" + str(h[j][1]))[-6:] + ("000000" + str(h[j][2]))[-6:])
            break

Submission status: Time Limit Exceeded

Solution code:
import math
import fractions
import copy
import numpy as np
def j(q):
    if q==1: print("Bad")
    elif q == 0:print("Good")
    exit(0)
rem = pow(10,9)+7
"""
def ct(x,y):
    if (x>y):print("+")
    elif (x<y): print("-")
    else: print("?")
"""

def ip():
    return int(input())
def iprow():
    return [int(i) for i in input().split()]
def ips():
    return (int(i) for i in input().split())
def printrow(a):
    for i in a:
        print(i)
def combinations(n,r):
    if n<r:return 0
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))
def permutations(n,r):
    if n<r:return 0
    return math.factorial(n) // math.factorial(n - r)
def lcm(x, y):
    return (x * y) // fractions.gcd(x, y)

n,m = ips()
#a = input()                                  #入力文字列
#a = input().split()                          #入力文字配列
#n = ip()                      #入力セット(整数改行あり)(1/2)
#a=[ip() for i in range(m)]    #入力セット(整数改行あり)(2/2)
#a=[input() for i in range(n)]    #入力セット(整数改行あり)(2/2)
#jの変数はしようできないので注意
#a.pop(0)は10^5あるときTLEしやすい!注意!抜くなら逆ソート!
a = []
for i in range(m):
    b = [int(i) for i in input().split()]
    b.append(i)
    a.append(b)
a.sort()
city = a[0][0]
ct = 0
c = []
d = []
for i in range(m):
    if city != a[i][0]:
        city = a[i][0]
        ct =1
    else:ct+=1
    cna = str(city)
    cnb = str(ct)
    cna = cna.zfill(6)
    cnb = cnb.zfill(6)
    name = ''.join([cna,cnb])
    c.append([a[i][2],name])
    d.append(int(a[i][2]))
for i in range(m):
    print(c[d.index(i)][1])
"""
c.sort()
for i in range(m):
    print(c[i][1])
"""

Submission status: Time Limit Exceeded

Solution code:
N,M = map(int,input().split())
para = []
for i in range(M):
    a,b = map(int,input().split())
    para.append([a,b,i])
para.sort(key = lambda x:(x[0],x[1]))
ans = []
memo = []
for i in range(M):
    if para[i][0] not in memo :
        cnt = 1
        a = format(para[i][0]).zfill(6) + format(cnt).zfill(6)
        ans.append([a,para[i][2]]) 
        memo.append(para[i][0])
    else : 
        cnt += 1
        a = format(para[i][0]).zfill(6) + format(cnt).zfill(6)
        ans.append([a,para[i][2]]) 
ans.sort(key=lambda x:x[1])
for i in range(M):
    print(ans[i][0])

Submission status: Time Limit Exceeded

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

cnt = [[0] for _ in range(n+1)]

for i in range(m):
    idx = ls[i][0]
    cnt[idx].append(ls[i][1])

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


for i in range(m):
    idx = ls[i][0]
    print("{:06d}{:06d}".format(idx,cnt[idx].index(ls[i][1])))

Submission status: Time Limit Exceeded

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


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

sortPY=sorted(PY,key=lambda x: (x[0],x[1]))
Plist=[sortPY[i][0] for i in range(m)]

for i in range(m):
	sortPY[i][2]=Plist[0:i+1].count(Plist[i])


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

Submission status: Time Limit Exceeded

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


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

sortPY=sorted(PY,key=lambda x: (x[0],x[1]))
Plist=[sortPY[i][0] for i in range(m)]

for i in range(m):
	sortPY[i][3]=Plist[0:i+1].count(Plist[i])

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

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

Submission status: Time Limit Exceeded

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

group = [[] for _ in range(N + 1)]
for p, y in PY:
	group[p] += [y]

for g in group:
	g.sort()

for p, y in PY:
	print("{:06d}{:06d}".format(p, group[p].index(y) + 1))

Submission status: Time Limit Exceeded

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

query = []

for _ in range(m):
  tp = tuple(map(int,input().split()))
  query.append(tp)
  lis[tp[0]-1].append(tp[1])
  
for i in range(n):
  lis[i].sort()

for item in query:
  print("{:06}{:06}".format(item[0],lis[item[0]-1].index(item[1])+1))

Submission status: Time Limit Exceeded

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

ms = []
for i in range(m):
    p, y = [int(x) for x in input().split()]
    ms.append({
        'p': p,
        'y': y
    })

ps = []
for i in range(n):
    result = list(filter(lambda x: x.get('p') == i+1, ms))
    result.sort(key=lambda x: x.get('y'))
    ps.append(result)

for i in range(m):
    for j, x in enumerate(ps[ms[i].get('p') - 1]):
        if x.get('y') == ms[i].get('y'):
            print('%s%s' % (str(ms[i].get('p')).zfill(6), str(j+1).zfill(6)))

Submission status: Time Limit Exceeded

Solution code:
nm = list(map(int,input().split()))
N = nm[0]
M = nm[1]

py ={}
iy ={}
yp ={}

for i in range(M):
    PY = list(map(int,input().split()))
    P = PY[0]
    Y = PY[1]
    iy[i] = Y
    yp[Y] = P
    if(P in py):
        temp = py[P]
        temp.append(Y)
        temp.sort()
        py[P] = temp
    else:
        temp = []
        temp.append(Y)
        py[P] = temp

for i in range(M):
    y = iy[i]
    p = yp[y]
    x = py[p].index(y)
    pref = "000000" + str(p)
    pref = pref[-6:]
    X = "000000" + str(x+1)
    X = X[-6:]
    print(pref + X)

Submission status: Time Limit Exceeded

Solution code:
N, M = map(int, input().split())
P =[]
Y =[]
for i in range(M):
    p1, y1 = [int(i) for i in input().split()]
    P.append(p1)
    Y.append(y1)

for i in range(M):
    cnt = 1
    for j in range(M):
        if P[i] == P[j] and Y[i] > Y[j]:
            cnt = cnt + 1
    print(str(P[i]).zfill(6)+str(cnt).zfill(6))

Submission status: Time Limit Exceeded

Solution code:
import bisect
n,m=map(int,input().split())
pl=[[] for i in range(n)]
cl=[]
for i in range(m):
    p,y=list(map(int,input().split()))
    cl+=[[p,y]]
    bisect.insort(pl[p-1],y)
for p,y in cl:
    print('{0:06d}{1:06d}'.format(p,pl[p-1].index(y)+1))

Submission status: Time Limit Exceeded

Solution code:
n,m=map(int,input().split())
pl=[[] for i in range(n)]
cl=[]
for i in range(m):
    p,y=list(map(int,input().split()))
    cl+=[[p,y]]
    pl[p-1].append(y)
for i in range(n):
    pl[i].sort()
for p,y in cl:
    print('{0:06d}{1:06d}'.format(p,pl[p-1].index(y)+1))

Submission status: Time Limit Exceeded

Solution code:
n,m=map(int,input().split())
cl=[list(map(int,input().split())) for i in range(m)]
pl=[[] for i in range(n)]
for p,y in cl:
    pl[p-1].append(y)
for i in range(n):
    pl[i].sort()
for p,y in cl:
    print('{0:06d}{1:06d}'.format(p,pl[p-1].index(y)+1))

Submission status: Time Limit Exceeded

Solution code:
import bisect
n,m=map(int,input().split())
cl=[list(map(int,input().split())) for i in range(m)]
pl=[[] for i in range(n)]
for p,y in cl:
    bisect.insort(pl[p-1],y)
for p,y in cl:
    print('{0:06d}{1:06d}'.format(p,pl[p-1].index(y)+1))

Submission status: Time Limit Exceeded

Solution code:
N, M = map(int, input().split())
from collections import defaultdict
d = defaultdict(list)
l = [[] for i in range(M)]
for i in range(M):
    P,Y = map(str, input().split())
    P = "0" * (6-len(P)) + P
    d[P] += [int(Y)]
    l[i] = [P,int(Y)]
for i in range(M):
    tmp = str((sorted(d[l[i][0]]).index(l[i][1]))+1)
    print(l[i][0] + "0" * (6-len(tmp)) + tmp)

Submission status: Time Limit Exceeded

Solution code:
N, M = map(int, input().split())
from collections import defaultdict
d = defaultdict(list)
l = [[] for i in range(M)]
for i in range(M):
    P,Y = map(str, input().split())
    P = "0" * (6-len(P)) + P
    d[P].append(int(Y))
    l[i] = [P,int(Y)]
for i in range(M):
    tmp = str((sorted(d[l[i][0]]).index(l[i][1]))+1)
    print(l[i][0] + "0" * (6-len(tmp)) + tmp)

Submission status: Time Limit Exceeded

Solution code:
import bisect
n,m=map(int,input().split())
d={i+1:[[],[]] for i in range(n)}
for i in range(m):
     p,y=map(int,input().split())
     idx=bisect.bisect_left(d[p][0],y)
     d[p][0].insert(idx,y)
     d[p][1].insert(idx,i)
tmp2=[0 for i in range(m)]
for k in d.keys():
     x=d[k][1]
     for i in range(len(x)):
          num=str(k).zfill(6)+str(i+1).zfill(6)
          tmp2[x[i]]=num
for x in tmp2:
     print(x)

Submission status: Time Limit Exceeded

Solution code:
import bisect
n,m=map(int,input().split())
d={i+1:[[],[]] for i in range(n)}
for i in range(m):
     p,y=map(int,input().split())
     idx=bisect.bisect_left(d[p][0],y)
     d[p][0].insert(idx,y)
     d[p][1].insert(idx,i)
tmp=[]
tmp2=[]
for k in d.keys():
     for i in range(len(d[k][0])):
          num=str(k).zfill(6)+str(i+1).zfill(6)
          idx=bisect.bisect_left(tmp,d[k][1][i])
          tmp.insert(idx,d[k][1][i])
          tmp2.insert(idx,num)
for x in tmp2:
     print(x)

Submission status: Time Limit Exceeded

Solution code:
N, M = map(int, input().split())
l = [None] * M
for i in range(M):
	p, y = map(int, input().split())
	l[i] = [y, p, i]
m = []
for i in range(1, N + 1):
	l_ = sorted(list(filter(lambda x: x[1] == i, l)))
	for i in range(len(l_)):
		l_[i][0] = i + 1
	m = m + l_
for i in sorted(m, key = lambda x: x[2]):
	p = str(i[1])
	y = str(i[0])
	print('0' * (6 - len(p)) + p + '0' * (6 - len(y)) + y)

Submission status: Time Limit Exceeded

Solution code:
## ABC113C - ID
import sys
input = sys.stdin.readline

n, m = list(map(int, input().rstrip().split()))
arr = [list(map(int, input().rstrip().split())) for _ in range(m)]
pref = [[] for _ in range(n)]
for i in arr:
    pref[i[0] - 1] += [i]
pref = [sorted(i) for i in pref]
for i in arr:
    j = pref[i[0] - 1].index(i) + 1
    print("{:0>6}{:0>6}".format(i[0], j))

Submission status: Time Limit Exceeded

Solution code:
N, M = map(int, input().split())
C = [tuple(map(int, input().split())) for _ in range(M)]
P = {c[0]: [] for c in C}
for c in C:
    P[c[0]].append(c[1])
for p in P:
    P[p].sort()
for c in C:
    print('{:06}{:06}'.format(c[0], 1 + P[c[0]].index(c[1])))

Submission status: Time Limit Exceeded

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

p_min = min(P)
p_max = max(P)

ANS = [0] * M
for pivot in range(p_min, p_max + 1):
    if pivot not in P:
        continue
    indices = [i for i, p in enumerate(P) if p == pivot]
    extracted_y = [Y[i] for i in indices]
    extracted_y.sort()
    for i in indices:
        ANS[i] = extracted_y.index(Y[i])

for p, y in zip(P, ANS):
    print('{:06}{:06}'.format(p, y + 1))

Submission status: Time Limit Exceeded

Solution code:
n,m=map(int,input().split())
N=[[] for i in range(n)]
P=[]
Y=[]
for i in range(m):
    p,y=map(int,input().split())
    P.append(p)
    Y.append(y)
    N[p-1].append(y)
for i in N:
    i.sort()
for k in range(m):
    a='{0:06d}'.format(P[k])
    b='{0:06d}'.format(N[P[k]-1].index(Y[k])+1)
    print(a+b)

Submission status: Time Limit Exceeded

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

pn_cn = []
pn_cn_dict = {}


for _ in range(m):
    pn, cn = map(int, input().split())
    cities = pn_cn_dict.get(pn)
    if cities is None:
        cities = [cn]
    else:
        cities.append(cn)
    pn_cn_dict[pn] = cities
    pn_cn.append((pn, cn))

for k in pn_cn_dict:
    c = pn_cn_dict[k]
    c = sorted(c)
    pn_cn_dict[k] = c

for pn, cn in pn_cn:
    ci = pn_cn_dict[pn].index(cn) + 1
    print("{:06}{:06}".format(pn, ci))

Submission status: Time Limit Exceeded

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

cityNum_place_year_lst = []

for i in range(M):
    Pi, Yi = map(int, input().split())
    cityNum_place_year_lst.append((i+1, Pi, Yi))

def sort_by_year(cityNum_place_year_lst):
    if len(cityNum_place_year_lst) < 2:
        return cityNum_place_year_lst
    pivot_year = cityNum_place_year_lst[0][2]
    older = [cityNum_place_year_lst[i] for i in range(len(cityNum_place_year_lst)) if cityNum_place_year_lst[i][2] > pivot_year]
    younger = [cityNum_place_year_lst[i] for i in range(len(cityNum_place_year_lst)) if cityNum_place_year_lst[i][2] < pivot_year]
    same = [cityNum_place_year_lst[i] for i in range(len(cityNum_place_year_lst)) if cityNum_place_year_lst[i][2] == pivot_year]

    return sort_by_year(younger) + same + sort_by_year(older)

def sort_by_place(cityNum_place_year_lst):
    if len(cityNum_place_year_lst) < 2:
        return cityNum_place_year_lst
    pivot_place = cityNum_place_year_lst[0][1]
    right = [cityNum_place_year_lst[i] for i in range(len(cityNum_place_year_lst)) if cityNum_place_year_lst[i][1] > pivot_place]
    left = [cityNum_place_year_lst[i] for i in range(len(cityNum_place_year_lst)) if cityNum_place_year_lst[i][1] < pivot_place]
    same = [cityNum_place_year_lst[i] for i in range(len(cityNum_place_year_lst)) if cityNum_place_year_lst[i][1] == pivot_place]

    return sort_by_place(left) + same + sort_by_place(right)

cityNum_place_year_lst = sort_by_year(cityNum_place_year_lst)
cityNum_place_year_lst = sort_by_place(cityNum_place_year_lst)

def make_number_2_6digits_str(n):
    s = str(n)
    zeros = ""
    for i in range(6-len(s)):
        zeros += "0"
    return zeros + s



def make_identifing_num(cityNum_place_year_lst):
    cityNum, place, year = cityNum_place_year_lst.pop(0)
    place = make_number_2_6digits_str(place)
    cityNum_place_year_lst.append((cityNum, place + "000001"))
    last_place = place
    count = 1
    for _ in range(1, M):
        cityNum, place, year = cityNum_place_year_lst.pop(0)
        place = make_number_2_6digits_str(place)
        if place == last_place:
            count += 1
            x = make_number_2_6digits_str(count)
            cityNum_place_year_lst.append((cityNum, place + x))
        else:
            count = 1
            x = make_number_2_6digits_str(count)
            cityNum_place_year_lst.append((cityNum, place + x))
        last_place = place

make_identifing_num(cityNum_place_year_lst)

cityNum_place_year_lst.sort()

for i in range(M):
    print(cityNum_place_year_lst[i][1])

Submission status: Time Limit Exceeded

Solution code:
from sys import stdin

N, M = [int(x) for x in stdin.readline().rstrip().split()]
A = [[int(x) for x in stdin.readline().rstrip().split()] for _ in range(M)]
pref = []
for k in range(N):
    pref.append(sorted([X[1] for X in A if X[0] == k + 1]))
for l in range(M):
    P = str(A[l][0])
    Y = str(pref[int(P) - 1].index(A[l][1]) + 1)
    print('0' * (6 - len(P)) + P + '0' * (6 - len(Y)) + Y)

Submission status: Time Limit Exceeded

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

n, m = map(int, input().split())
data = [[] for i in range(n+1)]
data2 = []

d2append = data2.append

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

for i in data2:
  p = i[0]
  y = i[1]
  data[p].sort()
  index = bisect.bisect_left(data[p], y) + 1
  print(str(p).zfill(6) + str(index).zfill(6))

Submission status: Time Limit Exceeded

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

n, m = map(int, input().split())
data = [[] for i in range(n+1)]
data2 = []

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

for i in data2:
  p = i[0]
  y = i[1]
  data[p].sort()
  index = bisect.bisect_left(data[p], y) + 1
  print(str(p).zfill(6) + str(index).zfill(6))

Submission status: Time Limit Exceeded

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

n, m = map(int, input().split())
data = [[] for i in range(n+1)]
data2 = []

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

for i in range(m):
  p = data2[i][0]
  y = data2[i][1]
  data[p].sort()
  index = bisect.bisect_left(data[p], y) + 1
  print(str(p).zfill(6) + str(index).zfill(6))

Submission status: Time Limit Exceeded

Solution code:
from __future__ import print_function
import numpy as np
import sys
import math,string,itertools,fractions,heapq,collections,re,array,bisect,copy,functools
import heapq
from heapq import heappush
from heapq import heappop
import random


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

n,m = map(int, input().split())
p=np.zeros(m+1,dtype=int)
y=np.zeros(m+1,dtype=int)
for i in range(1,m+1):
    p[i],y[i] = map(int, input().split())


l_pref=[[] for _ in range(n+1)]    # 県の数(==n)だけ空リストを用意
for i in range(1,m+1):
    l_pref[p[i]].append((y[i],i))
for i in range(1,n+1):
    l_pref[i].sort()

# eprint(l_pref)


lll = np.zeros(m+1,dtype=(int,int))
for i in range(1,n+1):
    for j in range(len(l_pref[i])):
        lll[l_pref[i][j][1]] = j+1
# eprint(lll)

for i in range(1,m+1):
    # temp =  l_pref[p[i]].index((y[i],i))  + 1
    print("0"*(6-len(str(p[i])))  +  str(p[i])  +  "0"*(6-len(str(lll[i]))) + str(lll[i]) )

Submission status: Time Limit Exceeded

Solution code:
from __future__ import print_function
import numpy as np
import sys
import math,string,itertools,fractions,heapq,collections,re,array,bisect,copy,functools
import heapq
from heapq import heappush
from heapq import heappop
import random


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

n,m = map(int, input().split())
p=np.zeros(m+1,dtype=int)
y=np.zeros(m+1,dtype=int)
for i in range(1,m+1):
    p[i],y[i] = map(int, input().split())


l_pref=[[] for _ in range(n+1)]    # 県の数(==n)だけ空リストを用意
for i in range(1,m+1):
    l_pref[p[i]].append((y[i],i))
for i in range(1,n+1):
    l_pref[i].sort()

eprint(l_pref)


for i in range(1,m+1):
    temp =  l_pref[p[i]].index((y[i],i))  + 1
    print("0"*(6-len(str(p[i])))  +  str(p[i])  +  "0"*(6-len(str(temp))) + str(temp) )

Submission status: Time Limit Exceeded

Solution code:
import bisect

n, m = map(int, input().split())
data = [[] for i in range(n+1)]
data2 = []

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

for i in range(m):
  p = data2[i][0]
  y = data2[i][1]
  data[p].sort()
  index = bisect.bisect_left(data[p], y) + 1
  print(str(p).zfill(6) + str(index).zfill(6))

Submission status: Time Limit Exceeded

Solution code:
import bisect

n, m = map(int, input().split())
data = [[] for i in range(n+1)]
data2 = []

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

for i in range(m):
  p = data2[i][0]
  y = data2[i][1]
  data[p].sort()
  index = bisect.bisect_left(data[p], y) + 1
  print('{:0=6}'.format(p) + '{:0=6}'.format(index))

Submission status: Time Limit Exceeded

Solution code:
import bisect

n, m = map(int, input().split())
data = [[] for i in range(n+1)]
data2 = []

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

for i in range(m):
  p = data2[i][0]
  y = data2[i][1]
  data[p].sort()
  index = bisect.bisect_left(data[p], y)
  print('{:0=6}'.format(p) + '{:0=6}'.format(index+1))

Submission status: Time Limit Exceeded

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

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

for i in range(m):
  count = 0
  p = data2[i][0]
  y = data2[i][1]
  for j in data[p]:
    if j < y:
      count += 1
  print('{:0=6}'.format(p) + '{:0=6}'.format(count+1))

Submission status: Time Limit Exceeded

Solution code:
n,m = map(int, input().split())
Y = [[] for _ in range(n)]
L = []
for i in range(m):
    p,yi = map(int, input().split())
    Y[p-1].append(yi)
    L.append(yi)
for i in range(n):
    Y[i].sort()
    for k in range(len(Y[i])):
        L[L.index(Y[i][k])] = str(i+1).rjust(6,"0") + str(k+1).rjust(6,"0")
for j in range(len(L)): print(L[j])

Submission status: Time Limit Exceeded

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

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

for py in PY:
    l[py[0]].append(py[1])

for py in PY:
    l[py[0]].sort()

for py in PY:
    print('{:0>6}'.format(py[0]) + '{:0>6}'.format(l[py[0]].index(py[1]) + 1))

Submission status: Time Limit Exceeded

Solution code:
# -*- coding: utf-8 -*-
"""
Created on Thu May 16 10:21:56 2019

@author: avina
"""
from collections import defaultdict
n,m = map(int, input().split())
l = []
k = defaultdict(list)
for i in range(m):
  a,b = map(int, input().split())
  k[a].append(b)
  l.append([a,b,0])

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

for i in range(m):
    a = l[i][0];b = l[i][1]
    f = k[a].index(b) + 1
    a = str(a); f = str(f)
    r = '0'*(6 - len(a)) + a + '0'*(6 - len(f)) + f
    print(r)

Submission status: Time Limit Exceeded

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

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

ypi.sort()

rank = [[] for i in range(N)]

for count in range(M):
    y, p, i = ypi[count]
    rank[p-1].append([i, p, y])

for count in range(M):
    i, p, y = ipy[count]
    ansp = p
    ansy = rank[p-1].index([i, p, y]) + 1

    print('{:06}'.format(ansp)+'{:06}'.format(ansy))

Submission status: Time Limit Exceeded

Solution code:
#C-113
n, m = [int(i) for i in input().split()]
py = []
py_dict = {}
for mi in range(m):
  p, y = [int(i) for i in input().split()]
  py.append([p,y])
  py_dict[mi]=[p,y]
py.sort()
for mi in range(m):
  pref = py_dict[mi][0]
  x = [py[i][1] for i in range(m) if py[i][0] == pref].index(py_dict[mi][1])+1
  print("{:06}{:06}".format(pref,x))

Submission status: Time Limit Exceeded

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

cs = {}
for p, y in PY:
	if not p in cs:
		cs[p] = [y]
	else:
		cs[p] += [y]

for v in cs.values():
	v.sort()

for p, y in PY:
	print("{:06d}{:06d}".format(p, cs[p].index(y) + 1))

Submission status: Time Limit Exceeded

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

city = {}
for i in all_city:
    if i[0] in city:
        city[i[0]].append(i[1])
    else:
        city[i[0]] = [i[1]]

for i,k in city.items():
    city[i] = sorted(k)

def change_Prefecture_code(prefecture):
    return str(prefecture).zfill(6)

def change_birth_code(birth_num):
    return str(birth_num).zfill(6)


for i in all_city:
    city_num = i[0]
    ind = city[city_num].index(i[1]) + 1
    print(change_Prefecture_code(city_num) + change_birth_code(ind))

Submission status: Time Limit Exceeded

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

city = {}
for i in all_city:
    if i[0] in city:
        city[i[0]].append(i[1])
    else:
        city[i[0]] = [i[1]]


for i,k in city.items():
    city[i] = sorted(k)

def change_Prefecture_code(prefecture):
    return str(prefecture).zfill(6)

def change_birth_code(birth_num):
    return str(birth_num).zfill(6)

for i in all_city:
    print(change_Prefecture_code(i[0]) + change_birth_code(city[i[0]].index(i[1]) + 1))

Submission status: Time Limit Exceeded

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

city = {}
for i in all_city:
    if i[0] in city:
        city[i[0]].append(i[1])
    else:
        city[i[0]] = [i[1]]

for i,k in city.items():
    city[i] = sorted(k)

def change_Prefecture_code(prefecture):
    return str(prefecture).zfill(6)

def change_birth_code(birth_num):
    return str(birth_num).zfill(6)

for i in all_city:
    print(change_Prefecture_code(i[0]) + change_birth_code(city[i[0]].index(i[1]) + 1))

Submission status: Time Limit Exceeded

Solution code:
# -*- coding: utf-8 -*-
from operator import itemgetter

N, M = list(map(int, input().split()))
A = [[0] * 4 for i in range(M)]
P = []
for i, a in enumerate(A):
    a[0], a[1] = list(map(int, input().split()))
    a[2] = i
    if not a[0] in P:
        P.append(a[0])

P_counts = [0]*len(P)
sorted_A = sorted(A, key=itemgetter(1))

for a in sorted_A:
    idx = P.index(a[0])
    P_counts[idx] += 1
    a[3] = str(a[0]).zfill(6) + str(P_counts[idx]).zfill(6)

B = sorted(sorted_A, key=itemgetter(2))
for b in B:
    print(b[3])

Submission status: Time Limit Exceeded

Solution code:
# -*- coding: utf-8 -*-
from operator import itemgetter

N, M = list(map(int, input().split()))
A = [[0] * 4 for i in range(M)]
for i in range(M):
    A[i][0], A[i][1] = list(map(int, input().split()))
    A[i][2] = i

P = list(set([a[0] for a in A]))
P_counts = [0]*len(P)
sorted_A = sorted(A, key=itemgetter(1))

for a in sorted_A:
    idx = P.index(a[0])
    P_counts[idx] += 1
    a[3] = str(a[0]).zfill(6) + str(P_counts[idx]).zfill(6)

B = sorted(sorted_A, key=itemgetter(2))
for b in B:
    print(b[3])

Submission status: Time Limit Exceeded

Solution code:
# -*- coding: utf-8 -*-
from operator import itemgetter

N, M = list(map(int, input().split()))
A = [0]*M
P = [0] * M
for i in range(M):
    A[i] = [0]*4
    A[i][0], A[i][1] = list(map(int, input().split()))
    A[i][2] = i
    P[i] = A[i][0]

p_unique = list(set(P))
p_unique_count = [0]*len(p_unique)
a = sorted(A, key=itemgetter(1))


def create_number(p, x):
    return str(p).zfill(6) + str(x).zfill(6)


for i in range(M):
    idx = p_unique.index(a[i][0])
    p_unique_count[idx] += 1
    number = create_number(a[i][0], p_unique_count[idx])
    a[i][3] = number

B = sorted(a, key=itemgetter(2))
for b in B:
    print(b[3])

Submission status: Time Limit Exceeded

Solution code:
n, m = tuple([int(i) for i in input().split(' ')])
p_y  = []
y = {i: [] for i in range(1, n + 1)}

for i in range(m):
    p_y.append(tuple([int(i) for i in input().split(' ')]))
    y[p_y[i][0]].append(p_y[i][1])

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

for k, v in p_y:
    print(str(k).zfill(6) + str(y[k].index(v) + 1).zfill(6))

Submission status: Time Limit Exceeded

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

argmax = lambda a: a.index(max(a))
ids = {i:[] for i in range(1, N+1)}
[ids[p].append(y) for p, y in cities]
for k in ids:
    for _ in ids[k]:
        ids[k][argmax(ids[k])] = 0
        ids[k] = list(map(lambda x: x+1, ids[k]))

[print("{:06}{:06}".format(p, ids[p].pop(0))) for p, _ in cities]

Submission status: Time Limit Exceeded

Solution code:
import numpy as np

n, m = list(map(int, input().split()))
py = np.array([list(map(int, input().split())) for _ in range(m)])

py = np.array(py)
order = np.argsort(py[:, 1])
argsorted = py[order]

count_below_same_class = []
visited = dict()
visited_keys = []
for i in range(m):
    p = argsorted[i, 0]
    if p not in visited_keys:
        count_below_same_class.append(0)
        visited[p] = 0
        visited_keys.append(p)
    else:
        count_below_same_class.append(visited[p] + 1)
        visited[p] += 1

inv_order = np.argsort(order)

for i in range(m):
    first = str(py[i, 0]).zfill(6)
    second = str(count_below_same_class[inv_order[i]] + 1).zfill(6)
    print(first + second)

Submission status: Time Limit Exceeded

Solution code:
N, M = map(int,input().split())
L = []
for i in range(M):
    p, y = map(int,input().split())
    L.append((p,y))
PY = sorted(L, key = lambda x: x[1])
from collections import defaultdict
d = defaultdict(list)
for p,y in PY:
    d[p].append(y)
for i in range(M):
    p,y = L[i]
    print("{:06}{:06}".format(p, d[p].index(y)+1))

Submission status: Time Limit Exceeded

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))
PY = sorted(L)
from collections import defaultdict
d = defaultdict(list)
for p,y,i in PY:
    d[p].append(y)
for i in range(M):
    p,y,j = L[i]
    print("{:06}{:06}".format(p, d[p].index(y)+1))