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:
number_of_prefecture, number_of_cities = [int(x) for x in input().split(' ')]

city_list = []

import collections
city_dict = collections.defaultdict(list)

for i in range (number_of_cities):
    prefecture_id, year_of_establishment = [int(x) for x in input().split(' ')]
    city_dict[prefecture_id].append(year_of_establishment)
    city_list.append([prefecture_id, year_of_establishment])

for prefecture in city_dict:
    city_dict[prefecture].sort()

# print(city_dict)
# print(city_list)

for j in city_list:
    prefecture = j[0]
    year = j[1]
    city_number = city_dict[prefecture].index(year) + 1
    front_string = '0'*(6 - len(str(prefecture))) + str(prefecture)
    back_string = '0'*(6 - len(str(city_number))) + str(city_number)
    print(front_string+back_string)

Submission status: Time Limit Exceeded

Solution code:
import bisect
from collections import defaultdict, deque

n, m = map(int, input().split())
d = defaultdict(list)

queue = deque()
for i in range(m):
    p, y = map(int, input().split())
    index = bisect.bisect_left(d[p], y)
    d[p].insert(index, y)
    queue.append((p, y))

while queue:
    p, y = queue.popleft()
    index = bisect.bisect_left(d[p], y)
    print('{:06d}{:06d}'.format(p, index + 1))

Submission status: Time Limit Exceeded

Solution code:
import bisect
from collections import defaultdict, deque

n, m = map(int, input().split())
d = defaultdict(list)

queue = deque()
for i in range(m):
    p, y = map(int, input().split())
    queue.append((p, y))
    index = bisect.bisect_left(d[p], y)
    d[p].insert(index, y)

while queue:
    p, y = queue.popleft()
    index = d[p].index(y)
    print('{:06d}{:06d}'.format(p, index + 1))

Submission status: Time Limit Exceeded

Solution code:
import bisect
from collections import defaultdict, deque

n, m = map(int, input().split())
d = defaultdict(list)

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

while queue:
    p, y = queue.popleft()
    index = sorted(d[p]).index(y)
    print('{:06d}{:06d}'.format(p, index + 1))

Submission status: Time Limit Exceeded

Solution code:
n, m = (int(x) for x in input().split())
l = []
d = {}
ds = []
for _ in range(m):
    l.append([int(x) for x in input().split()])
for li in l:
    k = str(li[0])
    if k not in ds:
        d[k] = [li[1]]
        ds.append(k)
    else:
        d[k].append(li[1])
for key in ds:
    d[key].sort()
for li in l:
    print(str(li[0]).zfill(6) + str(d[str(li[0])].index(li[1]) + 1).zfill(6))

Submission status: Time Limit Exceeded

Solution code:
n, m = (int(x) for x in input().split())
l = []
d = {}
ds = []
for _ in range(m):
    l.append([int(x) for x in input().split()])
for i in range(m):
    k = str(l[i][0])
    if k not in ds:
        d[k] = [l[i][1]]
        ds.append(k)
    else:
        d[k].append(l[i][1])
for key in ds:
    d[key].sort()
for li in l:
    print(str(li[0]).zfill(6) + str(d[str(li[0])].index(li[1]) + 1).zfill(6))

Submission status: Time Limit Exceeded

Solution code:
n, m = (int(x) for x in input().split())
l = []
d = {}
for _ in range(m):
    l.append([int(x) for x in input().split()])
for i in range(m):
    k = str(l[i][0])
    if k not in d.keys():
        d[k] = [l[i][1]]
    else:
        d[k].append(l[i][1])
for key in d.keys():
    d[key].sort()
for li in l:
    print(str(li[0]).zfill(6) + str(d[str(li[0])].index(li[1]) + 1).zfill(6))

Submission status: Time Limit Exceeded

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

N, M = [int(i) for i in input().split(" ")]
p = list()
y = list()
yd = {}
for i in range(0, M):
    pi, yi = [int(i) for i in input().split(" ")]
    p.append(pi)
    y.append(yi)
    if pi in yd.keys():
        yd[pi].append(yi)
    else:
        yd[pi] = [yi]

ydid = {}
for i in yd.keys():
    num = 1
    for j in sorted(yd[i]):
        ydid[j] = num
        num = num + 1

for i in range(0, M):
    print("{:06}{:06}".format(p[i], ydid[y[i]]))

