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: Wrong Answer

Solution code:
N,M=map(int, input().split())
PY=[list(map(int, input().split()))+[i] for i in range(M)]
PY=list(sorted(PY))
ls=[]
current=0
ct=1
for i in range(M):
    s1=str(PY[i][0])
    s2=''
    for j in range(6-len(s1)):
        s2+='0'
    s3=s2+s1

    if current==PY[i][0]:
        ct+=1
    else:
        ct=1
        current=PY[i][0]

    s4=str(ct)
    s5=''
    for j in range(6-len(s1)):
        s5+='0'
    s6=s5+s4
    s7=s3+s6

    ls.append([s7,PY[i][2]])

ls=sorted(ls, key=lambda x :x[1])
for i in ls:
    print(i[0])

Submission status: Wrong Answer

Solution code:
l = {}
ans = []
n, m = [int(_) for _ in input().split()]
for i in range(m):
    p, y = [int(_) for _ in input().split()]
    if p in l:
        y = l[p] + 1
        l[p] += 1
    else:
        y = 1
        l[p] = 1
    p_zero = '{0:06d}'.format(p)
    y_zero = '{0:06d}'.format(y)
    str = p_zero + y_zero
    ans.append(str)
ans.sort()
for j in range(m):
    print(ans[j])

Submission status: Wrong Answer

Solution code:
def c_id(N, M, City):
    City = sorted(City, key=lambda x: (x[0], x[1]))
    a, b = City[0][0], 1
    for j, (p, y, k) in enumerate(City):
        if p == a:
            City[j] = [p, b, k]
            b += 1
        else:
            a = p
            b = 1
            City[j] = [p, b, k]
    city = sorted(City, key=lambda x: x[2])

    ans_tmp = []
    for p, q, k in city:
        ans_tmp.append('{0:06d}{1:06d}'.format(p, q))
    ans = '\n'.join(ans_tmp)
    return ans

N, M = [int(i) for i in input().split()]
City = [[int(i) for i in input().split()] + [k] for j, k in enumerate(range(M), 1)]
print(c_id(N, M, City))

Submission status: Wrong Answer

Solution code:
N, M = map(int, input().split())
prefs = [list(map(int, input().split())) for _ in range(M)]
dict = {i:[] for i in range(1, N+1)}
count = 1
for pref in prefs:
    list = [pref[1], count]
    dict[pref[0]].append(list)
    count += 1
for k, v in dict.items():
    dict[k] = sorted(v)
result_dict = {i:[] for i in range(1, N+1)}
for k, v in dict.items():
    for i in range(len(v)):
        result_dict[v[i][1]] = '{0:06d}'.format(k) + '{0:06d}'.format(i+1)

for v in result_dict.values():
    print(v)

Submission status: Wrong Answer

Solution code:
n, m = map(int, input().split())
P = [0]*(m+1)
Y = [0]*(m+1)
for i in range(1, m+1):
    P[i], Y[i] = map(int, input().split())
PP = [[] for i in range(n+1)]
#print(PP)
for i in range(1, m+1):
    p = P[i]
    y = Y[i]
    PP[p].append((i, y))

for i in range(1, n+1):
    if len(PP[i]) == 0:
        continue
    for j in range(1, len(PP[i])+1):
         print('%06d%06d' % (i, j))
    #if len(PP[i]) > 1:
    #    PP[i].sort(key=lambda x: x[1])
    #for i, pp in enumerate(PP[i]):
    #    num = '%06d%06d' % (i, )

Submission status: Wrong Answer

Solution code:
n, m =map(int, input().split())
py_array = [[int(x) for x in input().split()]+[y] for x, y in enumerate(range(m), 0)]
py_array = sorted(py_array, key=lambda x:(x[0], x[1]))

base = 1
base2 = 0
res_array = []
for i, j, k in py_array:
    if base == i:
        base2 += 1
        print(i)
    else:
        base = i
        base2 = 1
    res_array.append([str(base).zfill(6), str(base2).zfill(6), k])

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

for i, j, k in res_array:
    print(i+j)

Submission status: Wrong Answer

Solution code:
N, M = map(int, input().split())
d={}
pl=[]
yl=[]
for i in range(N+1):
    d[i]=[]
