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())
Vs = [ list(map(int, input().split())) for _ in range(M)]

d = dict()

for v in Vs:
    if v[0] in d:
        d[v[0]].append(v[1])
    else:
        d[v[0]] = [v[1]]

for k, v in d.items():
    s = sorted(v)
    d[k] = s

for v in Vs:
    ind = d[v[0]].index(v[1])
    print(str(v[0]).zfill(6) + str(ind+1).zfill(6))

Submission status: Time Limit Exceeded

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

import numpy as np

def main():
    M_list = []
    y_array = np.array([[10000000000]*M]*N)
    for i in range(M):
        tmp = list(map(int, input().split()))
        M_list.append(tmp[0])
        y_array[tmp[0]-1,i] = tmp[1]

    num_array = np.zeros([N,M])
    ynum_array = np.ones([N,M])
    for k in range(N):
        a = np.argsort(y_array[k])
        tmp = 1
        for l in a:
            #print(int(y_array[k][l]))
            if int(y_array[k][l]) == 10000000000:
                #print('break')
                break
            ynum_array[k][l] = tmp
            tmp += 1

    for j in range(M):
        ac = (str(M_list[j]).zfill(6)) + (str(int(ynum_array[M_list[j]-1][j])).zfill(6))
        print(ac)
        
    #print(y_array)

if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
# ABC 113 C

import numpy as np

def resolve():
    N, M = map(int, input().split())

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

    cities = []

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

    for a in arr:
        a.sort()

    for city in cities:
        idx = arr[city[0]].index(city[1]) + 1
        print('%06d%06d' % (city[0], idx))


if __name__ == "__main__":
    resolve()

Submission status: Time Limit Exceeded

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

import numpy as np

def main():
    M_list = []
    y_array = np.array([[10000000000]*M]*N)
    for i in range(M):
        tmp = list(map(int, input().split()))
        M_list.append(tmp[0])
        y_array[tmp[0]-1,i] = tmp[1]

    num_array = np.zeros([N,M])
    ynum_array = np.ones([N,M])
    for k in range(N):
        #print(np.argsort(y_array[k]))
        #num_array[k,:] = np.argsort(y_array[k])
        #y_sorted = np.sort(y_array)
        a = np.argsort(y_array[k])
        tmp = 1
        for l in a:
            if int(ynum_array[k][l]) == 10000000000:
                break
            ynum_array[k][l] = tmp
            tmp += 1

    for j in range(M):
        ac = (str(M_list[j]).zfill(6)) + (str(int(ynum_array[M_list[j]-1][j])).zfill(6))
        print(ac)
        
    #print(y_array)

if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

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

import numpy as np

def main():
    M_list = []
    y_array = np.array([[10000000000]*M]*N)
    for i in range(M):
        tmp = list(map(int, input().split()))
        M_list.append(tmp[0])
        y_array[tmp[0]-1,i] = tmp[1]

    num_array = np.zeros([N,M])
    ynum_array = np.ones([N,M])
    for k in range(N):
        #print(np.argsort(y_array[k]))
        #num_array[k,:] = np.argsort(y_array[k])
        y_sorted = np.sort(y_array)
        tmp = 1
        for l in np.argsort(y_array[k]):
            if int(ynum_array[k][l]) == 10000000000:
                break
            ynum_array[k][l] = tmp
            tmp += 1

    for j in range(M):
        ac = (str(M_list[j]).zfill(6)) + (str(int(ynum_array[M_list[j]-1][j])).zfill(6))
        print(ac)
        
    #print(y_array)

if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

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

import numpy as np

def main():
    M_list = []
    y_array = np.array([[10000000000]*M]*N)
    for i in range(M):
        tmp = list(map(int, input().split()))
        M_list.append(tmp[0])
        y_array[tmp[0]-1,i] = tmp[1]

    num_array = np.zeros([N,M])
    ynum_array = np.ones([N,M])
    for k in range(N):
        #print(np.argsort(y_array[k]))
        num_array[k,:] = np.argsort(y_array[k])
        y_sorted = np.sort(y_array)
        tmp = 1
        for l in np.argsort(y_array[k]):
            if int(ynum_array[k][l]) == 10000000000:
                break
            ynum_array[k][l] = tmp
            tmp += 1

    for j in range(M):
        ac = (str(M_list[j]).zfill(6)) + (str(int(ynum_array[M_list[j]-1][j])).zfill(6))
        print(ac)
        
    #print(y_array)