Submission status: Time Limit Exceeded

Solution code:
N, M = [int(i) for i in input().split(" ")]
p = list()
y = list()
yd = {}
for i in range(0, M):
    pi, yi = [int(i) for i in input().split(" ")]
    p.append(pi)
    y.append(yi)
    if pi in yd.keys():
        yd[pi].append(yi)
    else:
        yd[pi] = [yi]

ydid = {}
for i in yd.keys():
    num = 1
    for j in sorted(yd[i]):
        ydid[j] = num
        num = num + 1

for i in range(0, M):
    print("{:06}{:06}".format(p[i], ydid[y[i]]))

Submission status: Time Limit Exceeded

Solution code:
N, M = [int(i) for i in input().split(" ")]
p = list()
y = list()
yd = {}
for i in range(0, M):
    pi, yi = [int(i) for i in input().split(" ")]
    p.append(pi)
    y.append(yi)
    if pi in yd.keys():
        yd[pi].append(yi)
    else:
        yd[pi] = [yi]

ydid = {}
for i in range(0, M):
    num = 1
    for j in sorted(yd[p[i]]):
        ydid[j] = num
        num = num + 1

for i in range(0, M):
    print("{:06}{:06}".format(p[i], ydid[y[i]]))

Submission status: Time Limit Exceeded

Solution code:
n, m = [int(i) for i in input().split()]
pairs = []
ranks = {}
for i in range(m):
    p, y = [int(j) for j in input().split()]
    pairs.append((p, y))
    if (p in ranks):
        ranks[p].append(y)
    else:
        ranks[p] = [y]
for key in ranks.keys():
    ranks[key].sort()
for pair in pairs:
    rank = ranks[pair[0]].index(pair[1]) + 1
    print ("%s%s" % (str(pair[0]).zfill(6), str(rank).zfill(6)))

Submission status: Time Limit Exceeded

Solution code:
n, m = [int(i) for i in input().split()]
pairs = []
ranks = {}
for i in range(m):
    p, y = [int(j) for j in input().split()]
    pairs.append((p, y))
    if (p in ranks):
        ranks[p] = sorted(ranks[p] + [y])
    else:
        ranks[p] = [y]
for pair in pairs:
    rank = ranks[pair[0]].index(pair[1]) + 1
    print ("%s%s" % (str(pair[0]).zfill(6), str(rank).zfill(6)))

Submission status: Time Limit Exceeded

Solution code:
n, m = [int(i) for i in input().split()]
pairs = []
ranks = {}
for i in range(m):
    p, y = [int(j) for j in input().split()]
    pairs.append((p, y))
    if (p in ranks):
        ranks[p].append(y)
    else:
        ranks[p] = [y]
for pair in pairs:
    rank = sorted(ranks[pair[0]]).index(pair[1]) + 1
    print ("%s%s" % (str(pair[0]).zfill(6), str(rank).zfill(6)))

Submission status: Time Limit Exceeded

Solution code:
n, m = [int(i) for i in input().split()]
eles = []
for i in range(m):
    p, y = [int(j) for j in input().split()]
    rank = 1
    for j, ele in enumerate(eles):
        if (ele[0] == p):
            if (ele[1] > y):
                eles[j] = (ele[0], ele[1], ele[2] + 1)
            else:
                rank += 1
    eles.append((p, y, rank))
for ele in eles:
    print ("%s%s" % (str(ele[0]).zfill(6), str(ele[2]).zfill(6)))

Submission status: Time Limit Exceeded

Solution code:
N,M=map(int,input().split())
D={}
L=[]

for i in range(M):
    P,Y=map(int,input().split())
    L.append([P,Y])
    if P not in D:
        D[P]=[]
    D[P].append(Y)
    
for v in D.values() :
    v.sort()

for i in L:
    ans=str(i[0]*1000000 + D[i[0]].index(i[1])+1)
    print("0"*(12-len(ans))+ ans)

Submission status: Time Limit Exceeded

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

for i in range(m):
  p,q=map(int,input().split())
  l[p-1].append(q)
  d.append([p,q])
 
for i in range(n):
  if len(l[i])>0:
    l[i].sort()

for i in range(m):
  print(str(d[i][0]).zfill(6)+str(l[d[i][0]-1].index(d[i][1])+1).zfill(6))

Submission status: Time Limit Exceeded

Solution code:

