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:
# - coding : utf-8 -*-
    
if __name__ == '__main__':
    n, m = map(int, raw_input().split())
    cities = []
    city_lst = {}
    for i in range(0, m):
        p, y = map(int, raw_input().split())
        cities.append((p, y))
        if not p in city_lst:
            city_lst[p] = [y]
        else:
            city_lst[p].append(y)
    for key in city_lst.keys():
        city_lst[key].sort()
    for city in cities:
        print str('%06d' % city[0]) + str('%06d' % (int(city_lst[city[0]].index(city[1]) + 1)))

Submission status: Time Limit Exceeded

Solution code:
# AtCoder Beginner Contest 097
#s = input()
#K = int(input())

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

pdic = {i:[] for i in range(N)}
outidx = {}
pl = []

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

for i in range(N):
    pdic[i] = sorted(pdic[i])

for i, j in enumerate(pl):
    #print(pdic[j])
    print('{:06}{:06}'.format(1+j, 1+pdic[j].index(outidx[i])))

Submission status: Time Limit Exceeded

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

PY_list = []
for num,i in enumerate(range(M)):
    p,y = map(int, input().split())
    PY_list = PY_list + [(num,p,y),]

rec = []
for i in range(N):
    cities = []
    for k in PY_list:
        if k[1] == i+1:
            cities = cities + [k,]
    cities = sorted(cities, key=lambda x:x[2])

    rec_list = []
    for num,k in enumerate(cities):
        rec_list = rec_list + [(k[0],str(k[1]).zfill(6) + str(num+1).zfill(6)),]

    rec = rec + rec_list
rec = sorted(rec, key=lambda x:x[0])

for s in rec:
    print(s[1])

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
N, M = map(int, input().split())
F = [list(map(int, (input().split()))) for i in range(M)]
tmp = [[] for i in range(N)]

for i in range(M):
    tmp[F[i][0]-1].append(F[i][1])

for i in range(N):
    tmp[i].sort()
    
for i in range(M):
    print(('0'*(6-len(str(F[i][0]))) + str(F[i][0])) + '0'*(6-len(str(tmp[F[i][0]-1].index(F[i][1])+1))) + str(tmp[F[i][0]-1].index(F[i][1])+1))

Submission status: Time Limit Exceeded

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

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

pp = []
for o in range(N):
    pp.append([])

for p, y in clist:
    pp[p-1].append(y)

spp = []
index = 0
for _ in range(N):
    pp[index].sort()
    index = index + 1

for p, y in clist:
    num = pp[p-1].index(y) + 1
    print('%06d' % p + '%06d' % num)

Submission status: Time Limit Exceeded

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

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

ken = [None] * N
for i in range(N):
    ken[i] = []

for i in range(M):
    ken[P[i] - 1].append(Y[i])

for i in range(N):
    ken[i] = sorted(ken[i])

city_info = [None] * M

k = 0


# 木構造
# def create_bitree(a):
#     # a = int list
#     n = len(a)
#     output = [None] * n
#
#     for i in range(n):
#         if a[i] < _:
#             output[sub_bitree()] = a[i]
#         else:
#             output[sub_bitree()] = a[i]


# count M
while(k < M):
    for l in range(N):
        for m in range(len(ken[l])):
            # ken[l][m]の値によって二分木を作る
            # if city_info[0] is None:
            #     city_info[0] = [ken[l][m], l + 1, m + 1]
            # else:

            city_info[k] = [ken[l][m], l + 1, m + 1]
            k += 1


def create_id(p, x):
    output_p = str(p)
    output_x = str(x)
    p_len = len(output_p)
    x_len = len(output_x)
    while p_len < 6:
        output_p = "0" + output_p
        p_len += 1
    while x_len < 6:
        output_x = "0" + output_x
        x_len += 1

    return output_p + output_x


# 律速？
for i in range(M):
    # Y[i]を探してきてprint
    for j in range(len(city_info)):
        if city_info[j][0] == Y[i]:
            print(create_id(city_info[j][1], city_info[j][2]))
            del city_info[j]
            break

Submission status: Time Limit Exceeded

Solution code:
N, M = map(int, raw_input().split())
D = []
for i in range(M):
	p, y = map(int, raw_input().split())
	D.append([p, y, i])
