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

pre = [[] for _ in range(n)]
p = []

for i in range(m):
    p.append(list(map(int, input().split())))
    pre[p[i][0] - 1].append(p[i][1])

for i in range(m):
    pref = "{:0>6}".format(p[i][0])

    years = pre[p[i][0] - 1]
    years.sort()

    y = years.index(p[i][1]) + 1
    year = "{:0>6}".format(y)
    print(pref + year)

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

for i in range(m):
    pref = "{:0>6}".format(p[i][0])

    y = 1
    for j in range(m):
        if p[i][0] == p[j][0] and p[i][1] > p[j][1]:
            y += 1

    year = "{:0>6}".format(y)
    print(pref + year)

Submission status: Time Limit Exceeded

Solution code:
# -*- coding: utf-8 -*-
import sys,bisect
# ----------------------------------------------------------------

N,M= map(int, input().split(' '))
NLIST = []
A = [[] for i in range(N)]
for i in range(M):
    P,Y = map(int, input().split(' '))
    bisect.insort(A[P-1], Y)
    NLIST.append((P,Y))
for x in NLIST:
    n = bisect.bisect(A[x[0]-1], x[1])
    print("{:0>6}{:0>6}".format(x[0], n))

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()))+[i+1])
    PY.sort(key=lambda x:(x[0],x[1]))
id=[]
l=[]
while len(PY)>0:
    p=PY[0][0]
    i=0
    while PY[i][0]==p:
        i+=1
        id.append('0'*(6-len(str(p)))+str(p)+'0'*(6-len(str(i)))+str(i))
        l.append(PY[i-1][2])
        if i+1>len(PY):
            break
    del PY[:i]
for i in range(1,M+1):
    print(id[l.index(i)])

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
N,M=map(int,input().split())
PY=[list(map(int,input().split())) for i in range(M)]
a=np.array(PY)
p=a[:,0]# 属する県の情報
q=a[:,1]
x=[i for i in range(M)]#答え
def make_number(p,x):
    return str(p*10**6+x).zfill(12)
for i in range(1,N+1):
    y=[]
    for j in range(M):
         if p[j]==i:
                y.append(a[j][1])#県iに属する市の誕生年
    y2=sorted(y) 
    for l in range(len(y2)):
        for k in range(len(q)):
            if q[k]==y2[l]:
                x[k]=make_number(i,l+1)
for i in range(M):
    print(x[i])

Submission status: Time Limit Exceeded

Solution code:
from collections import deque

N,M=map(int,input().split())
PY=[]
pY=[[] for i in range(N+1)]
for i in range(M):
    P,Y=map(int,input().split())
    PY.append([P,Y])
    pY[P].append(Y)
"""
N=2
M=3
PY=[[1,32],[2,63],[1,12]]
pY=[[],
   [32,12],
   [63]]
"""
py=[[]]
for i in range(1,len(pY)):
    pY[i].sort()
    py.append(pY[i])
for P in PY:
    for i in range(len(py[P[0]])):
        if py[P[0]][i]==P[1]:
            print(str(P[0]).zfill(6)+str(i+1).zfill(6))
            break

Submission status: Time Limit Exceeded

Solution code:
# 入力
N, M = map(int, input().split())
dic = {}
ps, ys = [], []
for _ in range(M):
    p, y = map(int, input().split())
    ps.append(p)
    ys.append(y)
    if p not in dic.keys():
        dic[p] = [y]
    else:
        dic[p].append(y)


# ソート
for k in dic.keys():
    dic[k] = sorted(dic[k])

for i in range(M):
    p, y = ps[i], ys[i]
    ans = "{:06d}".format(p)
    for j in range(len(dic[p])):
        if dic[p][j] == y:
            ans += "{:06d}".format(j+1)
            break
    print(ans)

Submission status: Time Limit Exceeded

Solution code:
import collections as c
d=c.defaultdict(list)
d2=c.defaultdict(list)
a,b,*q=map(int,open(0).read().split())
for s in range(b):
    g,j=q[2*s],q[2*s+1]
    d[g].append(j)
    d[g]=sorted(d[g])