n,m=map(int,input().split())
d=[[] for i in range(n)]
l=[]
g=[]
for i in range(m):
    a,b=map(int,input().split())
    d[a-1].append(b)
    l.append(a)
    g.append(b)
x=[{} for i in range(n)]
for i in range(n):
    for j in range(len(d[i])):
        ds=sorted(d[i])
        x[i][ds[j]]=j
for i in range(m):
    b=x[l[i]-1][g[i]]
    b+=1
    p=len(list(str(l[i])))
    q=len(list(str(b)))
    ans=''
    for j in range(6-p):
        ans+='0'
    ans+=str(l[i])
    for j in range(6-q):
        ans+='0'
    ans+=str(b)
    print(ans)

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
n,m=map(int,input().split())
d=[[] for i in range(n)]
l=[]
g=[]
for i in range(m):
    a,b=map(int,input().split())
    d[a-1].append(b)
    l.append(a)
    g.append(b)
x=[{} for i in range(n)]
for i in range(n):
    for j in range(len(d[i])):
        ds=sorted(d[i])
        x[i][ds[j]]=j
for i in range(m):
    b=x[l[i]-1][g[i]]
    b+=1
    p=len(list(str(l[i])))
    q=len(list(str(b)))
    ans=''
    for j in range(6-p):
        ans+='0'
    ans+=str(l[i])
    for j in range(6-q):
        ans+='0'
    ans+=str(b)
    print(ans)

Submission status: Time Limit Exceeded

Solution code:
N,M=map(int,input().split())
PY=[list(map(int,input().split())) for i in range(M)]
ans_1=0
ans_2=0
ans=0
num_1=0
num_2=0
for i in range(M):
  ans_1=10**12+PY[i][0]*10**6
  num_1=PY[i][0]
  num_2=PY[i][1]
  for i in range(M):
    if num_1==PY[i][0] and num_2>=PY[i][1]:
      ans_2+=1
  ans=ans_1+ans_2
  ans=str(ans)
  print(ans.lstrip('1'))
  ans_2=0

Submission status: Time Limit Exceeded

Solution code:
N, M = map(int, input().split())
l = [list(map(int, input().split())) for i in range(M)]
l_ = [[] for i in range(N)]
for i in range(M):
    l_[l[i][0] - 1].append(l[i][1])
l_ = [sorted(l_[i]) for i in range(N)]
a = [str(l[i][0]).zfill(6) + str(l_[l[i][0]-1].index(l[i][1]) + 1).zfill(6) for i in range(M)]

for i in range(M):
    print(a[i], end = "\n")

Submission status: Time Limit Exceeded

Solution code:
N, M = map(int, input().split())
l = [list(map(int, input().split())) for i in range(M)]
l_ = [[] for i in range(N)]
for i in range(M):
    l_[l[i][0] - 1].append(l[i][1])
l_ = [sorted(l_[i]) for i in range(N)]
print("\n".join([str(l[i][0]).zfill(6) + str(l_[l[i][0]-1].index(l[i][1]) + 1).zfill(6) for i in range(M)]))

Submission status: Time Limit Exceeded

Solution code:
N, M = map(int, input().split())
l=[]
l_=[]
for i in range(N):
    l_.append([])
for i in range(M):
    l.append(list(map(int, input().split())))
    l_[l[i][0] - 1].append(l[i][1])
for i in range(N):
    l_[i] = sorted(l_[i])
for i in range(M):
    numN = str(l[i][0]).zfill(6)
    numM = str(l_[l[i][0]-1].index(l[i][1]) + 1).zfill(6)
    print(numN + numM)

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
n,m=map(int,input().split())
d=[[] for i in range(n)]
l=[]
for i in range(m):
    a,b=map(int,input().split())
    d[a-1].append(b)
    l.append(a)
x=[[] for i in range(n)]
for i in range(n):
    d[i]=list(np.argsort(d[i]))
    tmp=[0]*len(d[i])
    for j in range(len(d[i])):
        tmp[d[i][j]]=j
    x[i]=tmp
for i in range(m):
    b=x[l[i]-1].pop(0)
    b+=1
    p=len(list(str(l[i])))
    q=len(list(str(b)))
    ans=''
    for j in range(6-p):
        ans+='0'
    ans+=str(l[i])
    for j in range(6-q):
        ans+='0'
    ans+=str(b)
    print(ans)