for i in range(M):
    P, Y = map(int, input().split())
    pl.append(P)
    yl.append(Y)
    d[P].append(Y)
    
for i in range(N+1):
    d[i].sort()

for i in range(M):
    pi='{0:06d}'.format(pl[i])
    x='{0:06d}'.format(d[pl[i]].index(yl[i])+1)
    print(int(pi+x))

Submission status: Wrong Answer

Solution code:
N,M=map(int, input().split())
PY=[list(map(int, input().split()))+[i] for i in range(M)]
PY=list(sorted(PY))
ls=[]
current=0
ct=1
for i in range(M):
    s1=str(PY[i][0])
    s2=''
    for j in range(6-len(s1)):
        s2+='0'
    s3=s2+s1

    if current==PY[i][0]:
        ct+=1
    else:
        ct=1
        current=PY[i][0]

    s4=str(ct)
    s5=''
    for j in range(6-len(s1)):
        s5+='0'
    s6=s5+s4
    s7=s3+s6

    ls.append([s7,PY[i][2]])


for i in ls:
    print(i[0])

Submission status: Wrong Answer

Solution code:
n, m =map(int, input().split())
py_array = [[int(x) for x in input().split()]+[y] for x, y in enumerate(range(m), 0)]
py_array = sorted(py_array, key=lambda x:(x[0], x[1]))

base = 1
base2 = 0
res_array = []
for i, j, k in py_array:
    if base == i:
        base2 += 1
        print(i)
    else:
        base = i
        base2 = 1
    res_array.append([str(base).zfill(6), str(base2).zfill(6), k])

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

for i, j, k in res_array:
    print(i, j)

Submission status: Wrong Answer

Solution code:
n,m=map(int,input().split())
l=[]
for i in range(n):l.append([])
for i in range(m):
    p,y=map(int,input().split())
    l[p-1].append((i,y))
rl=[]
for i in range(n):
    ll=l[i]
    ll.sort(key=lambda x:x[1])
    hd="000000"+str(i+1)[-6:]
    rr=[(ll[j][0],hd+("000000"+str(j+1))[-6:]) for j in range(len(ll))]
    rl+=rr
rl.sort()
for e in rl:
    print(e[1])

Submission status: Wrong Answer

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)
for i in range(m):
    n=1
    for j in range(m):
        if l[i][0]==l[j][0] and l[i][1]>l[j][1]:
            n+=1
    print(str('%06d'%l[i][0])+str('%06d'%n))

Submission status: Wrong Answer

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

import sys
import itertools
import math

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

ps=dict()
for c,(p,y) in enumerate(C):
    if not p in ps:
        ps[p]=[]
    ps[p].append((y,c))

qs=[]
for p,cs in ps.items():
    cs.sort()
    qs += [(c,p,i) for i,(y,c) in enumerate(cs)]

qs.sort()

for c,p,i in qs:
    print("{0:0=6}{1:0=6}".format(p,i))

Submission status: Wrong Answer

Solution code:
import numpy as np
N,M = [int(x) for x in input().strip('\n').split(' ')]
lis = np.zeros(N+1).astype('int32')
for i in range(M):
    p,y = [int(x) for x in input().strip('\n').split(' ')]
    lis[p] += 1
for i in range(N+1):
    if lis[i]==0:
        continue
    for j in range(lis[i]):
        print('%06d%06d' % (i,j+1))

Submission status: Wrong Answer

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

dic_p = {i: [] for i in range(1, N + 1)}

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

for i in range(1, N + 1):
    prefecture = '{:0=6}'.format(i)
    sorted(dic_p[i])
    for index, _ in enumerate(dic_p[i]):
        city = '{:0=6}'.format(index + 1)
        print(prefecture + city)

Submission status: Wrong Answer

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

P = [0]*N

for x in range(M):
	p, y = list(map(int, input().split()))
	P[p-1] += 1

for i, x in enumerate(P):
	for j in range(x):
		print(str('{0:06d}'.format(i+1))+str('{0:06d}'.format(j+1)))

Submission status: Wrong Answer