for t in d.keys():
    for k,v in enumerate(d[t]):
        d2[t].append((v,k+1))
#print(d2)
for s in range(b):
    g,j=q[2*s],q[2*s+1]
    for sss in d2[g]:
        if sss[0]==j:
            print('{:06d}'.format(g)+'{:06d}'.format(sss[1]))

Submission status: Time Limit Exceeded

Solution code:
import collections as c
d=c.defaultdict(list)
d2=c.defaultdict(list)
a,b=map(int,input().split())
l=[]
for s in range(b):
    g,j=map(int,input().split())
    d[g].append(j)
    d[g]=sorted(d[g])
    l.append([g,j])
for t in d.keys():
    for k,v in enumerate(d[t]):
        d2[t].append([v,k+1])
for sss in l:
    for ttt in d2[sss[0]]:
        if ttt[0]==sss[1]:
            print('{:06d}'.format(sss[0])+'{:06d}'.format(ttt[1]))

Submission status: Time Limit Exceeded

Solution code:
import collections as c
d=c.defaultdict(list)
d2=c.defaultdict(list)
a,b=map(int,input().split())
l=[]
for s in range(b):
    g,j=map(int,input().split())
    d[g].append(j)
    l.append([g,j])
#print(d)
d3=c.defaultdict(list)
for k,v in d.items():
    d2[k]=sorted(v)
for t in d2.keys():
    for k,v in enumerate(d2[t]):
        d3[t].append([v,k+1])
#print(d3)
#print(l)
for sss in l:
    for ttt in d3[sss[0]]:
        if ttt[0]==sss[1]:
            print('{:06d}'.format(sss[0])+'{:06d}'.format(ttt[1]))
  #          print(sss[0],ttt[1])

Submission status: Time Limit Exceeded

Solution code:
N, M = map(int,input().split())
C=[[0 for _ in range(2)] for _ in range(M)]
for i in range(M):
  C[i][0], C[i][1] = map(int,input().split())
D = sorted(C,key = lambda x:x[1])
D.sort(key = lambda x:x[0])
count = [0 for _ in range(M)]
for i in range(M):
  if i == 0:
    count[i]=1
  else:
    if D[i][0]==D[i-1][0]:
      count[i] += count[i-1]+1
    else:
      count[i]=1
for i in C:
  index = D.index(i)
  print("{:06}{:06}".format(i[0],count[index]))

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
from bisect import bisect_left

N,M = 2,4
s = [[2,55],[2,77],[2,33],[1,44]]
Ps = np.array(s)

N, M = map(int,input().split())
Ps = np.zeros((M,2))
for i in range(M):
    j, Y = map(int,input().split())
    Ps[i] = [j,Y]

dist = []
for i in range(N):
    s = Ps[np.where(Ps[:,0]==i+1)][:,1]
    dist.append(np.sort(s))

for city, year in Ps:
    city = int(city)
    rank = bisect_left(dist[city-1],year)
    print("{:06d}{:06d}".format(city,rank+1))

Submission status: Time Limit Exceeded

Solution code:
N, M=map(int,input().split())
listP=[]
listY=[]
ni=[]
for i in range(N+1):
    ni.append([])
for i in range(M):
    P,Y=map(int,input().split())
    listP.append(P)
    listY.append(Y)
    ni[P].append(Y)
for i in listP:
  ni[i].sort()
for i in range(M):
    A="%06d" % listP[i]
    k=ni[listP[i]].index(listY[i])+1
    B="%06d" % k
    print(A+B)

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
N, M = map(int,input().split())
Ps = np.zeros((M,2))
for i in range(M):
    j, Y = map(int,input().split())
    Ps[i] = [j,Y]

def rank(argsort):
    x = np.zeros(len(argsort))
    for i,s in enumerate(argsort):
        x[s] = i+1
    return list(x)


ranks = []
for i in range(N):
    s = np.argsort(Ps[np.where(Ps[:,0]==i+1)][:,1])
    ranks.append(rank(s))