Submission status: Time Limit Exceeded

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

city_list = []
for _ in range(M):
    P, Y = map(int, input().split()) 
    prefecture_dict[P].append(Y)
    city_list.append([P, Y])

for i in range(1, N+1):
    prefecture_dict[i].sort()

for j in range(M):
    prefecture = city_list[j][0]
    num = prefecture_dict[prefecture].index(city_list[j][1]) + 1
    prefecture = str(prefecture)
    num = str(num)
    print(prefecture.zfill(6) + num.zfill(6))

Submission status: Time Limit Exceeded

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

N_list_sorted = [n.sort() for n in N_list]

for e in entry:
  p, y = e[0], e[1]
  idx = str(N_list[p].index(y)+1).zfill(6)
  print(str(p+1).zfill(6)+idx)

Submission status: Time Limit Exceeded

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

PY_list=[[] for _ in range(n)]

for p,y in PY:
    PY_list[p-1].append(y)
for i in range(n):
    PY_list[i].sort()

for p,y in PY:
    p_str=str(p)
    index_str=str(PY_list[p-1].index(y)+1)
    print(p_str.zfill(6)+index_str.zfill(6))

Submission status: Time Limit Exceeded

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

PY_list=[[] for _ in range(n)]

for p,y in PY:
    PY_list[p-1].append(y)
for i in range(n):
    PY_list[i].sort()

for p,y in PY:
    p_str=str(p)
    index_str=str(PY_list[p-1].index(y)+1)
    print("{}{}".format("0"*(6-len(p_str))+p_str, \
                        "0"*(6-len(index_str))+index_str))

Submission status: Time Limit Exceeded

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


def main():
    n, m = map(int, input().split())
    lst = [[] for _ in range(n + 1)]
    py = [tuple(map(int, input().split())) for i in range(m)]
    for p, y in py:
        lst[p].append(y)
    for i in lst:
        i.sort()

    ans = []
    for i, j in py:
        ans.append(str(i).zfill(6) + str(lst[i].index(j)+1).zfill(6))
    print(*ans, sep=('\n'))


if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

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

def main():
    n, m = map(int, input().split())
    lst = [[] for _ in range(n + 1)]
    py = []
    for i in range(m):
        p, y = map(int, input().split())
        py.append([p, y])
        lst[p].append(y)

    for i in range(n+1):
        lst[i] = sorted(lst[i])
    ans = []
    for i, j in py:
        ans.append(str(i).zfill(6) + str(lst[i].index(j)+1).zfill(6))
    print(*ans, sep=('\n'))

if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
from bisect import bisect_left
from collections import deque
N,M = map(int,input().split())
PY = []
S =[[] for _ in range(N)]

for i in range(M):
    PY.append(list(map(int,input().split())))
    S[PY[i][0]-1].insert(bisect_left(S[PY[i][0]-1],PY[i][1]),PY[i][1])

for i in range(M):
    x = bisect_left(S[PY[i][0]-1],PY[i][1])+1
    print(str(PY[i][0]).zfill(6)+str(x).zfill(6))

Submission status: Time Limit Exceeded

Solution code:
n, m = map(int, input().split())
lst = [[] for _ in range(n + 1)]
py = []
for i in range(m):
    p, y = map(int, input().split())
    py.append([p, y])
    lst[p].append(y)

for i in range(n+1):
    lst[i] = sorted(lst[i])
ans = []
for i, j in py:
    ans.append(str(i).zfill(6) + str(lst[i].index(j)+1).zfill(6))
print(*ans, sep=('\n'))

Submission status: Time Limit Exceeded

Solution code:
n, m = map(int, input().split())
lst = [[] for _ in range(n + 1)]
py = []
for i in range(m):
    p, y = map(int, input().split())
    py.append([p, y])
    lst[p].append(y)

for i in range(n+1):
    lst[i] = sorted(lst[i])

for i, j in py:
    print(str(i).zfill(6) + str(lst[i].index(j)+1).zfill(6))

Submission status: Time Limit Exceeded

Solution code:
import collections as coll
n,m=map(int,input().split())
py=[list(map(int,input().split())) for _ in range(m)]
a=coll.defaultdict(list)
for x,y in sorted(py): a[x].append(y)
for x,y in py:
    z=a[x].index(y)+1
    print('%06d%06d'%(x,z))