SD = sorted(D, key = lambda d: d[1])
C = [1] * (M + 1)
P = {}
for i in range(M):
	pref = SD[i][0]
	year = SD[i][1]
	city = SD[i][2]
	if not pref in P.keys():
		P[pref] = 1
	else:
		P[pref] += 1
	C[city] = P[pref]
for i in range(M):
	print "%06d%06d" % (D[i][0], C[i])

Submission status: Time Limit Exceeded

Solution code:
import math
from functools import reduce
import collections
import itertools
a = list(map(int,input().split()))
n = a[0]
m = a[1]
li = [list(map(int,input().split())) for i in range(m)]
w0 = dict()
results = {}
for i in li:
    results.setdefault(i[0], []).append(i[1])
#print(results)
for i in li:
    #print(results[i[0]])
    years = sorted(results[i[0]])
    co = 0
    for j in years:
        co += 1
        if j == i[1]:
            print("{0:06d}".format(i[0]) + "{0:06d}".format(co))

Submission status: Time Limit Exceeded

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

P=[PY_pairs[i][0] for i in range(M)]
Y=[PY_pairs[i][1] for i in range(M)]

sorted_Y=sorted(Y)

P_table=[[]]*N

for i in range(M):
	P_table[P[Y.index(sorted_Y[i])]-1]=P_table[P[Y.index(sorted_Y[i])]-1]+[Y.index(sorted_Y[i])]

answer=[0]*M
for i in range(N):
	i_pad="%06d" % (i+1)
	for j in range(len(P_table[i])):
		j_pad="%06d" % (j+1)
		answer[P_table[i][j]]=i_pad+j_pad

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

Submission status: Time Limit Exceeded

Solution code:
n,m = map(int, input().split())
li = []
countA = 1 
countB = 0

for i in range(m):
    li.append(list(map(int, input().split())))

for item in li:
    for i in range(m):
        if item[0] == li[i][0] and item[1] == li[i][1]:
            countB = 0
        elif item[0] == li[i][0]: 
            if item[1] > li[i][1]:
                countA += 1
    pr_id = str(1000000+item[0])[1:7]
    ci_id = str(1000000+countA)[1:7]
    countA = 1
    print(pr_id + ci_id)

Submission status: Time Limit Exceeded

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

for i in range(M):
    P,Y = map(int, input().split())
    n.append(P)
    k[P].append(Y)
    k[str(P)].append(Y)

for i in range(N):
    k[str(i+1)] = sorted(k[str(i+1)])

for i in range(M):
    print(str(n[i]).zfill(6) + str(k[str(n[i])].index(k[n[i]][0])+1).zfill(6))
    k[n[i]].pop(0)

Submission status: Time Limit Exceeded

Solution code:
n,p = map(int, input().split())
lst = []
for i in range(p):
  a = list(map(int, input().split()))
  lst.append(a)
lstp = []
lsty = []
for i in lst:
  lstp.append(i[0])
  lsty.append(i[1])
dic = {}
for i in range(1,max(lstp)+1):
  lsti = []
  for j in lst:
    if j[0] == i:
      lsti.append(j[1])
  lsti.sort()
  dic[i] = lsti
for k in range(p):
  x = str(lstp[k]).zfill(6)
  y = str(dic[lstp[k]].index(lsty[k])+1).zfill(6)
  print(x + y)

Submission status: Time Limit Exceeded

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

P = []
Y = []
a = {}
for m in range(M):
    p, y = (int(i) for i in input().split())
    if p in a:
        a[p].append(y)
    else:
        a[p] = [y]
    P.append(p)
    Y.append(y)

def rank(ls, i):
    r = 1
    for l in ls:
        if l < i:
            r += 1
    return r

cnt = 0
for i, p in enumerate(P):
    print('%06d' % p + '%06d' % (rank(a[p], Y[i])))

Submission status: Time Limit Exceeded

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

n,m=map(int,input().split())
l=[list(map(int,input().split())) for _ in range(m)]
#print(l)
li=sorted(l)
#print(li)
for i in l:
    a=li.index(i)+1
    if i[0]>=2:
        for j in li:
            if i[0]==j[0]:
                b=li.index(j)
                a=a-b
                break
    print(str('%06d'%i[0])+str('%06d'%a))