for index, year in Ps:
    index = int(index)
    print("{:06d}{:06d}".format(index,int(ranks[index-1][0])))
    ranks[index-1].pop(0)

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
N, M = map(int,input().split())
Ps = [[] for _ in range(N)]
for i in range(M):
    j, Y = map(int,input().split())
    Ps[j-1].append([i,Y])
rets = [""]*M
for i_city,P in enumerate(Ps):
    if len(P)==0:
        continue
    
    inds = np.array(P)[:,0]
    years = np.array(P)[:,1]
    sorts = np.argsort(years)
    
    ## 降順/昇順に手こずりすぎ
    for i,(ind,s) in enumerate(zip(inds,sorts)):
        a = np.where(sorts==i)[0][0]
        rets[ind] = "{:06d}{:06d}".format(i_city+1,a+1)


for ret in rets:
    print(ret)

Submission status: Time Limit Exceeded

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


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


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


N, M = LI()
P, Y = [], []
for i in range(M):
    j, k = LI()
    P.append(j)
    Y.append(k)

city_records = [[]for i in range((max(P)+1))]
for p, y in zip(P, Y):
    #  print('p,y', p, y)
    #  print('city_records[p]', city_records[p])
    city_records[p].append([p, y])

#  print(city_records)

for i in range(len(city_records)):
    if city_records[i] == []:
        continue
    city_records[i].sort(key=lambda x: x[1])

#  print(city_records)

for p, y in zip(P, Y):
    order = (city_records[p].index([p, y])) + 1
    print(str(p).zfill(6) + str(order).zfill(6))

Submission status: Time Limit Exceeded

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

P, Y = [], []
cities = {}
appeared_pref = []

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

    try:
        cities[p].append(y)
    except Exception:
        cities[p] = []
        cities[p].append(y)

    if p not in appeared_pref:
        appeared_pref.append(p)

result = [None for i in range(M)]
for p in appeared_pref:
    for i, y in enumerate(sorted(cities[p])):
        id_val = '{:06}{:06}'.format(p, i+1)
        result[Y.index(y)] = id_val

[print(id_val) for id_val in result]

Submission status: Time Limit Exceeded

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

input_order = []
p_list = []
for i in range(M):
    P, Y = map(int, input().split())

    if P not in p_list:
        p_list.append(P)

    try:
        cities[P].append(Y)
    except Exception:
        cities[P] = []
        cities[P].append(Y)

    input_order.append([P, Y])

named = []
for p in p_list:
    p_str = '0'*(6-len(str(p))) + str(p)
    sorted_cities_p = sorted(cities[p])

    named += [[p, city, p_str + '0'*(6-len(str(y))) + str(y+1)] for y, city in enumerate(sorted_cities_p)]

for p, y in input_order:
    [print(id_val) for _p, _y, id_val in named if p == _p and y == _y]

Submission status: Time Limit Exceeded

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

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

named = []
for p in range(1, N+1):
    p_str = '0'*(6-len(str(p))) + str(p)
    named += [[p, city, p_str + '0'*(6-len(str(y))) + str(y+1)] for y, city in enumerate(sorted(cities[p]))]

for p, y in input_order:
    [print(id_val) for _p, _y, id_val in named if p == _p and y == _y]

Submission status: Time Limit Exceeded

Solution code:
from collections import defaultdict
N, M = map(int, input().split())
cities = []
prefs = defaultdict(list)
for i in range(M):
    city = tuple(map(int, input().split()))
    cities.append(city)
    prefs[city[0]].append(city[1])

for pref in prefs.values():
    pref.sort()
for c in cities:
    x = prefs[c[0]].index(c[1]) + 1
    print('{:06}{:06}'.format(c[0], x))

Submission status: Time Limit Exceeded

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

citys.sort(key=lambda x: (x[0],x[1]))
states = []
for s in range(N):
    temp = list(filter(lambda x:x[0]==s+1,citys))
    states += [city+[i+1] for i,city in enumerate(temp)]

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