Solution code:
n,m=map(int,input().split())
l=[]
for i in range(n):l.append([])
for i in range(m):
    print(i)
    p,y=map(int,input().split())
    l[p-1].append((i,y))
rl=[]
for i in range(n):
    ll=l[i]
    ll.sort(key=lambda x:x[1])
    hd="000000"+str(i+1)[-6:]
    rr=[(ll[j][0],hd+("000000"+str(j+1))[-6:]) for j in range(len(ll))]
    rl+=rr
rl.sort()
for e in rl:
    print(e[1])

Submission status: Wrong Answer

Solution code:
import heapq

N, M = map(int, input().split())
S = ["" for m in range(M)]

D = {}
for m in range(M):
    P, Y = map(int, input().split())
    listP = D.setdefault(P, [])
    heapq.heappush(listP, (Y, m))

print(D)

for p, l in D.items():
    for i in range(len(l)):
        y, m = heapq.heappop(l)
        S[m] = format(p, "06") + format(i + 1, "06")

for s in S:
    print(s)

Submission status: Wrong Answer

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

PY = []
P_Y = [[] for i in range(N)]

for i in range(M):
    p,y = list(map(int,input().split()))
    P_Y[p-1].append(y)
    PY.append([p,y])
    
import numpy as np

for i in range(N):
    P_Y[i]=np.argsort(np.array(P_Y[i]))
    
p_count = [0 for i in range(N)]

for i in range(M):
    ps = str(1000000+PY[i][0])
    ys = str(1000000+P_Y[PY[i][0]-1][p_count[PY[i][0]-1]] + 1)
    p_count[PY[i][0]-1]+=1
    print(ps[1:]+ys[1:])

Submission status: Wrong Answer

Solution code:
import numpy as np
N,M = [int(x) for x in input().strip('\n').split(' ')]
lis = np.zeros(N+1).astype('int')
for i in range(M):
    p,y = [int(x) for x in input().strip('\n').split(' ')]
    lis[p] += 1
for i in range(N+1):
    if lis[i]==0:
        continue
    for j in range(lis[i]):
        print('%06d%06d' % (i,j+1))

Submission status: Wrong Answer

Solution code:

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

city = []
PY = []
for i in range(M):
    ll = [i] + list(map(int, input().split(" ")))
    # print(ll)
    PY.append(ll)

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

ken = [1]*N
answer = []
for i in range(M):
    ue6 = "{0:06d}".format(PY[i][1])
    sita6 = "{0:06d}".format(ken[PY[i][1]-1])
    ken[PY[i][1]-1] += 1
    answer.append([PY[i][0], ue6+sita6])

answer = sorted(answer, key=lambda x: x[0])
for i in range(M):
    print(answer[i][1])

Submission status: Wrong Answer

Solution code:
import numpy as np

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

py = np.array(py)
for i in range(1, n+1):
    mask = py[:, 0] == i
    py[mask, 1] = np.argsort(py[mask, 1]) + 1
for [p, y] in py:
    print('{0:06d}{1:06d}'.format(p, y))

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
n,m = map(int, input().split())
pl =[1]*(n+1)

a=[]
for i in range(0,m):
  p,l = map(int, input().split())
  s='{:06}{:06}'.format(p,pl[p])
  pl[p]=pl[p]+1
  a.append(s)
a.sort()
for i in range(0,m):
  print(a[i])

Submission status: Wrong Answer

Solution code:
a = input().split()
a = [int(i) for i in a]
query = []
citydict = dict()
for i in range(a[1]):
	temp = input().split()
	query.append(temp)
	if temp[0] not in citydict:
		citydict[temp[0]] = [temp[1]]
	else:
		citydict[temp[0]].append(temp[1])
		
for i in citydict:
	citydict[i] = sorted(citydict[i])
	
for i in query:
	print (i[0].zfill(6) + str(citydict[i[0]].index(i[1]) + 1).zfill(6))

Submission status: Wrong Answer

Solution code:
from itertools import groupby

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

a.sort(key=lambda x: x[1]*10**5+x[2])
r = []
for k, g in groupby(a, key=lambda x: x[1]):
  pre ='{0:06d}'.format(k)
  for j, (i, _, _) in enumerate(g):
    r.append((i, pre + '{0:06d}'.format(j+1)))