Submission status: Time Limit Exceeded

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

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

pp = []
for o in range(N):
    pp.append([])

for p, y in clist:
    pp[p-1].append(y)

spp = []
index = 0
for _ in range(N):
    spp.append(sorted(pp[index]))
    index = index + 1

for p, y in clist:
    num = spp[p-1].index(y) + 1
    print('%06d' % p + '%06d' % num)

Submission status: Time Limit Exceeded

Solution code:
n, m = input().strip().split(' ')
n, m = [int(n), int(m)]

p = []
y = []
id = []

for i in range(m):
    id.append(000000000000)

for i in range(m):
    a, b = input().strip().split(' ')
    a, b = [int(a), int(b)]
    p.append(a)
    y.append(b)

def order(j, k, l):
    order = 1
    for i in range(m):
        if (not i == l) and p[i] == j and y[i] < k:
            order += 1
    return order

def addzero(a):
    str = ''
    for i in range(6 - len(a)):
        str += '0'
    return str

for i in range(m):
    print(addzero(str(p[i])) + str(p[i]) + addzero(str(order(p[i], y[i], i))) + str(order(p[i], y[i], i)))

Submission status: Time Limit Exceeded

Solution code:
n, m = map(int,input().split())
zan = [[] for _ in range(n)]
ans = []
for r in range(m):
    p, y = map(int,input().split())
    zan[p-1].append(y)
    ans.append(y)
for i in range(n):
    zan[i].sort()
    for j in range(len(zan[i])):
        k = ans.index(zan[i][j])
        x = '{:0>6}'.format(i+1)
        y = '{:0>6}'.format(j+1)
        ans[k] = x + y
for f in ans:
    print(f)

Submission status: Time Limit Exceeded

Solution code:
N, M =map(int, input().split())
Ps =[]
Ys =[]
dic = {}
for i in range(M):
    p, y = map(int, input().split())
    Ps.append(p)
    Ys.append(y)
    ls = dic.get(p, [])
    ls.append(y)
    ls.sort()
    dic[p] = ls
for i in range(M):
    p = Ps[i]
    y = Ys[i]
    number = dic[p].index(y) + 1
    strp = str(p)
    strn = str(number)
    print(strp.zfill(6) + strn.zfill(6))

Submission status: Time Limit Exceeded

Solution code:
import bisect
N, M = map(int, input().split())
P, Y = [], []
pref = [[] for _ in range(N+1)] # non-0-indexed
for m in range(M):
    p,y = map(int, input().split())
    P.append(p)
    Y.append(y)
    pref[p].append(y)

    
for p,y in zip(P,Y):
    ans = "{:0>6}".format(p)
    i = bisect.bisect(sorted(pref[p]), y)
    ans += "{:0>6}".format(i)
    print(ans)

Submission status: Time Limit Exceeded

Solution code:
N, M = map(int, input().split())
dic_p = {i: [] for i in range(1, N + 1)}
order = []
for _ in range(M):
    p, y = map(int, input().split())
    dic_p[p].append(y)
    order.append((p, y))
for k in dic_p:
    dic_p[k] = sorted(dic_p[k])
for p, y in order:
    print('{:0=6}'.format(p) + '{:0=6}'.format(dic_p[p].index(y) + 1))

Submission status: Time Limit Exceeded

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

sorted=[ [] for i in range(N+1) ]
for i in range(M):
    cities.append(list(map(int,input().split())))
    sorted[cities[i][0]].append(cities[i][1])

for s in sorted:
  s.sort()
for p,y in cities:
  for i in range(len(sorted[p])):
    if sorted[p][i]== y:
      id_y = i
      break

  print('{0:06d}{1:06d}'.format(p,id_y+1))

Submission status: Time Limit Exceeded

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

a,b = map(int,input().split())

da = [[] for i in range(a)]
d = []
for i in range(b):
    k,kk = map(int,input().split())
    da[k-1].append(kk)
    d.append([k, kk])

for i in range(a):
    da[i].sort()

for i in range(b):
    p = da[d[i][0]-1].index(d[i][1])

    n = str(d[i][0])
    m = str(p+1)

    n = "0"*(6-len(n)) + n
    m = "0"*(6-len(m)) + m

    print(n+m)