for city in states:
    print(str(city[0]).zfill(6)+str(city[3]).zfill(6))

Submission status: Time Limit Exceeded

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

citys.sort(key=lambda x: (x[0],x[1]))
states = []
for s in range(N):
    temp = list(filter(lambda x:x[0]==s+1,citys))
    states += [city+[i+1] for i,city in enumerate(temp)]

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

def zero6(n):
    return ('0'*6+str(n))[-6:]

for city in states:
    print(zero6(city[0])+zero6(city[3]))

Submission status: Time Limit Exceeded

Solution code:
def solve(string):
    n, m, *py = map(int, string.split())
    p = [[] for _ in range(n)]
    for _p, _y in zip(py[0::2], py[1::2]):
        p[_p - 1].append(_y)
    p = [sorted(p[i]) for i in range(n)]
    ans = []
    for _p, _y in zip(py[0::2], py[1::2]):
        ans.append("{:06}{:06}".format(_p, p[_p - 1].index(_y) + 1))
    return "\n".join(ans)


if __name__ == '__main__':
    n, m = map(int, input().split())
    print(solve("{} {}\n".format(n, m) + "\n".join([input() for _ in range(m)])))

Submission status: Time Limit Exceeded

Solution code:
import numpy as np


def solve(string):
    n, m, *py = map(int, string.split())
    p = [[] for _ in range(n)]
    for _p, _y in zip(py[0::2], py[1::2]):
        p[_p - 1].append(_y)
    for i in range(n):
        p[i] = np.argsort(np.argsort(p[i]))
    counter = [0 for _ in range(n)]
    ans = []
    for _p, _y in zip(py[0::2], py[1::2]):
        t = "{:06}{:06}".format(_p, p[_p - 1][counter[_p - 1]] + 1)
        ans.append(t)
        counter[_p - 1] += 1
        p[i] = np.argsort(np.argsort(p[i]))
    return "\n".join(ans)


if __name__ == '__main__':
    n, m = map(int, input().split())

    print(solve("{} {}\n".format(n, m) + "\n".join([input() for _ in range(m)])))

Submission status: Time Limit Exceeded

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

kens = []
ps = [0] * M
ys = [0] * M
for _ in range(N):
    kens.append([])
for i in range(M):
    p,y = (int(i) for i in input().split())
    ps[i] = p
    ys[i] = y
    kens[p-1].append(y)

#print(len(kens))
kens_s = [0] * N
for i in range(N):
    kens_s[i] = sorted(kens[i])

for i in range(M):
    #print(ps[i]-1)
    num = kens_s[ps[i]-1].index(ys[i]) + 1
    print('{0:06d}'.format(ps[i]) + '{0:06d}'.format(num))

Submission status: Time Limit Exceeded

Solution code:
N, M = map(int, input().split())
dic = {}
for m in range(M):
  dic[m] = list(map(int, input().split()))
for n in range(N):
  l = sorted([d for d in dic.items() if d[1][0]==n+1], key=lambda x:x[1][1])
  for i in range(len(l)):
    l[i][1].append(i+1)
for d in dic.items():
  print("{:06d}{:06d}".format(d[1][0], d[1][2]))

Submission status: Time Limit Exceeded

Solution code:
n, m = map(int, input().split())
inputs = []
dict = {}
for i in range(m):
  p, y = map(int, input().split())
  inputs.append((p, y))
  same = dict.get(p, [])
  same.append(y)
  dict[p] = same

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

for i in inputs:
  p = i[0]
  x = dict[p].index(i[1]) + 1
  print(str(p).zfill(6) + str(x).zfill(6))

Submission status: Time Limit Exceeded

Solution code:
n, m = map(int, input().split())
city = []
p_list = []
for i in range(m):
    p, y = map(int, input().split())
    city.append([p, y, i])
city.sort(key=lambda x: x[1])
city.sort()
n = 0
for i in range(m):
    p_list.append(city[i][0])
max_p = max(p_list)