r.sort()
for _, s in r:
  print(s)

Submission status: Wrong Answer

Solution code:
N, M = list(map(int, input().split()))
PYs = {}
for _ in range(M):
    p, y = list(map(int, input().split()))
    if p not in PYs:
        PYs[p] = []
    PYs[p].append(y)

for p in sorted(PYs.keys()):
    str_p = '{}'.format(p).zfill(6)
    for idx, c in enumerate(sorted(PYs[p])):
        print(str_p + '{}'.format(idx + 1).zfill(6))

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
import bisect
import heapq
import math
import random
import sys
from collections import Counter, defaultdict, deque
from decimal import ROUND_CEILING, ROUND_HALF_UP, Decimal
from functools import lru_cache, reduce
from itertools import combinations, combinations_with_replacement, product, permutations
from operator import add, mul, sub

sys.setrecursionlimit(10000)


def read_int():
    return int(input())


def read_int_n():
    return list(map(int, input().split()))


def read_float():
    return float(input())


def read_float_n():
    return list(map(float, input().split()))


def read_str():
    return input().strip()


def read_str_n():
    return list(map(str, input().split()))


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


def mt(f):
    import time

    def wrap(*args, **kwargs):
        s = time.time()
        ret = f(*args, **kwargs)
        e = time.time()

        error_print(e - s, 'sec')
        return ret

    return wrap


@mt
def slv(N, M, PY):
    PY.sort(key=lambda x: x[1])

    id = []
    pc = Counter()
    for p, y in PY:
        pc[p] += 1
        id.append("%06d%06d" % (p, pc[p]))

    id.sort(key=lambda x: x[6:])
    for i in id:
        print(i)


def main():
    N, M = read_int_n()
    PY = [read_int_n() for _ in range(M)]
    slv(N, M, PY)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import collections
n,m = map(int, input().split())
l=[]
for i in range(m):
  p,y = map(int, input().split())
  l.append((i,p,y))
l.sort(key=lambda x:x[2])
r={}
c = {}
for i,p,y in l:
  if p not in c:
    c[p] = 0
  c[p] += 1
  r[i] = (p, c[p])

for i in range(m):
  print(str(r[i][0]).rjust(10,'0') + str(r[i][1]).rjust(10,'0'))

Submission status: Wrong Answer

Solution code:
n,m=map(int,input().split())
dict1={}
dict2={}
for i in range(m):
    x,y=map(int,input().split())
    try:
        dict1[x].append([y,i+1])
    except:
        KeyError
        dict1[x]=[[y,i+1]]
ansarr=["0"]*m
for i in dict1.keys():
    dict1[i].sort()
    s1=(6-len(str(i)))*'0'+str(i)
    for j in range(len(dict1[i])):
        s2=(6-len(str(j+1)))*'0'+str(j+1)
        print(dict1[i][j][1])
        ansarr[dict1[i][j][1]-1]=s1+s2
for i in range(m):
    print(ansarr[i])

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
n,m = map(int, input().split())
d = {}
for i in range(1,m+1):
    p,y = map(int, input().split())
    if p not in d:
        d[p] = []
    d[p].append([y,i])

for k in d.keys():
    d[k] = sorted(d[k])

ret = []
for k in d.keys():
    for i in range(len(d[k])):
        idx = i+1
        ret.append("{:06x}{:06x}".format(k,idx))

for s in sorted(ret):
    print(s)

Submission status: Wrong Answer

Solution code:
N, M = map( int, input().split())
X = [(0,0)]*M
Y = [1]*(N+1)
for i in range(M):
    p,y = map( int, input().split())
    X[i] = (y,p)
X.sort()
for i in range(M):
    y, p = X[i]
    ans = '%06d'%p + '%06d'%Y[p]
    print(ans)
    Y[p] += 1

Submission status: Wrong Answer

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

PYI=[PY[i]+[i] for i in range(M)]

PYI.sort(key=lambda x:x[1])

Nu=[1]*(N+1)
ANS=[None]*M

for p,y,i in PYI:
    ANS[i]=(p,Nu[p])
    Nu[p]+=1

print(ANS)