Submission status: Time Limit Exceeded

Solution code:
n, m = map(int, input().split())
a = [list(map(int,input().split())) for i in range(m)]
p = [[] for i in range(n)]
for i,j in sorted(a, key=lambda x:x[1]): p[i-1].append(j)
for i,j in a:
	high6 = str(i).zfill(6)
	low6 = str(p[i-1].index(j)+1).zfill(6)
	print(high6+low6)

Submission status: Time Limit Exceeded

Solution code:
n, m = map(int, input().split())
a = [list(map(int,input().split())) for i in range(m)]
p = [[]for i in range(n)]
for i,arr in enumerate(a): p[arr[0]-1].append(arr[1])
for i in range(n): p[i].sort()
for i,j in a:
	high6 = str(i).zfill(6)
	low6 = str(p[i-1].index(j)+1).zfill(6)
	print(high6+low6)

Submission status: Time Limit Exceeded

Solution code:
from bisect import insort_left, bisect_left
n, m = map(int, input().split())
d = [[] for _ in range(n + 1)]
m = [tuple(map(int, input().split())) for _ in range(m)]

for p, y in m:
    insort_left(d[p], y)

for p, y in m:
    print('{:06}{:06}'.format(p, bisect_left(d[p], y)+1))

Submission status: Time Limit Exceeded

Solution code:
from bisect import insort_left
n, m = map(int, input().split())
d = [[] for _ in range(n + 1)]
m = [tuple(map(int, input().split())) for _ in range(m)]

for p, y in m:
    insort_left(d[p], y)

for i, row in enumerate(d):
    d[i] = {x: i+1 for i, x in enumerate(row)}

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

Submission status: Time Limit Exceeded

Solution code:
from bisect import insort_left
n, m = map(int, input().split())
d = [[] for _ in range(n + 1)]
m = [tuple(map(int, input().split())) for _ in range(m)]

for p, y in m:
    insort_left(d[p], y)
for p, y in m:
    print('{:06}{:06}'.format(p, d[p].index(y)+1))

Submission status: Time Limit Exceeded

Solution code:
n, m = map(int, input().split())
d = [[] for _ in range(n + 1)]
m = [tuple(map(int, input().split())) for _ in range(m)]
for p, y in m:
    d[p].append(y)
d = [sorted(s) for s in d]
for p, y in m:
    print('{:06}{:06}'.format(p, d[p].index(y)+1))

Submission status: Time Limit Exceeded

Solution code:
# -*- coding: utf-8 -*-
n,m = map(int, input().split())
i=0
lst = []
x = set()
while i < m: 
    l = list(map(int, input().split()))
    l.append(i)
    x.add(l[0])
    lst.append(l)
    i+=1
ll=sorted(lst)
j=1
for i in sorted(list(x)):
    for k in ll:
        if i > k[0]:
            continue
        if i == k[0]:
            k[1]=i*1000000+j
            j+=1
        else:
            j=1
            break


#ans
for ans in sorted(ll, key=lambda x:x[2]):
    print('{0:012d}'.format(ans[1]))

Submission status: Time Limit Exceeded

Solution code:
# -*- coding: utf-8 -*-
n,m = map(int, input().split())
i=0
lst = []
x = set()
while i < m: 
    l = list(map(int, input().split()))
    l.append(i)
    x.add(l[0])
    lst.append(l)
    i+=1
ll=sorted(lst)
j=1
for i in sorted(list(x)):
    for k in ll:
        if i == k[0]:
            k[1]=i*1000000+j
            j+=1
        else:
            j=1
#ans
for ans in sorted(ll, key=lambda x:x[2]):
    print('{0:012d}'.format(ans[1]))

Submission status: Time Limit Exceeded

Solution code:
# -*- coding: utf-8 -*-
n,m = map(int, input().split())
i=0
lst = []
x = set()
while i < m: 
    l = list(map(int, input().split()))
    l.append(i)
    x.add(l[0])
    lst.append(l)
    i+=1
xxx= sorted(list(x))
ll=sorted(lst)
j=1
for i in xxx:
    for k in ll:
        if i == k[0]:
            k[1]=i*1000000+j
            j+=1
        else:
            j=1
#ans
for ans in sorted(ll, key=lambda x:x[2]):
    print('{0:012d}'.format(ans[1]))

Submission status: Time Limit Exceeded