if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

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

import sys
import math
import bisect
sys.setrecursionlimit(1000000000)
from heapq import heappush, heappop,heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
inf = float('inf')
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))


n,m = LI()
lst = [[] for _ in range(n)]
py = [LI() for _ in range(m)]
for i in range(m):
    p,y = py[i]
    lst[p-1].append(y)
for i in lst:
    i.sort()
for i in range(m):
    p,y = py[i]
    s1 = '00000' + str(p)
    s2 = '00000' + str(lst[p-1].index(y)+1)
    ans = s1[-6:] + s2[-6:]
    print(ans)

Submission status: Time Limit Exceeded

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

import sys
import math
import bisect
sys.setrecursionlimit(1000000000)
from heapq import heappush, heappop,heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
inf = float('inf')
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))


n,m = LI()
lst = [[] for _ in range(n)]
py = [LI() for _ in range(m)]
for i in range(m):
    p,y = py[i]
    lst[p-1].append(y)

ans = []
for i in lst:
    i.sort()
for i in range(m):
    p,y = py[i]
    s1 = '00000' + str(p)
    s2 = '00000' + str(lst[p-1].index(y)+1)
    s = s1[-6:] + s2[-6:]
    ans.append(s)
for i in ans:
    print(i)

Submission status: Time Limit Exceeded

Solution code:
N,M= list(map(int, input().split()))
li=[list(map(int,input().split())) for _ in range(M)]
lisorted=sorted(li)
div=[0 for _ in range(N)]
memo=0
check=0
for i in range(M):
    if memo!=lisorted[i][0]:
        div[lisorted[i][0]-1]=check
        memo=lisorted[i][0]
        check+=1
    else:
        check+=1
for i in li:
    print("{0:06d}".format(i[0]),end="")
    tmp=lisorted.index(i)-div[i[0]-1]+1
    print("{0:06d}".format(tmp))

Submission status: Time Limit Exceeded

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

cities_prefec = {}
pref_ids = []
years = []

for i in range(M):
    prefec_id, year = map(int, input().split())

    pref_ids.append(prefec_id)
    years.append(year)

    if prefec_id in cities_prefec:
        bisect.insort(cities_prefec[prefec_id], year)
    else:
        cities_prefec[prefec_id] = [year]

for i in range(M):
    p_id = pref_ids[i]
    cn = bisect.bisect_left(cities_prefec[p_id], years[i]) + 1
    print("{0:0>6}{1:0>6}".format(p_id, cn))

Submission status: Time Limit Exceeded

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

cities_prefec = {}
data = []
cities = []
years = []

for i in range(M):
    prefec_id, year = map(int, input().split())

    data.append(
        {
            "pref_id": prefec_id,
            "year": year
        }
    )

    if prefec_id in cities_prefec:
        bisect.insort(cities_prefec[prefec_id], year)
    else:
        cities_prefec[prefec_id] = [year]


for d in data:
    p_id = d["pref_id"]
    cn = bisect.bisect_left(cities_prefec[p_id], d["year"]) + 1
    print("{0:0>6}{1:0>6}".format(p_id, cn))

Submission status: Time Limit Exceeded

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

cities_prefec = {}
data = []
cities = []
years = []

for i in range(M):
    prefec_id, year = map(int, input().split())

    data.append(
        {
            "pref_id": prefec_id,
            "year": year
        }
    )

    if prefec_id in cities_prefec:
        bisect.insort(cities_prefec[prefec_id], year)
    else:
        cities_prefec[prefec_id] = [year]


for d in data:
    p_id = d["pref_id"]
    cn = bisect.bisect_left(cities_prefec[p_id], d["year"]) + 1
    print("{p_id:0>6}{cn:0>6}".format(**locals()))

Submission status: Time Limit Exceeded

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

cities_prefec = {}
data = []
cities = []
years = []