def numb(x,y):
    x=str(x)
    y=str(y)
    l=len(x)
    m=len(y)

    return (6-l)*"0"+x+(6-m)*"0"+y

for a,b in ANS:
    print(numb(a,b))

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
import bisect
import heapq
import math
import random
import sys
from collections import Counter, defaultdict, deque
from decimal import ROUND_CEILING, ROUND_HALF_UP, Decimal
from functools import lru_cache, reduce
from itertools import combinations, combinations_with_replacement, product, permutations
from operator import add, mul, sub

sys.setrecursionlimit(10000)


def read_int():
    return int(input())


def read_int_n():
    return list(map(int, input().split()))


def read_float():
    return float(input())


def read_float_n():
    return list(map(float, input().split()))


def read_str():
    return input().strip()


def read_str_n():
    return list(map(str, input().split()))


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


def mt(f):
    import time

    def wrap(*args, **kwargs):
        s = time.time()
        ret = f(*args, **kwargs)
        e = time.time()

        error_print(e - s, 'sec')
        return ret

    return wrap


@mt
def slv(N, M, PY):
    PY.sort(key=lambda x: x[1])

    id = []
    pc = Counter()
    for p, y in PY:
        pc[p] += 1
        id.append("%06d%06d" % (p, pc[p]))

    id.sort()
    for i in id:
        print(i)


def main():
    N, M = read_int_n()
    PY = [read_int_n() for _ in range(M)]
    slv(N, M, PY)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

ans = [0]*m
prefecs = [1]*(n+1)
for i, (p, y) in enumerate(py):
    top = p
    under = prefecs[p]
    ans[i] = str(top).zfill(6)+str(under).zfill(6)
    prefecs[p] += 1

for i in range(m):
    print(ans[i])

Submission status: Time Limit Exceeded

Solution code:
n, m = map(int, input().split())
list_PY = [ list(map(int,input().split(" "))) for _ in range(m)]
list_K = [[] for _ in range(n + 1)]

for p, y in list_PY:
    list_K[p].append(y)

for l in list_K:
    l.sort()

for p, y in list_PY:
    u = str(p)
    u = "0" * (6 - len(u)) + u

    d = str(list_K[p].index(y) + 1)
    d = "0" * (6 - len(d)) + d

    print(u + d)

Submission status: Time Limit Exceeded

Solution code:
n, m = map(int, input().split())
list_PY = [ list(map(int,input().split(" "))) for _ in range(m)]
list_K = [[] for _ in range(n + 1)]

for p, y in list_PY:
    list_K[p].append(y)

for l in list_K:
    l.sort()

for p, y in list_PY:
    u = str(p)
    while True:
        if len(u) == 6:
            break
        u = "0" + u

    d = str(list_K[p].index(y) + 1)

    while True:
        if len(d) == 6:
            break
        d = "0" + d

    print(u + d)

Submission status: Time Limit Exceeded

Solution code:
N,M = map(int,input().split())
py = [list(map(int,input().split())) for i in range(M)]
P = [[] for i in range(N)]
for p,y in py:
    P[p-1].append(y)
for i in P:
    i.sort()
for p,y in py:
    c = str(P[p-1].index(y) + 1)
    p = str(p)
    ans = "0" * (6-len(p)) + p + "0" *(6-len(c)) + c
    print(ans)

Submission status: Time Limit Exceeded

Solution code:
from collections import defaultdict


def mapt(fn, *args):
    return tuple(map(fn, *args))


def Input():
    return mapt(int, input().split(" "))


def main():
    n, m = Input()
    data = [Input() for _ in range(m)]
    sorted_data = sorted(data)
    previous = sorted_data[0][0]
    count = 0
    d = defaultdict()
    for x, y in sorted_data:
        if previous == x:
            count += 1
        else:
            count = 1
            previous = x

        index = data.index((x, y))
        d[index] = str(x).rjust(6, "0") + str(count).rjust(6, "0")

    for key, value in sorted(d.items(), key=lambda x:x[0]):
        print(value)
main()

Submission status: Time Limit Exceeded