Solution code:
# -*- coding: utf-8 -*-
n,m = map(int, input().split())
i=0
lst = []
while i < m: 
    l = list(map(int, input().split()))
    l.append(i)
    lst.append(l)
    i+=1

ll=sorted(lst)
for i in range(1,n+1):
    j=1
    for k in ll:
        if i == k[0]:
            k.append(str(i).rjust(6,'0') + str(j).rjust(6,'0'))
            j+=1
#ans
sss= sorted(ll, key=lambda x:x[2])
for ans in sss:
    print(ans[3])

Submission status: Time Limit Exceeded

Solution code:
# -*- coding: utf-8 -*-
n,m = map(int, input().split())
i=0
lst = []
while i < m: 
    l = list(map(int, input().split()))
    l.append(i)
    lst.append(l)
    i+=1
res=[]
lst.sort()
for i in range(1,n+1):
    j=1
    for k in lst:
        if i == k[0]:
            res.append([k[2],str(k[0]).rjust(6,'0') + str(j).rjust(6,'0')])
            j+=1
#ans
res.sort()
for ans in res:
    print(ans[1])

Submission status: Time Limit Exceeded

Solution code:
# -*- coding: utf-8 -*-
#import numpy as np
n,m = map(int, input().split())
i=0
lst = []
while i < m: 
    l = list(map(int, input().split()))
    l.append(i)
    lst.append(l)
    i+=1
sort_lst = sorted(lst)
i=1
res=[]
for i in range(1,n+1):
    j=1
    for k in sort_lst:
        if i == k[0]:
            res.append([k[2],str(k[0]).rjust(6,'0') + str(j).rjust(6,'0')])
            j+=1
#ans
for ans in sorted(res):
    print(ans[1])

Submission status: Time Limit Exceeded

Solution code:
# -*- coding: utf-8 -*-
#import numpy as np
n,m = map(int, input().split())
i=0
lst = []
while i < m: 
    l = list(map(int, input().split()))
    l.append(i)
    lst.append(l)
    i+=1
sort_lst = sorted(lst)
i=1
res=[]
for i in range(1,n+1):
    j=1
    for k in sort_lst:
        if i == k[0]:
            res.append([k[2],str(k[0])+str(k[1]),str(k[0]).rjust(6,'0') + str(j).rjust(6,'0')])
            j+=1
#ans
for ans in sorted(res):
    print(ans[2])

Submission status: Time Limit Exceeded

Solution code:
# -*- coding: utf-8 -*-
#import numpy as np
n,m = map(int, input().split())
i=0
lst = []
while i < m: 
    l = map(int, input().split())
    lst.append(list(l))
    i+=1

sort_lst = sorted(lst)
i=1
res=[]
for i in range(1,n+1):
    j=1
    for k in sort_lst:
        if i == k[0]:
            res.append([str(k[0])+str(k[1]),str(k[0]).rjust(6,'0') + str(j).rjust(6,'0')])
            j+=1

#ans
for ans in lst:
    for r in res:
        if str(ans[0])+str(ans[1]) == r[0]:
            print(r[1])

Submission status: Time Limit Exceeded

Solution code:
# -*- coding: utf-8 -*-
#import numpy as np
n,m = map(int, input().split())
i=0
lst = []
while i < m: 
    l = map(int, input().split())
    lst.append(list(l))
    i+=1

sort_lst = sorted(lst)
i=1
k=0
for i in range(1,n+1):
    j=1
    for k in sort_lst:
        if i == k[0]:
            k.append(j)
            j+=1

#ans
for ans in lst:
    for res in sort_lst:
        if ans[0]==res[0] and ans[1] == res[1]:
            print(str(res[0]).rjust(6,'0') + str(res[2]).rjust(6,'0'))

Submission status: Time Limit Exceeded

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

lis = [""] * (m * 4)
set_P = set() 
for i in range(0, m * 4, 4):
  p, y = map(int, input().split())
  lis[i] = i // 4
  lis[i+1] = p
  lis[i+2] = y
  set_P.add(p)

for p in list(set_P):
  y_lis = []
  for i in range(0, m * 4, 4):
    if lis[i + 1] == p:
      y_lis.append([lis[i], lis[i+2]])
  y_lis.sort(key=lambda y_lis:(y_lis[1]))
  for i, city in enumerate(y_lis):
    lis[city[0]*4 + 3] = i + 1
    