Submission status: Time Limit Exceeded

Solution code:
#coding:utf-8
N, M = map(int, input().split())
P_list = []
Y_list = []
num_list = []
for i in range(M):
    P, Y = map(int, input().split())
    P_list.append(P)
    Y_list.append(Y)

# print(P_list)
# print(Y_list)
for i in range(M):
    p = P_list[i]
    y = Y_list[i]
    list2 = [j for j, x in enumerate(P_list) if x == p] #県が同じ市のリスト
    # list2 = P_list.index(p)
    # print(list2)
    same_pref = []
    for j in range(len(list2)):
        same_pref.append(Y_list[list2[j]])
    # print(same_pref) #県が同じ市の年のリスト
    same_pref_sort = sorted(same_pref) #昇順、古い順に並び替え
    # print(same_pref_sort)
    # print(y)
    num = same_pref_sort.index(y)+1 #何番目か
    # print(num)
    num_list.append(num)
    str1 = '{0:06d}'.format(P_list[i])
    str2 = '{0:06d}'.format(num)
    print(str(str1)+str(str2))

Submission status: Time Limit Exceeded

Solution code:

from operator import itemgetter

n,m=map(int,input().split())
s = [ list(map(int,input().split())) for _ in range(m)]
l = sorted(s,key=itemgetter(0,1))
j=1
for i in range(0,len(l)):
    if i !=0 and l[i][0] != l[i-1][0]:
        j = 1
    l[i].append(('%06d' % l[i][0]) + ('%06d' % j))
    j = j + 1
for i in range(0,len(s)):
    for j in range(0,len(l)):
        if s[i][0] == l[j][0] and s[i][1] == l[j][1]:
            print(l[j][2])
            break

Submission status: Time Limit Exceeded

Solution code:
N,M=map(int,input().split())
list1=[[]for i in range(N)]
list2=[]
for i in range(M):
    A=input()
    A=A.rstrip().split()
    P=int(A[0])
    Y=int(A[1])
    list1[P-1].append(Y)
    list2.append([P,Y])
#print(list1)
for j in range(N):
    list1[j].sort()
#print(list1)
for k in range(M):
    ansP="0"*(6-len(str(list2[k][0])))+str(list2[k][0])
    ansY="0"*(6-len(str(list1[list2[k][0]-1].index(list2[k][1])+1)))+str(list1[list2[k][0]-1].index(list2[k][1])+1)
    ans=ansP+ansY
    print(ans)

Submission status: Time Limit Exceeded

Solution code:
n,m = map(int,input().split())
py = []
for i in range(m):
    py.append(list(map(int,input().split())))
y = []
p = []
for i in range(m):
    y.append(py[i][1])
    p.append(py[i][0])
py.sort()
py2 = []
for i in range(m):
    py2.append(py[i][1])
check = 0
nums = []
an = 0
for i in range(m):
    if check != py[i][0]:
        an = 1
        check = py[i][0]
        nums.append(an)
    else:
        an += 1
        nums.append(an)
for i in y:
    a = py2.index(i)
    b = nums[a]
    c = py[a][0]
    print('{:0=6}'.format(c),end = '')
    print('{:0=6}'.format(b))

Submission status: Time Limit Exceeded

Solution code:
import heapq
N, M = map(int, input().split())
P = [0 for i in range(M)]
Y = [0 for i in range(M)]
country = [[] for i in range(N+1)]
for i in range(M):
    P[i], Y[i] = map(int, input().split())
    heapq.heappush(country[P[i]], Y[i])
cs = [[] for i in range(N+1)]
for i in range(N+1):
    cs[i] = [heapq.heappop(country[i]) for j in range(len(country[i]))]

for i in range(M):
    num = cs[P[i]].index(Y[i]) + 1
    line = str(P[i]).zfill(6) + str(num).zfill(6)
    print(line)

Submission status: Time Limit Exceeded

Solution code:
N,M=map(int, input().split())
lis=[]
for i in range(M):
    lis.append(list(map(int,input().split())))
l_2=sorted(lis, key=lambda x: x[1])
dic={}
for i,j in l_2:
    dic[i]=dic.get(i,0)+1
    lis[lis.index([i,j])]='{:0=6}{:0=6}'.format(i,dic[i])