Solution code:
# -*- coding: utf-8 -*-
"""
Created on Tue Sep 15 01:01:58 2020

@author: liang
"""
#ゼロパディング＋インデックス
#str(1).zfill(6) + str(a.index(2) + 1).zfill(6)

N, M = map(int, input().split())
#d = [list() for _ in range(N)]
dic = dict()
P = list()

#insert O(M)
for i in range(M):
    p, y = map(int,input().split())
    #d[p-1].append(y)
    if p not in dic.keys():
        dic[p] = [y]
    else:
        dic[p].append(y)
    P.append((p,y))

#year sort O(N log N) => 重い　dict使用
#for i in range(N):
#    d[i].sort()
for key in dic.keys():
    dic[key].sort()

#search O(M)
for i in range(M):
    p, y = P[i]
    #ans = str(p).zfill(6)+str(d[p-1].index(y)+1).zfill(6)
    # zfill 重い？
    ans = ''
    ans += '0'*( 6 - len(str(p))) + str(p)
    t = dic[p].index(y)+1
    ans += '0'*( 6 - len(str(t))) + str(t)
    print(ans)

Submission status: Time Limit Exceeded

Solution code:
# -*- coding: utf-8 -*-
"""
Created on Tue Sep 15 01:01:58 2020

@author: liang
"""
#ゼロパディング＋インデックス
#str(1).zfill(6) + str(a.index(2) + 1).zfill(6)

N, M = map(int, input().split())
#d = [list() for _ in range(N)]
dic = dict()
P = list()

#insert O(M)
for i in range(M):
    p, y = map(int,input().split())
    #d[p-1].append(y)
    if p not in dic.keys():
        dic[p] = [y]
    else:
        dic[p].append(y)
    P.append((p,y))

#year sort O(N log N) => 重い　dict使用
#for i in range(N):
#    d[i].sort()
for key in dic.keys():
    dic[key].sort()

#search O(M)
for i in range(M):
    p, y = P[i]
    #ans = str(p).zfill(6)+str(d[p-1].index(y)+1).zfill(6)
    ans = str(p).zfill(6)+str(dic[p].index(y)+1).zfill(6)
    print(ans)

Submission status: Time Limit Exceeded

Solution code:
# -*- coding: utf-8 -*-
"""
Created on Tue Sep 15 01:01:58 2020

@author: liang
"""
#ゼロパディング＋インデックス
#str(1).zfill(6) + str(a.index(2) + 1).zfill(6)

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

#insert O(M)
for i in range(M):
    p, y = map(int,input().split())
    d[p-1].append(y)
    P.append((p,y))

#year sort O(N log N)
for i in range(N):
    d[i].sort()

#search O(M)
for i in range(M):
    p, y = P[i]
    ans = str(p).zfill(6)+str(d[p-1].index(y)+1).zfill(6)
    print(ans)

Submission status: Time Limit Exceeded

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

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

P_1 = [sorted(l) for l in P]

for p,y in Q:
    a = str(p).zfill(6)
    b = str(P_1[p-1].index(y) + 1).zfill(6)
    print(a+b)

Submission status: Time Limit Exceeded

Solution code:

url = "https://atcoder.jp//contests/abc113/tasks/abc113_c"

def main():
    t = list(map(int, input().split()))
    town = {k: [] for k in range(1, t[0]+1)}
    all_town = []
    for _ in range(t[1]):
        tmp = list(map(int, input().split()))
        all_town.append(tmp)
        town[tmp[0]].append(tmp[1])
    for k in town:
        town[k].sort()
    for row in all_town:
        print(str(row[0]).zfill(6) + str(town[row[0]].index(row[1])+1).zfill(6))


if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
# coding=utf-8
from math import floor, ceil, sqrt, factorial, log, gcd
from itertools import accumulate, permutations, combinations, product, combinations_with_replacement
from bisect import bisect_left, bisect_right
from collections import Counter, defaultdict
from heapq import heappop, heappush, heappushpop, heapify
import copy
import numpy as np
import sys
INF = float('inf')
mod = 10**9+7
sys.setrecursionlimit(10 ** 6)


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

# 1 2 3
# a, b, c = LI()


def LI(): return list(map(int, sys.stdin.buffer.readline().split()))

# a = I()