for i in range(max_p + 1):
    for j in range(p_list.count(i)):
        city[n].append(str(p_list[n]).zfill(6) + (str(j + 1)).zfill(6))
        n += 1

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

Submission status: Time Limit Exceeded

Solution code:
n, m = map(int, input().split())
city = []
p_list = []
for i in range(m):
    p, y = map(int, input().split())
    p_list.append(p)
    city.append([p, y, i])
p_list.sort()
city.sort(key=lambda x: x[1])
city.sort()

n = 0
max_p = max(p_list)

for i in range(max_p + 1):
    for j in range(p_list.count(i)):
        city[n].append(str(p_list[n]).zfill(6) + (str(j + 1)).zfill(6))
        n += 1

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

Submission status: Time Limit Exceeded

Solution code:
N, M = [int(i) for i in input().split()]
data = list()
sorted_data = dict()
for i in range(M):
    p, y = [int(i) for i in input().split()]
    data.append([p, y])
    if sorted_data.get(p) is None:
        sorted_data[p] = []
    sorted_data[p].append(y)
sorted_data = {i: sorted(j) for i, j in sorted_data.items()}

for i in range(M):
    rank = sorted_data[data[i][0]].index(data[i][1]) + 1
    print(str(data[i][0]).zfill(6) + str(rank).zfill(6))

Submission status: Time Limit Exceeded

Solution code:
N, M = [int(i) for i in input().split()]
data = list()
data_dict = dict()
for i in range(M):
    p, y = [int(i) for i in input().split()]
    data.append([p,y])
for p, y in sorted(data,key=lambda x:x[1]):
    if data_dict.get(p) is None:
        data_dict[p] = []
    data_dict[p].append(y)

def num2str(num, len_str=6):
    return "0" * (len_str - len(str(num))) + str(num)

for p, y in data:
    rank = data_dict[p].index(y) + 1
    print(num2str(p) + num2str(rank))

Submission status: Time Limit Exceeded

Solution code:
N , M = [int(i) for i in input().split()]
data = list()
sorted_data = dict()
for i in range(M):
    p, y = [int(i) for i in input().split()]
    data.append([p,y])
for p, y in sorted(data):
    if sorted_data.get(p) is None:
        sorted_data[p] = []
    sorted_data[p].append(y)

def num2str(num, len_str=6):
    return "0" * (len_str - len(str(num))) + str(num)

for p, y in data:
    rank = sorted_data[p].index(y) + 1
    print(num2str(p) + num2str(rank))

Submission status: Time Limit Exceeded

Solution code:
N , M = [int(i) for i in input().split()]
data = list()
sorted_data = dict()
for i in range(M):
    p, y = [int(i) for i in input().split()]
    data.append([p,y])
    if sorted_data.get(p) is None:
        sorted_data[p] = []
    sorted_data[p].append(y)
sorted_data = {i:sorted(j) for i,j in sorted_data.items()}

def num2str(num, len_str=6):
    return "0" * (len_str - len(str(num))) + str(num)

for i in range(M):
    rank = sorted_data[data[i][0]].index(data[i][1]) + 1
    print(num2str(data[i][0]) + num2str(rank))

Submission status: Time Limit Exceeded

Solution code:
N , M = [int(i) for i in input().split()]
data = list()
for i in range(M):
    data.append([int(i) for i in input().split()])
sorted_data = dict()
for i in data:
    if sorted_data.get(i[0]) is None:
        sorted_data[i[0]] = []
    sorted_data[i[0]].append(i[1])
sorted_data = {i:sorted(j) for i,j in sorted_data.items()}

def num2str(num, len_str=6):
    return "0" * (len_str - len(str(num))) + str(num)

for i in range(M):
    rank = sorted_data[data[i][0]].index(data[i][1]) + 1
    print(num2str(data[i][0]) + num2str(rank))

Submission status: Time Limit Exceeded

Solution code:
N , M = [int(i) for i in input().split()]
data = list()
for i in range(M):
    data.append([int(i) for i in input().split()])