for i in lis:print(i)

Submission status: Time Limit Exceeded

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

def zeroume(a, b):
    a, b = str(a), str(b)
    txt = ""
    for _ in range(6 - len(a)):
        txt += "0"
    txt += a
    for _ in range(6 - len(b)):
        txt += "0"
    txt += b
    return txt

if __name__ == "__main__":
    dum = list(map(int, input().split()))
    n, m = dum[0], dum[1]

    whole = [0. for _ in range(m)]
    keys = []
    values = []
    for i in range(m):
        dum = list(map(int, input().split()))
        whole[i] = dum

        n_dum, m_dum = dum[0], dum[1]
        if n_dum in keys:
            num = keys.index(n_dum)
            values[num].append(m_dum)

        else:
            keys.append(n_dum)
            values.append([m_dum])

    for i in range(len(values)):
        values[i] = sorted(values[i])

    for i in range(m):
        n_dum, m_dum = whole[i][0], whole[i][1]
        print(zeroume(n_dum, values[keys.index(n_dum)].index(m_dum)+1))

Submission status: Time Limit Exceeded

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

def rank(lst):
	r = []
	for l in lst:
		r.append(sorted(lst).index(l)+1)
	return r

def len6(t):
	s = str(t)
	while len(s) < 6:
		s = '0' + s
	return s

for i in range(len(mat)):
	mat[i] = rank(mat[i])

for p in line:
	print(len6(p) + len6(mat[p-1].pop(0)))

Submission status: Time Limit Exceeded

Solution code:
a = input().split()
b = []
for i in range(int(a[1])):
  c = input().split()
  b.append(c)

for i, j in b:
    posi = 1
    for k, l in b:
        if int(i) == int(k):
            if int(j) > int(l):
                posi+=1
    print(str(i).zfill(6) + str(posi).zfill(6))

Submission status: Time Limit Exceeded

Solution code:
N,M = map(int,input().split())
P = []
Y = []
arr = [[]for j in range(10**5+1)]
for i in range(M):
  listA = list(map(int,input().split()))
  P.append(listA[0])
  Y.append(listA[1])
  arr[listA[0]].append(listA[1])
  arr[listA[0]].sort()
for i in range(M):
  left = 0
  right = len(arr[P[i]])-1
  while left <= right:
    mid = (left+right)//2
    if arr[P[i]][mid] == Y[i]:
      k = mid
      break
    elif arr[P[i]][mid] > Y[i]:
      right = mid-1
    else:
      left = mid+1
  print(str(P[i]).rjust(6,'0')+str(k+1).rjust(6,'0'))

Submission status: Time Limit Exceeded

Solution code:
from operator import itemgetter
N, M = (int(i) for i in input().split(' '))
py=[]
p =[]

# 全都市を配列に代入
for i in range(M):
    p = [i]
    p.extend([int(j) for j in input().split(' ')])
    py.append(p)

# 全N個の県について調べる
Npy = []
for i in range(1,N+1):
    # 県i
    pyi = [j for j in py if j[1] == i] # 県iの市リスト
    pyi.sort(key=itemgetter(2)) # 県iの市を生まれた年でソート
    l = len(pyi)
    cnt = 0
    for k in range(1,l+1):
        pyi[k-1][2] = k
    Npy.extend(pyi)

Npy.sort(key=itemgetter(0))

for t in Npy:
    print('{0:0>6}{1:0>6}'.format(t[1],t[2]))

Submission status: Time Limit Exceeded

Solution code:
n,m = map(int, input().split())
inputs = []
indexs = []
nums = ["0"]*m
for i in range(n):
    inputs.append([])
    indexs.append([])
for i in range(m):
    p,y = map(int, input().split())
    inputs[p-1].append(y)
    indexs[p-1].append(i)
for e,i in enumerate(inputs):
    if len(i) > 0:
        j = sorted(i)
        for k in range(len(i)):
            pn = (6-len(str(e+1)))*"0"+str(e+1)
            yn = (6-len(str(j.index(i[k])+1)))*"0"+str(j.index(i[k])+1)
            nums[indexs[e][k]] = pn+yn
for i in nums:
    print(i)

Submission status: Time Limit Exceeded

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