def I(): return int(sys.stdin.buffer.readline())

# abc def
# a, b = LS()


def LS(): return sys.stdin.buffer.readline().rstrip().decode('utf-8').split()

# a = S()


def S(): return sys.stdin.buffer.readline().rstrip().decode('utf-8')

# 2
# 1
# 2
# [1, 2]


def IR(n): return [I() for i in range(n)]

# 2
# 1 2 3
# 4 5 6
# [[1,2,3], [4,5,6]]


def LIR(n): return [LI() for i in range(n)]

# 2
# abc
# def
# [abc, def]


def SR(n): return [S() for i in range(n)]

# 2
# abc def
# ghi jkl
# [[abc,def], [ghi,jkl]]


def LSR(n): return [LS() for i in range(n)]

# 2
# abcd
# efgh
# [[a,b,c,d], [e,f,g,h]]


def SRL(n): return [list(S()) for i in range(n)]


def main():
    n, m = LI()
    py = LIR(m)
    lst = [[] for i in range(n)]

    for pair in py:
        lst[pair[0] - 1].append(pair[1])

    for i in range(n):
        if len(lst[i]) > 1:
            lst[i].sort()

    for pair in py:
        print(str(pair[0]*1000000+lst[pair[0]-1].index(pair[1])+1).zfill(12))


if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

Solution code:
N,M=map(int,input().split())
d={}
PY=[]
for _ in range(M):
    p,y=map(int,input().split())
    PY.append((p,y))
    d[p]=d.get(p, [])+[y]

dx={}
for k, v in d.items():
    sv=sorted(v)
    for i in range(len(sv)):
        dx[(k,sv[i])]=i+1
        
for p,y in PY:
    print(str(p).zfill(6)+str(dx[(p,y)]).zfill(6))

Submission status: Time Limit Exceeded

Solution code:
N,M=map(int,input().split())
d={}
PY=[]
for _ in range(M):
    p,y=map(int,input().split())
    PY.append((p,y))
    d[p]=d.get(p, [])+[y]

import bisect

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

for p,y in PY:
    print(str(p).zfill(6)+str(bisect.bisect_left(d[p],y)+1).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)]
d={}
import bisect

for p,y in PY:
    d[p]=d.get(p, [])+[y]

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

for p,y in PY:
    print(str(p).zfill(6)+str(bisect.bisect_left(d[p],y)+1).zfill(6))

Submission status: Time Limit Exceeded

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

for i in range(m):
  x,y=map(int,input().split())
  lst[x].append(y)
  prev.append([x,y])
  
for i in lst:
  i.sort()
  
for i in prev:
  s,t=i[0],i[1]
  x=lst[s].index(t)+1
  
  s,x=str(s),str(x)
  
  while len(s)<6:
    s='0'+s

  while len(x)<6:
    x='0'+x

  print(s+x)

Submission status: Time Limit Exceeded

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

for i in range(m):
  x,y=map(int,input().split())
  lst[x].append(y)
  prev.append([x,y])
  
for i in lst:
  i.sort()
  
for i in prev:
  s,t=i[0],i[1]
  for j,v in enumerate(lst[s]):
    if v==t:
      x=j+1
  
  s,x=str(s),str(x)
  
  while len(s)<6:
    s='0'+s

  while len(x)<6:
    x='0'+x

  print(s+x)

Submission status: Time Limit Exceeded

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

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

for i in l: i.sort()
for i in city:
  ans = ""
  ans += "0"*(6-len(str(i[0])))+str(i[0])
  t = str(l[i[0]-1].index(i[1])+1)
  ans += "0"*(6-len(t))+t
  print(ans)

Submission status: Time Limit Exceeded

Solution code:
import sys
def main():
   input = sys.stdin.buffer.readline
   n,m = map(int, input().split())
   results = {}
   p_list=[]
   y_list=[]
   cnt = 0
   for i in range(m):
       p,y = map(int, input().split())
       p_list.append(p)
       y_list.append(y)
       if results.get(p) is None:
           results[p] = [y]
       else:
           results[p].append(y)
   for i ,p in enumerate(p_list):
       p_sort = sorted(results[p])
       import bisect
       print('{:006}'.format(p)+'{:006}'.format(bisect.bisect_left(p_sort,y_list[i])+1))