sorted_data = sorted(data, key=lambda x:x[1])

def num2str(num, len_str=6):
    return "0" * (len_str - len(str(num))) + str(num)

for i in range(M):
    rank = [j[1] for j in sorted_data if j[0] == data[i][0]].index(data[i][1])
    print(num2str(data[i][0]) + num2str(rank+1))

Submission status: Time Limit Exceeded

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

ans = []
for i in range(1,N+1):
    p = [j for j in data if j[0][0]==i]
    if len(p)==0:
        continue
    p.sort(key = lambda x:x[0][1])
    for k in range(len(p)):
         ans.append([p[k][1],str(i).zfill(6) + str(k+1).zfill(6)])

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

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

Submission status: Time Limit Exceeded

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

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

dict = {}

for c in c_l:
    if c[0] in dict:
        dict[c[0]].append(c[1])
    else:
        dict[c[0]] = [c[1]]


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

# print(dict)

for c in c_l:
    idx = dict[c[0]].index(c[1]) + 1
    print("{:06}{:06}".format(c[0], idx))

Submission status: Time Limit Exceeded

Solution code:
import numpy as np

N,M = map(int, input().split())
X = [list(map(int, input().split()))+[1] for _ in range(M)]
X = np.array(X, dtype=int)
for i in range(1,N+1):
    a = X[:,0]==i
    X[a, 2] = np.argsort(np.argsort(X[a, 1]))+1
for x in X:
    print('{:06}{:06}'.format(x[0], x[2]))

Submission status: Time Limit Exceeded

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

for i in range(m):
    p = list(map(int,input().split()))
    row_data.append(p)
    pref_city[p[0]-1].append(p[1])
    
for i,city in enumerate(row_data):
    pref_city[city[0]-1] = sorted(pref_city[city[0]-1])
    pref_id = "0" * 6 + str(city[0])
    city_id = "0" * 6 + str(pref_city[city[0]-1].index(city[1] ) + 1)
    print(pref_id[-6:] + city_id[-6:])

Submission status: Time Limit Exceeded

Solution code:
N, M = map(int, input().split())
shi = [[0] for i in range(N)]
# for i in range(N):
    # shi.append([0])
# print(shi)

data = []
for i in range(M):
    data.append(list(map(int, input().split())))
    shi[data[i][0]-1].append(data[i][1])

# for each in data:
#     shi[each[0]-1].append(each[1])

for i in range(N):
    shi[i].sort()
    # shi[i] = sorted(shi[i])

# print(shi)
for each in data:
    print(str(each[0]).zfill(6)+str(shi[each[0]-1].index(each[1])).zfill(6))

Submission status: Time Limit Exceeded

Solution code:
from collections import defaultdict
import numpy as np

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

PYlist = []
PYmap = defaultdict(list)

for _ in range(M):
    P, Y = map(int, input().split())
    PYlist.append((P, Y))
    PYmap[P].append(Y)
for P in PYmap.keys():
    PYmap[P] = list(np.argsort(np.argsort(PYmap[P])) + 1)

for P, Y in PYlist:
    print(format(P, '06') + format(PYmap[P].pop(0), '06'))

Submission status: Time Limit Exceeded

Solution code:
n = raw_input()
n,m = int(n.split(" ")[0]),int(n.split(" ")[1])

def leftzeros(n):
	size = len(str(n))
	return "0"*(6-size)+str(n)

cities = []
for i in range(m):
	v = raw_input()
	a = v.split(" ")
	cities.append((int(a[0]), int(a[1])))

prefectures = dict()
for city in cities:
	pref, year = city
	if pref not in prefectures:
		prefectures[pref] = []
	prefectures[pref].append(year)

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

for city in cities:
	pref, year = city
	year = [i+1 for i in range(len(prefectures[pref])) if prefectures[pref][i]==year][0]
	ident = leftzeros(pref)+leftzeros(year)
	print(ident)

Submission status: Time Limit Exceeded

Solution code:
N, M = map(int, input().split())
shi = []
for i in range(N):
    shi.append([0])