n,m=map(int,input().split())
l=[list(map(int,input().split())) for _ in range(m)]
#print(l)
li=sorted(l)
#print(li)
for i in l:
    a=li.index(i)+1
    if i[0]>=2:
        for j in l:
            if i[0]>j[0]:
                a-=1
    print(str('%06d'%i[0])+str('%06d'%a))

Submission status: Time Limit Exceeded

Solution code:
N, M = map(int, input().split())
tmp = []
PY = [[] for _ in range(N + 1)]
# PY_sorted = [[] for _ in range(N + 1)]

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

# for i in range(1, N + 1):
#     PY_sorted[i] = sorted(PY[i])

for prefecture, year in tmp:
    text = ""
    text += "%06d" % prefecture
    text += "%06d" % (PY[prefecture].index(year) + 1)
    print(text)

Submission status: Time Limit Exceeded

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


MOD = 10 ** 9 + 7

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

# KenList = [{} for _ in range(N)]
KenList = [[] for _ in range(N)]


PYlist = [None] * M
for i in range(M):
    P, Y = [int(x) for x in input().split()]
    P = P - 1
    PYlist[i] = (P, Y)
    KenList[P].append((i, Y))


for i in range(N):
    KenList[i] = sorted(KenList[i], key=lambda x: x[1])

for i in range(M):
    ken = PYlist[i][0]
    idx = 0
    kl = KenList[ken]
    for j in range(len(kl)):
        if kl[j][0] == i:
            idx = j
            break
    print("{0:06d}{1:06d}".format(ken+1, idx+1))


sys.exit(0)

Submission status: Time Limit Exceeded

Solution code:
#coding:utf-8
import numpy as np
def argsort_p1(ls):
    a = sorted(ls)
    r = [a.index(t)+1 for t in ls]
    return r

N,M = list(map(int,input().split()))
P = []
Y = []
for m in range(M):
    p,y = list(map(int,input().split()))
    P.append(p)
    Y.append(y)
#print (P,Y)
ls = [ [] for _ in range(max(P))]
#print (ls)
for p,y in zip(P,Y):
    ls[p-1].append(y)
ls_dict = []
for line in ls:
    #arg_line = np.argsort(line)+1
    arg_line = argsort_p1(line)
    temp_dict = dict(zip(line, arg_line))
    ls_dict.append(temp_dict)
#print (ls_dict)
for p,y in zip(P,Y):
    print (str(p).zfill(6)+str(ls_dict[p-1][y]).zfill(6))

Submission status: Time Limit Exceeded

Solution code:
n,m=map(int,input().split())
p=[]
for i in range(m):
    p.append(list(map(int,input().split())))
    p[i].append(i)
p.sort(key=lambda x:x[1])
count=0
for i in range(1,n+1):
    count = 0
    j=0
    while j<m:
        if p[j][0]==i:
            count +=1
            ans1 = '{0:06d}'.format(p[j][0])
            ans2 = '{0:06d}'.format(count)
            p[j].append(ans1 + ans2)
        j +=1
p.sort(key=lambda x: x[2])
for i in range(m):
    print(p[i][3])

Submission status: Time Limit Exceeded

Solution code:
from bisect import insort,bisect_left

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

d = {}

for py in PY:
    tmp = d.get(py[0],[])
    insort(tmp,py[1])
    d[py[0]] = tmp

for py in PY:
    s1 = str(py[0])
    s1 = ("0"*(6-len(s1)))+s1
    s2 = str(bisect_left(d[py[0]],py[1])+1)
    s2 = ("0"*(6-len(s2)))+s2

    print(s1+s2)

Submission status: Time Limit Exceeded

Solution code:
n,m = input().split()
plist = []
ylist = []
n = int(n)
m = int(m)
anslist = [0 for i in range(m)]
list = [[] for i in range(n+1)]
for i in range(m):
    p,y = input().split()
    p = int(p)
    y = int(y)
    plist.append(p)
    ylist.append(y)
for i in range(m):
    for j in range(n+1):
        if plist[i] == j + 1:
            list[j].append([ylist[i],i])
for i in range(n):
    list[i].sort()
    for j in range(len(list[i])):
        mtem = list[i][j][1]
        ans1 = str(plist[mtem])
        while len(ans1) < 6:
            ans1 = "0" + ans1
        ans2 = str(j+1)
        while len(ans2) < 6:
            ans2 = "0" + ans2
        anslist[mtem] = ans1 + ans2