for i in range(0, m*4, 4):
  print("{:0=6}".format(lis[i+1]) + "{:0=6}".format(lis[i+3]))

Submission status: Time Limit Exceeded

Solution code:
def main():
  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
  
  for i in range(m):
    cnt = 1
    for j in range(m):
      if P[i] == P[j] and Y[i] > Y[j]:
        cnt += 1
    print(str(P[i]).zfill(6)+str(cnt).zfill(6))
  
if __name__ == '__main__':
  main()

Submission status: Time Limit Exceeded

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

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

dct = {}
for i in range(m):
    if py[i][0] in dct.keys():
        dct[py[i][0]].append(py[i][1])
    else:
        dct[py[i][0]] = [py[i][1]]

for key in dct.keys():
    dct[key].sort()

for i in range(m):
    print("{:06}{:06}".format(py[i][0], dct[py[i][0]].index(py[i][1]) + 1))

Submission status: Time Limit Exceeded

Solution code:
n,m = [int(i) for i in input().split()]
l = [[int(i) for i in input().split()] for _ in range(m)]
l2 = sorted(l,key = lambda x:(x[0],x[1]))
t = [[] for _ in range(n)]

for p,y in l2:
    t[p-1].append(y)
    
for i in l:
    order = t[i[0]-1].index(i[1])
    print(str(i[0]).zfill(6)+str(order+1).zfill(6))

Submission status: Time Limit Exceeded

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

N,M = map(int, input().split())
PY = [list(map(int,input().split())) for _ in range(M)]
PY_originals = tuple(PY)
N_counter = [0] * N
M_counter = [0] * M

PY.sort(key=lambda val: val[1])

for i in range(M):
    N_counter[PY[i][0]-1] += 1
    M_counter[i] = N_counter[PY[i][0]-1]

for i in PY_originals:
    ans = str(i[0]).zfill(6)+str(M_counter[PY.index(i)]).zfill(6)
    print(ans)

Submission status: Time Limit Exceeded

Solution code:
N,M = map(int, input().split())
PY = [list(map(int,input().split())) for _ in range(M)]
PY_originals = tuple(PY)
N_counter = [0] * N
M_counter = [0] * M

PY.sort(key=lambda val: val[1])

for i in range(M):
    N_counter[PY[i][0]-1] += 1
    M_counter[i] = N_counter[PY[i][0]-1]

for i in PY_originals:
    ans = str(i[0]).zfill(6)+str(M_counter[PY.index(i)]).zfill(6)
    print(ans)

Submission status: Time Limit Exceeded

Solution code:
N,M = map(int, input().split())
PY = [list(map(int,input().split())) for _ in range(M)]
PY_originals = tuple(PY)
N_counter = [0] * N
M_counter = [0] * M

PY.sort(key=lambda val: val[1])
i = 0

for P,Y in PY:
    N_counter[P-1] += 1
    M_counter[i] = N_counter[P-1]
    i += 1

for i in PY_originals:
    ans = str(i[0]).zfill(6)+str(M_counter[PY.index(i)]).zfill(6)
    print(ans)

Submission status: Time Limit Exceeded

Solution code:
N,M = map(int, input().split())
PY = [list(map(int,input().split())) for _ in range(M)]
PY_original = tuple(PY)
N_counter = [0] * N
M_counter = [0] * M

PY.sort(key=lambda val: val[1])
i = 0

for P,Y in PY:
    N_counter[P-1] += 1
    M_counter[i] = N_counter[P-1]
    i += 1

for i in PY_original:
    ans = str(i[0]).zfill(6)+str(M_counter[PY.index(i)]).zfill(6)
    print(ans)

Submission status: Time Limit Exceeded

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

c = [[] for i in range(a)]
z = []
for _ in range(b):
  f,g = map(int,input().split())
  c[f - 1].append(g)
  z.append([f,g])

for i in range(a):
    if c[i] != []:
        c[i].sort()

#print(z)
x =''
y = ''
for j in range(b):                    
    x = str(z[j][0])
    x = '0' * (6 - len(x)) + x
    y = str(c[z[j][0] - 1].index(z[j][1]) + 1)
    y = '0' * (6 - len(y)) + y
    print(x + y)

Submission status: Time Limit Exceeded

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