for i in range(M):
    prefec_id, year = map(int, input().split())

    data.append(
        {
            "pref_id": prefec_id,
            "year": year
        }
    )

    if prefec_id in cities_prefec:
        bisect.insort(cities_prefec[prefec_id], year)
    else:
        cities_prefec[prefec_id] = [year]


for d in data:
    p_id = d["pref_id"]
    cn = cities_prefec[p_id].index(d["year"]) + 1
    print("{p_id:0>6}{cn:0>6}".format(**locals()))

Submission status: Time Limit Exceeded

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

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

pref = [[0] for i in range(N+1)]
import collections
q = collections.deque()

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

for p,y in q:
    print("%06d%06d" %(p, pref[p].index(y)))

Submission status: Time Limit Exceeded

Solution code:
import math
import sys
from itertools import accumulate
from functools import reduce
import queue
from fractions import gcd

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

def combination_count(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

def permutations_count(n, r):
    return math.factorial(n) // math.factorial(n - r)

sys.setrecursionlimit(10000)

mod = 1000000007

"""
# 0埋め, 小数点出力桁指定時のときの出力
a = 100
b = 0.987654321
print("{0:06d}-{1:6f}".format(a,b))
000100-0.987654

# 文字列をリストに格納
char_list = list("abcd") # ["a","b","c","d"]

# 標準入力取得
## 文字列
    = sys.stdin.readline().rstrip()
    = list(sys.stdin.readline().rstrip())

## 数値
    = int(sys.stdin.readline())
    = map(int, sys.stdin.readline().split())
    = list(map(int, sys.stdin.readline().split()))
    = [list(map(int,list(sys.stdin.readline().split()))) for i in range(h)]  # 二次元配列入力　二次元マップみたいな入力のとき
"""

if __name__ == "__main__":
    N, M = map(int, sys.stdin.readline().split())
    L = [list(map(int,list(sys.stdin.readline().split()))) for i in range(M)]
    sL = sorted(L, key=lambda x : x[0])

    d = {}
    for l in sL:
        if l[0] not in d:
            d[l[0]] = [l[1]]
        else:
            d[l[0]].append(l[1])

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

    for l in L:
        key = l[0]
        val = l[1]
        num = d[key].index(val) + 1
        print("{}{}".format(str(key).zfill(6),str(num).zfill(6)))

Submission status: Time Limit Exceeded

Solution code:
N,M = map(int,input().split())
cities = [[] for _ in range(N)]
order_p = []
order_y = []
for _ in range(M):
    p,y = map(int,input().split())
    cities[p-1].append(y)
    order_p.append(p)
    order_y.append(y)
#print(cities)
for pref in range(N):
    cities[pref].sort()
#print(cities)
for key_pref, key_year in zip(order_p,order_y):
    print(str(key_pref).zfill(6)+str((cities[key_pref-1].index(key_year))+1).zfill(6))

Submission status: Time Limit Exceeded

Solution code:
from collections import defaultdict
import bisect
N, M = map(int, input().split())
P = [[int(i) for i in input().split()] for _ in range(M)]
D = defaultdict(list)

for p, y in sorted(P):
  D[p] += [y]
  
for p, y in P:
  z = D[p].index(y)
  print ("%06d%06d"%(p, z+1))

Submission status: Time Limit Exceeded

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


n,m=map(int,input().split())
l=[[0,0] for _ in range(m)]
p=[[] for _ in range(n)]

for i in range(m):
        l[i][0],l[i][1]=map(int,input().split())
        p[l[i][0]-1].append(l[i][1])
for i in range(n):
        p[i].sort()
for i in range(m):
        for j in range(len(p[l[i][0]-1])):
                if p[l[i][0]-1][j]==l[i][1]:
                        c=j+1
                        print(str(l[i][0]).zfill(6)+str(c).zfill(6))
                        break

Submission status: Time Limit Exceeded

Solution code:
N,M = map(int,input().split())
PY = [[int(i) for i in input().split()]for i in range(M)]
l = [[] for i in range(N+1)]
for p,y in PY:
    l[p].append(y)
for i in range(N+1):
    l[i].sort()
for p,y in PY:
    print(str(p).zfill(6),end="")
    print(str(l[p].index(y)+1).zfill(6))

Submission status: Time Limit Exceeded

Solution code:
N, M = map(int, input().split())
lis = []
for index in range(M):
	p, y = map(int, input().split())
	lis.append((p, y, index))

n_lis = []
for unique_p in range(1, N+1):
	tmp = [(p, y, index) for p, y, index in lis if p == unique_p]
	tmp = sorted(tmp, key=lambda x: x[1])
	for born, val in enumerate(tmp, start=1):
		p, y, index = val
		n_lis.append((p, y, index, born))

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

for p, _, _, born in n_lis:
	print('{}{}'.format(str(p).zfill(6), str(born).zfill(6)))

Submission status: Time Limit Exceeded

Solution code:
P,C = map(int,input().split())
pref = [[] for _ in range(P)]
city = []
for ci in range(C):
  p,y = map(int,input().split())
  city.append(p-1)
  pref[p-1].append([y,ci])
cinp = []
for pi in range(P):
  pref[pi].sort()
  cnow = ['null' for _ in range(C)]
  for j in range(len(pref[pi])):
    citycode = pref[pi][j][1]
    cnow[citycode] = j
  cinp.append(cnow)
for ci in range(C):
  pnow = city[ci]
  inow = cinp[pnow][ci]
  try:
    ans = (pnow+1) * 10 ** 6 + (inow+1)
  except:
    print(pnow,inow,p,cinp)
  ANS = str(ans)
  print( '0' * (12 - len(ANS)) + ANS)

Submission status: Time Limit Exceeded

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

ans = [None] * M
for i in range(len(D)):
  new_d = sorted(D[i])
  for j in range(len(new_d)):
    a = str(i+1).zfill(6)
    b = str(new_d.index(D[i][j])+1).zfill(6)
    n = Y.index(D[i][j])
    ans[n] = a+b
print(*ans, sep = '\n')

Submission status: Time Limit Exceeded

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

for l in D:
  l.sort()

for i in range(M):
  a = str(P[i]).zfill(6)
  b = str(D[P[i]-1].index(Y[i])+1).zfill(6)
  print(a+b)

Submission status: Time Limit Exceeded

Solution code:
N, M = map(int, input().split())
P = []
Y = []
D = {}
for i in range(M):
  p, y = map(int, input().split())
  P.append(p)
  Y.append(y)
  if p in D:
    D[p].append(y)
  else:
    D[p] = [y]

for i in D.keys():
  D[i].sort()

for i in range(M):
  a = str(P[i]).zfill(6)
  b = str(D[P[i]].index(Y[i])+1).zfill(6)
  print(a+b)

Submission status: Time Limit Exceeded

Solution code:
N, M = map(int, input().split())
P = []
Y = []
D = {}
for i in range(M):
  p, y = map(int, input().split())
  P.append(p)
  Y.append(y)
  if p in D:
    D[p].append(y)
  else:
    D[p] = [y]

for p in D:
  D[p] = sorted(D[p])
answer = []

for i in range(M):
  a = str(P[i]).zfill(6)
  b = str(D[P[i]].index(Y[i])+1).zfill(6)
  print(a+b)

Submission status: Time Limit Exceeded

Solution code:
import bisect
n,m=map(int, input().split())
pl=[0]*100000
yl=[0]*100000
ol=[[] for i in range(100001)]
for i in range(m):
    pl[i],yl[i] = map(int, input().split())
    ol[pl[i]].append(yl[i])
for i in range(1,n+1):
    ol[i].sort()
for i in range(m):
    print("%06d%06d" % (pl[i], ol[pl[i]].index(yl[i])+1))

Submission status: Time Limit Exceeded

Solution code:
import bisect
n,m=map(int, input().split())
pl=[0]*100000
yl=[0]*100000
ol=[[] for i in range(100001)]
for i in range(m):
    pl[i],yl[i] = map(int, input().split())
    bisect.insort_left(ol[pl[i]], yl[i])
for i in range(m):
    x = bisect.bisect_right(ol[pl[i]], yl[i])
    print("%06d%06d" % (pl[i], x))

Submission status: Time Limit Exceeded

Solution code:
n,m=map(int, input().split())
pl=[0]*m
yl=[0]*m
cl=[0]*m
ppl=[[] for j in range(n+1)]
for i in range(m):
    pl[i],yl[i] = map(int, input().split())
    cnt=1
    for j in ppl[pl[i]]:
        if yl[i] < yl[j]:
            cl[j] += 1
        else:
            cnt+=1
    ppl[pl[i]].append(i)
    cl[i] = cnt
for i in range(m):
    print("%06d%06d" % (pl[i], cl[i]))

Submission status: Time Limit Exceeded

Solution code:
n,m=map(int, input().split())
pl=[0]*m
yl=[0]*m
sl={}
cl=[0]*m
for i in range(m):
    p,y = map(int, input().split())
    pl[i]=p
    yl[i]=y
    if not p in sl:
        sl[p] = []
    sl[p].append((y, i))

for k, s in sl.items():
    sl[k] = sorted(s)

for i in range(m):
    p=pl[i]
    for j, tl in enumerate(sl[p]):
        if tl[1]==i:
            cl[i] = j+1

for i in range(m):
    print("%06d%06d" % (pl[i], cl[i]))

Submission status: Time Limit Exceeded

Solution code:
n,m=map(int, input().split())
pl=[0]*m
yl=[0]*m
sl={}
cl=[0]*m
for i in range(m):
    p,y = map(int, input().split())
    pl[i]=p
    yl[i]=y
    if not p in sl:
        sl[p] = [(y, i)]
        continue
    no=True
    for j, tl in enumerate(sl[p]):
        if tl[0] > y:
            sl[p].insert(j, (y, i))
            no=False
            break
    if no:
        sl[p].append((y, i))

for i in range(m):
    p=pl[i]
    for j, tl in enumerate(sl[p]):
        if tl[1]==i:
            cl[i] = j+1

for i in range(m):
    print("%06d%06d" % (pl[i], cl[i]))

Submission status: Time Limit Exceeded

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

for i in range(M):
    P[i], Y[i] = map(int, input().split())
    check[P[i]-1].append(Y[i])

for i in range(N):
    check[i].sort()

for i in range(M):
    tmp1 = ('00000' + str(P[i]))[-6:] 
    tmp2 = ('00000' + str(check[P[i]-1].index(Y[i])+1))[-6:]
    tmp = tmp1 + tmp2
    print(tmp)

Submission status: Time Limit Exceeded

Solution code:
import numpy as np

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

p_ls = []
y_ls = []
for _ in range(M):
    p,y = map(int,input().split(" "))
    p_ls.append(p)
    y_ls.append(y)

p_ar = np.array(p_ls)
y_ar = np.array(y_ls)


# 市ごとに連続するようにする
sort_ind = p_ar.argsort()
p_sorted = p_ar[sort_ind]
y_sorted = y_ar[sort_ind]
x_ar = np.zeros(len(p_ls))
x_ar_sorted = np.zeros(len(p_ls))

ind = M-1

while ind >= 0:
    min_ind = p_sorted[:ind+1].argmax() 
    tmp_x = y_sorted[min_ind:ind+1].argsort()+min_ind
    x_ar_sorted[tmp_x] = np.array(range(len(tmp_x)))+1
    ind = min_ind-1

x_ar[sort_ind] = x_ar_sorted

for i in range(M):
    print('%06d'%p_ar[i] + '%06d'%x_ar[i])

Submission status: Time Limit Exceeded

Solution code:
import numpy as np

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

py_ls =[list(map(int,input().split(" "))) for _ in range(M)]
    
py_ar = np.array(py_ls)


# 市ごとに連続するようにする
py_T = py_ar.T
sort_ind = py_T[0].argsort()
p_sorted = py_T[0][sort_ind]
y_sorted = py_T[1][sort_ind]
x_ar = np.zeros(len(py_ls))
x_ar_sorted = np.zeros(len(py_ls))

ind = 0

while ind < M:
    d = 0
    while ind+d < M-1 and p_sorted[ind] == p_sorted[ind+d+1]:
        d+=1
    tmp_x = y_sorted[ind:ind+d+1].argsort()+ind
    x_ar_sorted[tmp_x] = np.array(range(len(tmp_x)))+1
    ind = ind + d + 1

x_ar[sort_ind] = x_ar_sorted

for i in range(M):
    print('%06d'%py_T[0][i] + '%06d'%x_ar[i])

Submission status: Time Limit Exceeded

Solution code:
import numpy as np

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

p_ls = []
y_ls = []
for _ in range(M):
    p,y = map(int,input().split(" "))
    p_ls.append(p)
    y_ls.append(y)

p_ar = np.array(p_ls)
y_ar = np.array(y_ls)


# 市ごとに連続するようにする
sort_ind = p_ar.argsort()
p_sorted = p_ar[sort_ind]
y_sorted = y_ar[sort_ind]
x_ar = np.zeros(len(p_ls))
x_ar_sorted = np.zeros(len(p_ls))

ind = 0

while ind < M:
    d = 0
    while ind+d < M-1 and p_sorted[ind] == p_sorted[ind+d+1]:
        d+=1
    tmp_x = y_sorted[ind:ind+d+1].argsort()+ind
    x_ar_sorted[tmp_x] = np.array(range(len(tmp_x)))+1
    ind = ind + d + 1

x_ar[sort_ind] = x_ar_sorted

for i in range(M):
    print('%06d'%p_ar[i] + '%06d'%x_ar[i])

Submission status: Time Limit Exceeded

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

for i in range(M):
    P[i], Y[i] = map(int, input().split())
    check[P[i]-1].append(Y[i])

for i in range(N):
    check[i].sort()

for i in range(M):
    print(('000000' + str(P[i]))[-6:] + ('000000' + str(check[P[i]-1].index(Y[i])+1))[-6:])

Submission status: Time Limit Exceeded

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

for i in range(M):
    P[i], Y[i] = map(int, input().split())
    check[P[i]-1].append(Y[i])

for i in range(N):
    check[i].sort()

for i in range(M):
    tmp1 = ('000000' + str(P[i]))[-6:]
    tmp2 = ('000000' + str(check[P[i]-1].index(Y[i])+1))[-6:]
    tmp = tmp1 + tmp2
    print(tmp)

Submission status: Time Limit Exceeded

Solution code:
n,m=map(int,input().split())
prev=[];ord=[[]for _ in range(n+1)]
for _ in range(m):
  a,b=map(int,input().split())
  prev.append([a,b])
  ord[a].append(b)
for i in range(n+1):
  if i!=[]:ord[i]=sorted(ord[i])
for [x,y] in prev:
  ind=ord[x].index(y)+1
  print("%06d"%x+"%06d"%ind)

Submission status: Time Limit Exceeded

Solution code:
n,m=map(int,input().split())
prev=[];ord=[[]for _ in range(n+1)]
for _ in range(m):
  a,b=map(int,input().split())
  prev.append([a,b])
  ord[a].append(b)
for i in range(n+1):
  ord[i]=sorted(ord[i])
for p in prev:
  x,y=p[0],p[1]
  ind=ord[x].index(y)+1
  print("%06d"%x+"%06d"%ind)

Submission status: Time Limit Exceeded

Solution code:
n, m = (int(i) for i in input().split()) 
p, y = [], []
yd = [[] for i in range(n+1)]
for i in range(m):
  tmp = [int(i) for i in input().split()]
  p.append(tmp[0])
  y.append(tmp[1])
  yd[p[i]].append(y[i])
for i in range(n):
  yd[i+1].sort()
for i in range(m):
  l = str(p[i])
  r = str(yd[p[i]].index(y[i])+1)
  lzero = l.zfill(6)
  rzero = r.zfill(6)
  print(lzero + rzero)

Submission status: Time Limit Exceeded

Solution code:
N,M = [int(n) for n in input().split()]
o = {}
a = []
for i in range(M):
    p,y = [int(n) for n in input().split()]
    a.append((p, y))
    if p in o:
        o[p].append(y)
    else:
        o[p] = [y]
sa = {k:sorted(o[k]) for k in o}
for ans in ((t[0], sa[t[0]].index(t[1])+1) for t in a):
    print("{}{}".format(str(ans[0]).zfill(6),str(ans[1]).zfill(6)))

Submission status: Time Limit Exceeded

Solution code:
# -*- coding: utf-8 -*-
#ABC113C
import sys

tmp = input().split()
hoge = list(map(lambda a: int(a), tmp))
n = hoge[0]
m = hoge[1]

lis=[]
x=[]
y=[]
for i in range(0,m):
	tmp = input().split()
	hoge = list(map(lambda a: int(a), tmp))
	lis.append((i,hoge[0],hoge[1]))#i,p,y
	x.append(0)
	y.append(hoge[0])

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

for i in range(1,n+1):
	number=1
	for j in range(0,m):
		if(lis[j][1]==i):
			x[lis[j][0]]=number
			number+=1

for i in range(0,m):
	print("{:0=6}{:0=6}".format(y[i],x[i]))

Submission status: Time Limit Exceeded

Solution code:
# -*- coding: utf-8 -*-
#ABC113C
import sys

tmp = input().split()
hoge = list(map(lambda a: int(a), tmp))
n = hoge[0]
m = hoge[1]

lis=[]
x=[]
y=[]
for i in range(0,m):
	tmp = input().split()
	hoge = list(map(lambda a: int(a), tmp))
	lis.append((i,hoge[0],hoge[1]))#i,p,y
	x.append(0)
	y.append(hoge[0])

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

for i in range(1,n+1):
	number=1
	for j in range(0,m):
		if(lis[j][1]==i):
			x[lis[j][0]]=number
			number+=1
#lis.sort(key=lambda x:x[0])

for i in range(0,m):
#	print("{:0=6}{:0=6}".format(lis[i][1],x[i]))
	print("{:0=6}{:0=6}".format(y[i],x[i]))

Submission status: Time Limit Exceeded

Solution code:
# -*- coding: utf-8 -*-
#ABC112C
import sys

tmp = input().split()
hoge = list(map(lambda a: int(a), tmp))
n = hoge[0]
m = hoge[1]

lis=[]
x=[]
y=[]
for i in range(0,m):
	tmp = input().split()
	hoge = list(map(lambda a: int(a), tmp))
	lis.append((i,hoge[0],hoge[1]))#i,p,y
	x.append(0)
	y.append(hoge[0])

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

for i in range(1,n+1):
	number=1
	for j in range(0,m):
		if(lis[j][1]==i):
			x[lis[j][0]]=number
			number+=1
lis.sort(key=lambda x:x[0])

for i in range(0,m):
#	print("{:0=6}{:0=6}".format(lis[i][1],x[i]))
	print("{:0=6}{:0=6}".format(y[i],x[i]))

Submission status: Time Limit Exceeded

Solution code:
# -*- coding: utf-8 -*-
#ABC112C
import sys

tmp = input().split()
hoge = list(map(lambda a: int(a), tmp))
n = hoge[0]
m = hoge[1]

lis=[]
x=[]
for i in range(0,m):
	tmp = input().split()
	hoge = list(map(lambda a: int(a), tmp))
	lis.append((i,hoge[0],hoge[1]))#i,p,y
	x.append(0)

#lis.sort(key=lambda student: student[1])
lis.sort(key=lambda x:x[2])

for i in range(1,n+1):
	number=1
	for j in range(0,m):
		if(lis[j][1]==i):
			x[lis[j][0]]=number
			number+=1
lis.sort(key=lambda x:x[0])

for i in range(0,m):
	print("{:0=6}{:0=6}".format(lis[i][1],x[i]))

Submission status: Time Limit Exceeded

Solution code:
n,m = map(int,input().split())
a = [list(map(int,input().split())) for i in range(m)]
for i in range(m):
    b = []
    for j in range(m):
        if a[i][0] == a[j][0]:
            b.append(a[j])
    b.sort(key =lambda x: x[1])
    x = str(b.index(a[i])+1)
    p = str(a[i][0])
    while len(x) < 6:
        x = "0"+x
    while len(p) < 6:
        p = "0"+p
    print(p+x)

Submission status: Time Limit Exceeded

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

for i in range(N):
    B[i].sort()

for p, y in zip(P, Y):
    print("{:06}{:06}".format(p, B[p-1].index(y) + 1))

Submission status: Time Limit Exceeded

Solution code:
n, m = (int(i) for i in input().split()) 
p, y = [], []
yd = [[] for i in range(n+1)]
for i in range(m):
  tmp = [int(i) for i in input().split()]
  p.append(tmp[0])
  y.append(tmp[1])
  yd[p[i]].append(y[i])
for i in range(n):
  yd[i+1].sort()
for i in range(m):
  l = str(p[i])
  r = str(yd[p[i]].index(y[i])+1)
  lzero = l.zfill(6)
  rzero = r.zfill(6)
  print(lzero + rzero)

Submission status: Time Limit Exceeded

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

n, m = map(int, input().split())
city = [[0] for _ in range(n)]
buffer = []

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

for i in range(n):
    city[i].sort()

for i in range(m):
    p, y = buffer[i]
    print(str(p).zfill(6) + str(city[p - 1].index(y)).zfill(6))

Submission status: Time Limit Exceeded

Solution code:
n,m = map(int, input().split())
data = []
o = {}
for i in range(m):
  p,y = map(int, input().split())
  data.append((p,y))
for i in data:
  if i[0] not in list(o.keys()):
    o[i[0]] = sorted([j[1] for j in data if j[0] == i[0]])
  print(str(i[0]).zfill(6)+str((o[i[0]].index(i[1]))+1).zfill(6))

Submission status: Time Limit Exceeded

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

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

for i in range(n):
    city[i].sort()

for i in range(m):
    p, y = buffer[i]
    print(str(p).zfill(6) + str(city[p - 1].index(y)).zfill(6))

Submission status: Time Limit Exceeded

Solution code:
n, m = map(int, input().split())
city = [[0] for _ in range(n)]
cnt = [0] * n
buffer = []

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

for i in range(n):
    city[i].sort()

for i in range(m):
    p, y = buffer[i]
    cnt[p - 1] += 1
    print(str(p).zfill(6) + str(city[p - 1].index(y)).zfill(6))

Submission status: Time Limit Exceeded

Solution code:
N,M=map(int,input().split())
pdic={}
plst,ylst=[],[]
for i in range(M):
  p,y=map(int,input().split())
  plst.append(p)
  ylst.append(y)
  if p not in pdic.keys():
    pdic[p]=[y]
  else:
    pdic[p].append(y)
for i in pdic.keys():
  pdic[i].sort()
for i in range(M):
  p,y=plst[i],ylst[i]
  print(str(p).zfill(6)+str(pdic[p].index(y)+1).zfill(6))

Submission status: Time Limit Exceeded

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

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

rank = [[] for _ in range(n)]
for p,y in x:
    rank[p-1].append([p,y])
for p,y in py:
    front = '00000'+str(p)
    back = '00000'+str(rank[p-1].index([p,y])+1)
    print(front[-6:]+back[-6:])

Submission status: Time Limit Exceeded

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

n,m = map(int,input().split())
py = [list(map(int,input().split())) for _ in range(m)]
for p,y in py:
    mi = 1
    for i,j in py:
        if p == i:
            if y > j:
                mi += 1
    p = '00000'+ str(p)
    mi = '00000' + str(mi)
    print(p[-6:]+mi[-6:])

Submission status: Time Limit Exceeded

Solution code:
N,M=map(int,input().split())
P=[]
Y=[]
seiritsu=[[]*i for i in range(N)]
for i in range(M):
  p,y=map(int,input().split())
  P.append(p)
  Y.append(y)
  seiritsu[P[i]-1].append(Y[i])
for k in range(N):
  seiritsu[k].sort()
for l in range(M):
  print(str(P[l]).zfill(6)+str(seiritsu[P[l]-1].index(Y[l])+1).zfill(6))

Submission status: Time Limit Exceeded

Solution code:
N,M=map(int,input().split())
P=[]
Y=[]
seiritsu=[]
for j in range(N):
  seiritsu.append([])
for i in range(M):
  p,y=map(int,input().split())
  P.append(p)
  Y.append(y)
  seiritsu[P[i]-1].append(Y[i])
for k in range(N):
  seiritsu[k].sort()
for l in range(M):
  print(str(P[l]).zfill(6)+str(seiritsu[P[l]-1].index(Y[l])+1).zfill(6))