for i in range(m):
    print(anslist[i])

Submission status: Time Limit Exceeded

Solution code:
a,b = map(int,input().split())

da = [[] for i in range(a)]
d = []
for i in range(b):
    k,kk = map(int,input().split())
    da[k-1].append(kk)
    d.append([k, kk])

for i in range(a):
    da[i].sort()

for i in range(b):
    p = da[d[i][0]-1].index(d[i][1])

    n = str(d[i][0])
    m = str(p+1)

    n = "0"*(6-len(n)) + n
    m = "0"*(6-len(m)) + m

    print(n+m)

Submission status: Time Limit Exceeded

Solution code:
import numpy as np

N, M = map(int, input().split())
PY = [list(map(int, input().split())) for _ in range(M)]
A = list(PY)
A = sorted(A, key=lambda x: x[1])

for i in PY:
    B = []
    for j in A:
        if j[0] == i[0]:
            B.append(j[1])
            
    print('{:06}'.format(i[0]), end='')
    print('{:06}'.format(B.index(i[1])+1))

Submission status: Time Limit Exceeded

Solution code:
n, m = list(map(int, input().split()))
p, y = [], []
for i in range(m):
    a = list(map(int, input().split()))
    p.append(a[0])
    y.append(a[1])

p_city_yrs = [sorted([y[j] for j in range(m) if p[j] == i + 1])
              for i in range(n)]

for i in range(m):
    order = p_city_yrs[p[i] - 1].index(y[i]) + 1
    output = '%06d%06d' % (p[i], order)
    print(output)

Submission status: Time Limit Exceeded

Solution code:
def main():
    N, M = map(int, input().split())
    P = []
    Y = []
    for _ in range(M):
        pi, yi = [int(i) for i in input().split()]
        P.append(pi)
        Y.append(yi)
    temp_list = []
    temp_dict = {}
    for i in range(N):
        for j in range(M):
            if P[j] == i+1:
                temp_list.append(Y[j])
        temp_list.sort()
        for i in range(len(temp_list)):
            temp_dict[str(temp_list[i])] = i+1
        temp_list = []

    for i in range(M):
        print(str(P[i]).zfill(6) + str(temp_dict[str(Y[i])]).zfill(6))


if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

Solution code:
n,m = map(int, input().split())
inputs = []
indexs = []
nums = ["0"]*m
for i in range(n):
    inputs.append([])
    indexs.append([])
for i in range(m):
    p,y = map(int, input().split())
    inputs[p-1].append(y)
    indexs[p-1].append(i)
for e,i in enumerate(inputs):
    j = sorted(i)
    for k in range(len(i)):
        pn = (6-len(str(e+1)))*"0"+str(e+1)
        yn = (6-len(str(j.index(i[k])+1)))*"0"+str(j.index(i[k])+1)
        nums[indexs[e][k]] = pn+yn
for i in nums:
    print(i)

Submission status: Time Limit Exceeded

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

array = [list(map(int, input().split())) for i in range(M)]
myset = set()

for i in range(M):
    array[i][0] = '%06d' % array[i][0]
    myset.add(array[i][0])

for i in myset:
    array2 = [array[j][1] for j in range(M) if array[j][0] == i]
    array2 = sorted(array2)
    for j in range(M):
        for k in range(len(array2)):
            if array[j][0] == i and array[j][1] == array2[k]:
                array[j][1] = '%06d' % (k + 1)
                break

for i in range(M):
    print(str(array[i][0]) + str(array[i][1]))

Submission status: Time Limit Exceeded

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

PY_list = []
for num,i in enumerate(range(M)):
    p,y = map(int, input().split())
    PY_list = PY_list + [(num,p,y),]
    
rec = []
for i in range(N):
    cities = []
    for k in PY_list:
        if k[1] == i+1:
            cities = cities + [k,]
    cities = sorted(cities, key=lambda x:x[2])

    rec_list = []
    for num,k in enumerate(cities):
        rec_list = rec_list + [(k[0],str(k[1]).zfill(6) + str(num+1).zfill(6)),]

    rec = rec + rec_list