if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

Solution code:
import sys
def main():
   input = sys.stdin.buffer.readline
   n,m = map(int, input().split())
   results = {}
   p_list=[]
   y_list=[]
   cnt = 0
   for i in range(m):
       p,y = map(int, input().split())
       p_list.append(p)
       y_list.append(y)
       if results.get(p) is None:
           results[p] = [y]
       else:
           results[p].append(y)
   for i in p_list:
       p_sort = sorted(results[i])
       print('{:006}'.format(i)+'{:006}'.format(p_sort.index(y_list[cnt])+1))
       cnt+=1
if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

Solution code:
import sys

def main():
   input = sys.stdin.buffer.readline
   n,m = map(int, input().split())
   results = {}
   p_list=[]
   y_list=[]
   cnt = 0
   
   for i in range(m):
       p,y = map(int, input().split())
       p_list.append(p)
       y_list.append(y)
       results.setdefault(p,[]).append(y)
       
   for i in p_list:
       p_sort = sorted(results[i])
       print('{:006}'.format(i)+'{:006}'.format(p_sort.index(y_list[cnt])+1))
       cnt+=1
       
   
if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

Solution code:
import sys

def main():
   n,m = map(int, input().split())
   results = {}
   p_list=[]
   y_list=[]
   cnt = 0
   
   for i in range(m):
       p,y = map(int, input().split())
       p_list.append(p)
       y_list.append(y)
       results.setdefault(p,[]).append(y)
       
   for i in p_list:
       p_sort = sorted(results[i])
       print('{:006}'.format(i)+'{:006}'.format(p_sort.index(y_list[cnt])+1))
       cnt+=1
       
   
if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

Solution code:
# n県、m市の数
#y年, p県に属する
import numpy as np
n,m = list(map(int, input().split()))
ls = np.array([0] *(n+1))
pys = []

for i in range(m):
    p,y=list(map(int, input().split()))
    ls[p] += 1
    pys.append([p,y])
    
cp_list = pys.copy()
cp_list.sort()

ls = np.cumsum(ls)

for py in pys:
    idx = cp_list.index(py)
    a,b = py
    print(str(a).zfill(6) + str(idx-ls[a-1]+1).zfill(6))

Submission status: Time Limit Exceeded

Solution code:
#n県、m市の数
#y年, p県に属する
n,m = list(map(int, input().split()))
ls = [0] *n
param_list = []

for i in range(m):
    p,y=list(map(int, input().split()))
    ls[p-1] += 1
    param_list.append([p,y])
    
cp_list = param_list.copy()
cp_list.sort()

for i in range(m):
    idx = cp_list.index(param_list[i])
    a,b = param_list[i]
    print(str(a).zfill(6) + str(idx-sum(ls[:a-1])+1).zfill(6))

Submission status: Time Limit Exceeded

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

for p,y in py:
  s = str(p)
  t = str(l[p].index(y)+1)
  ans = "0"*(6-len(s))+s + "0"*(6-len(t))+t
  print(ans)

Submission status: Time Limit Exceeded

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

for i in range(M):
  p, y = map(int, input().split())
  pairs.append((p, y))
  if p not in ys:
    ys[p] = [y]
  else:
    ys[p].append(y)

for p, y in pairs:
  ys[p].sort()
  ID = str(p).rjust(6, "0")
  n = ys[p].index(y) + 1
  ID += str(n).rjust(6, "0")
  print(ID)

Submission status: Time Limit Exceeded

Solution code:
n,m=map(int,input().split())
ken=[[] for i in range(n+1)]
inf=[[] for i in range(m)]
def f(x):
    m=0
    while x>0:
        m+=1
        x=x//10
    return m

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

for i in range(n):
    ken[i+1]=sorted(ken[i+1])
for i in range(m):
    ans=""
    p=inf[i][0]
    y=inf[i][1]
    for j in range(6-f(p)):
        ans+="0"
    ans=ans+str(p)
    x=ken[p].index(y)+1
    for j in range(6-f(x)):
        ans=ans+"0"
    ans=ans+str(x)
    print(ans)