# print(shi)

data = []
for i in range(M):
    data.append(list(map(int, input().split())))
    shi[data[i][0]-1].append(data[i][1])

# for each in data:
#     shi[each[0]-1].append(each[1])

for i in range(N):
    shi[i].sort()
    # shi[i] = sorted(shi[i])

# print(shi)
for each in data:
    print(str(each[0]).zfill(6)+str(shi[each[0]-1].index(each[1])).zfill(6))

Submission status: Time Limit Exceeded

Solution code:
from collections import defaultdict

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

PYlist = []
PYmap = defaultdict(list)

for _ in range(M):
    P, Y = map(int, input().split())
    PYlist.append((P, Y))
    PYmap[P].append(Y)
for Ylist in PYmap.values():
    Ylist.sort()

for P, Y in PYlist:
    print(format(P, '06') + format(PYmap[P].index(Y)+1, '06'))

Submission status: Time Limit Exceeded

Solution code:
N, M = map(int, input().split())
shi = []
for i in range(N):
    shi.append([0])
# print(shi)

data = []
for i in range(M):
    data.append(list(map(int, input().split())))

for each in data:
    shi[each[0]-1].append(each[1])

for i in range(N):
    shi[i].sort()
    # shi[i] = sorted(shi[i])

# print(shi)
for each in data:
    print(str(each[0]).zfill(6)+str(shi[each[0]-1].index(each[1])).zfill(6))

Submission status: Time Limit Exceeded

Solution code:
N, M = map(int, input().split())
shi = []
for i in range(N):
    shi.append([0])
# print(shi)

data = []
for i in range(M):
    data.append(list(map(int, input().split())))

for each in data:
    shi[each[0]-1].append(each[1])

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

# print(shi)
for each in data:
    print(str(each[0]).zfill(6)+str(shi[each[0]-1].index(each[1])).zfill(6))

Submission status: Time Limit Exceeded

Solution code:
from collections import OrderedDict
N, M = map(int, input().split())
L = [list(map(int, input().split())) for _ in range(M)]
IDs = OrderedDict()
result = [None] * M
for i, (p, y) in enumerate(L):
    if p not in IDs:
        IDs[p] = OrderedDict()
    IDs[p][y] = i
P = sorted(IDs.keys())
for p in P:
    Y = sorted(IDs[p].keys())
    for i, y in enumerate(Y):
        result[IDs[p][y]] = "{:06}{:06}".format(p, i + 1)
for r in result:
    print(r)

Submission status: Time Limit Exceeded

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

cities = {}
prefs = []

for i in range(1, M + 1):
  p, y = list(map(int, input().split()))
  
  pref = {"city": p, "year": y}
  prefs.append(pref)

  if p not in cities:
    cities[p] = [pref]
  else:
    city = cities[p]
    for idx_city, pref_in_city in enumerate(city):
      if y < pref_in_city['year']:
        city.insert(idx_city, pref)
        break
      elif idx_city == len(city) - 1:
        city.append(pref)
        break

[print("%s%s" % (
  str(int(pref['city'])).zfill(6), 
  str(cities[pref['city']].index(pref) + 1).zfill(6))) for pref in prefs]

Submission status: Time Limit Exceeded

Solution code:
N, M = map(int, input().split())
L = []
P = []
#Y = []
var = []
for i in range(M):
    p, y = map(int, input().split())
    if p not in P:
        var.append(p)
    P.append(p)
    #Y.append(y)
    L.append([i, p, y])

#L = list(zip(range(M), P, Y))     

Order = [None]*M

for v in var:
    #l = filter(lambda x:x[1] == v, L)
    l_ = sorted(filter(lambda x:x[1] == v, L), key = lambda x:x[2])
    
    for n in l_:
        Order[n[0]] = (n[1], l_.index(n)+1)
        
for n in Order:
    print('{0:0>6d}{1:0>6d}'.format(n[0], n[1]))

Submission status: Time Limit Exceeded