rec = sorted(rec, key=lambda x:x[0])

for s in rec:
    print(s[1])

Submission status: Time Limit Exceeded

Solution code:
n, m = map(int, input().split())
a = [[] for _ in range(n)]
b = []
for i in range(m):
    s, t = map(int, input().split())
    a[s-1].append(t)
    b.append((s, t))
for i in range(n):
    a[i].sort()

for i in range(m):
    s, t = b[i][0], b[i][1]
    u = str(a[s-1].index(t)+1)
    print("0"*(6-len(str(s))) + str(s) + "0"*(6-len(u)) + u)

Submission status: Time Limit Exceeded

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

P = []
Y = []
a = {}
for m in range(M):
    p, y = (int(i) for i in input().split())
    if p in a:
        a[p].append(y)
    else:
        a[p] = [y]
    P.append(p)
    Y.append(y)


sa = {}
for k, v in a.items():
    V = sorted(v)
    sa[k] = V

cnt = 0
for i, a in enumerate(P):
    print('%06d' % a + '%06d' % (sa[a].index(Y[i]) + 1))

Submission status: Time Limit Exceeded

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

def zeroume(a, b):
    a, b = str(a), str(b)
    txt = ""
    for _ in range(6 - len(a)):
        txt += "0"
    txt += a
    for _ in range(6 - len(b)):
        txt += "0"
    txt += b
    return txt

if __name__ == "__main__":
    dum = list(map(int, input().split()))
    n, m = dum[0], dum[1]

    whole = [0. for _ in range(m)]
    for i in range(m):
        dum = list(map(int, input().split()))
        whole[i] = dum

    keys = []
    values = []
    for i in range(m):
        n_dum, m_dum = whole[i][0], whole[i][1]
        if n_dum in keys:
            num = keys.index(n_dum)
            values[num].append(m_dum)

        else:
            keys.append(n_dum)
            values.append([m_dum])

    for i in range(len(values)):
        values[i] = sorted(values[i])

    for i in range(m):
        n_dum, m_dum = whole[i][0], whole[i][1]
        print(zeroume(n_dum, values[keys.index(n_dum)].index(m_dum)+1))

Submission status: Time Limit Exceeded

Solution code:
N,M=map(int,input().split())
cities = []
for i in range(M):
    cities.append(list(map(int,input().split())))
sorted=[ [] for i in range(N+1) ]
for p,y in cities:
  sorted[p].append(y)
for s in sorted:
  s.sort()
for p,y in cities:
  for i in range(len(sorted[p])):
    if sorted[p][i]== y:
      id_y = i

  print('{0:06d}{1:06d}'.format(p,id_y+1))

Submission status: Time Limit Exceeded

Solution code:
N,M = map(int,input().split())
P = []
Y = []
arr = [[]for j in range(10**5+1)]
for i in range(M):
  listA = list(map(int,input().split()))
  P.append(listA[0])
  Y.append(listA[1])
  arr[listA[0]].append(listA[1])
  arr[listA[0]].sort()
for i in range(M):
  for k in range(M):
    if arr[P[i]][k] == Y[i]:
      break
  print(str(P[i]).rjust(6,'0')+str(k+1).rjust(6,'0'))

Submission status: Time Limit Exceeded

Solution code:
n, m = map(int,input().split())
zan = [[] for _ in range(n)]
ans = []
for r in range(m):
    p, y = map(int,input().split())
    zan[p-1].append(y)
    ans.append(y)
for o in range(n):
    zan[o].sort()
for i in range(n):
    for j in range(len(zan[i])):
        k = ans.index(zan[i][j])
        x = '{:0>6}'.format(i+1)
        y = '{:0>6}'.format(j+1)
        ans[k] = x + y
for f in ans:
    print(f)

Submission status: Time Limit Exceeded

Solution code:
N,M=map(int,input().split())
F=[False]*(N+1)
PY=[]

for _ in range(M):
    p,y=map(int,input().split())
    PY.append([p,y])
    if F[p]==False: F[p]=[y]
    else: F[p].append(y)
    
for i in range(1,N+1):
    if F[i]!=False:
        F[i].sort()
        
for i in range(M):
    PY[i][1]=F[PY[i][0]].index(PY[i][1])+1

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