c = [[] for i in range(a)]
z = []
for _ in range(b):
  f,g = map(int,input().split())
  c[f - 1].append(g)
  z.append([f,g])
d = c.copy()


for i in range(a):
    if c[i] != []:
        c[i].sort()

#print(z)
h = []
x =''
y = ''
for j in range(b):                    
    x = str(z[j][0])
    while len(x) <= 5:
        x = '0' + x
    y = str(c[z[j][0] - 1].index(z[j][1]) + 1)
    while len(y) <= 5:
        y = '0' + y
    print(x + y)

Submission status: Time Limit Exceeded

Solution code:
import bisect
from collections import defaultdict

L=[]
d=defaultdict(list)
N,M=map(int,input().split())
for _ in range(M):
    p,y=map(int,input().split())
    L.append((p,y))
    bisect.insort(d[p],y)

for l in L:
    city=l[0]
    x=bisect.bisect_left(d[city],l[1])
    print("{:06}".format(city)+"{:06}".format(x+1))

Submission status: Time Limit Exceeded

Solution code:
import bisect
dic_pref = {}
list_city =[]

def add_city(pno,year):
    if pno not in dic_pref:
        dic_pref[pno] = [year]
    else:
        bisect.insort(dic_pref[pno],year)

N,M = map(int,input().split())
for _ in range(M):
    P,Y = map(int,input().split())
    add_city(P,Y)
    list_city.append([P,Y])

for city in list_city:
    pref = city[ 0 ]
    year = city[ 1 ]
    order = bisect.bisect_left(dic_pref[pref], year)+1
    print("{0:06}{1:06}".format(pref,order))

Submission status: Time Limit Exceeded

Solution code:
n,m = map(int, input().split())
PY = [[] for i in range(m)]
for i in range(m):
  PY[i] = list(map(int, input().split()))
  PY[i].append(i)
  
PY.sort(key = lambda x:x[1])
PY.sort(key = lambda x:x[0])

l = [0]*(n)
for i in range(m):
  l[PY[i][0]-1]+=1

for i in range(n):
  j = 0
  while j < l[i]:
    list(filter(lambda x:x[0]==i+1,PY))[j].append(j+1)
    j += 1
  
PY.sort(key = lambda x:x[2])
for i in range(m):
  print('{:0=6}'.format(PY[i][0])+'{:0=6}'.format(PY[i][3]))

Submission status: Time Limit Exceeded

Solution code:
def main():
    import sys
    input = sys.stdin.readline

    n, m = map(int, input().split())
    query = []
    result =  [[] for i in range(n)]
    for _ in range(m):
        p, y = map(int, input().split())
        query.append((p, y))
        result[p-1].append(y)

    result = [sorted(i) for i in result]
 
    for city in query:
        rank = result[city[0]-1].index(city[1])+1
        resultStr = "{}{}".format(str(city[0]).zfill(6), str(rank).zfill(6))
        print(resultStr)

main()

Submission status: Time Limit Exceeded

Solution code:
def main():
    n, m = map(int, input().split())
    query = []
    result =  [[] for i in range(n)]
    for i in range(m):
        qList = list(map(int, input().split()))
        query.append(qList)
        result[qList[0]-1].append(qList[1])

    for i in result:
        i.sort()

    for city in query:
        rank = result[city[0]-1].index(city[1])+1
        resultStr = "{}{}".format(str(city[0]).zfill(6), str(rank).zfill(6))
        print(resultStr)

if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

Solution code:
n, m = map(int, input().split())
query = []
result =  [[] for i in range(n)]
for i in range(m):
    qList = list(map(int, input().split()))
    query.append(qList)
    result[qList[0]-1].append(qList[1])
 
for i in result:
    i.sort()
 
for city in query:
    rank = result[city[0]-1].index(city[1])+1
    resultStr = "{}{}".format(str(city[0]).zfill(6), str(rank).zfill(6))
    print(resultStr)

Submission status: Time Limit Exceeded

Solution code:
n, m = map(int, input().split())
query = []
result =  [[] for i in range(n)]
for i in range(m):
    qList = list(map(int, input().split()))
    query.append(qList)
    result[qList[0]-1].append(qList[1])

for i in result:
    i.sort()

for city in query:
    rank = result[city[0]-1].index(city[1])+1
    resultStr = "{}{}".format(str(city[0]).zfill(6), str(rank).zfill(6))
    print(resultStr)