Solution code:
N, M = map(int, input().split())
L = []
P = []
#Y = []
var = []
for i in range(M):
    p, y = map(int, input().split())
    if p not in P:
        var.append(p)
    P.append(p)
    #Y.append(y)
    L.append([i, p, y])

#L = list(zip(range(M), P, Y))     

Order = [None]*M

for v in var:
    l = filter(lambda x:x[1] == v, L)
    l_ = sorted(l, key = lambda x:x[2])
    
    for n in l_:
        Order[n[0]] = (n[1], l_.index(n)+1)
        
for n in Order:
    print('{0:0>6d}{1:0>6d}'.format(n[0], n[1]))

Submission status: Time Limit Exceeded

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

#L = list(zip(range(M), P, Y))     

Order = [None]*M
P = [p for (i, p, y) in L]

for v in set(P):
    l = filter(lambda x:x[1] == v, L)
    l_ = sorted(l, key = lambda x:x[2])
    
    for n in l_:
        Order[n[0]] = l_.index(n)+1
        
for (p, od) in zip(P, Order):
    print('{0:0>6d}{1:0>6d}'.format(p, od))

Submission status: Time Limit Exceeded

Solution code:
N, M = map(int, input().split())
P = []
Y = []
#var = []
for i in range(M):
    p, y = map(int, input().split())
    #if p not in P:
    #    var.append(p)
    P.append(p)
    Y.append(y)

L = list(zip(range(M), P, Y))     

Order = [None]*M

for v in set(P):
    l = filter(lambda x:x[1] == v, L)
    l_ = sorted(l, key = lambda x:x[2])
    
    for n in l_:
        Order[n[0]] = l_.index(n)+1
        
for (p, od) in zip(P, Order):
    print('{0:0>6d}{1:0>6d}'.format(p, od))

Submission status: Time Limit Exceeded

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

Order = [None]*M

for v in set(P):
    l = filter(lambda x:x[1] == v, zip(range(M), P, Y))
    l_ = sorted(l, key = lambda x:x[2])
    
    for n in l_:
        Order[n[0]] = l_.index(n)+1
        
for (p, od) in zip(P, Order):
    print('{0:0>6d}{1:0>6d}'.format(p, od))

Submission status: Time Limit Exceeded

Solution code:
a,b=map(int,input().split())
L=[]
l=[]
ll=[]
u=0
for i in range(b):
    u+=1
    c=list(map(int,input().split()))
    c.append(u)
    L.append(c)
L.sort(key=lambda x:x[0])
for i in range(1,a+1):
    lll=[]
    for j in L:
        if j[0]==i:
            lll.append(j)
    ll.append(lll)
for i in ll:
    i.sort(key=lambda x:x[1])
for i in ll:
    e=0
    for j in i:
        e+=1
        j.append(e)
q=[]
for w in ll:
   q.extend(w) 
q.sort(key=lambda x:x[2])
for r in range(b):
        print('0'*(6-len(str(q[r][0])))+str(q[r][0])+'0'*(6-len(str(q[r][3])))+str(q[r][3]))

Submission status: Time Limit Exceeded

Solution code:
a,b=map(int,input().split())
L=[]
l=[]
for i in range(b):
    L.append(list(map(int,input().split())))
for i in range(b):
    x=0
    for j in range(b):
        if not j==i and L[i][0]==L[j][0] and L[i][1]>L[j][1]:
            x+=1
    l.append('0'*(6-len(str(L[i][0])))+str(L[i][0])+'0'*(6-len(str(x+1)))+str(x+1))
for r in range(b):
        print(l[r])

Submission status: Time Limit Exceeded

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

for k, v in city.items():
    v.sort()
    i = 1
    for e in v:
        order[order.index(e)] = str(k).zfill(6) + str(i).zfill(6)
        i += 1

print(*order, sep='\n')

Submission status: Time Limit Exceeded

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

for k, v in city.items():
    v.sort()
    i = 1
    for e in v:
        order[order.index(e)] = str(k).zfill(6) + str(i).zfill(6)
        i += 1

for r in order:
    print(r)