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: Runtime Error

Solution code:
n,m = map(int,input().split())
lst = [list(map(int,input().split())) for i in range(m)]
order = sorted(lst , key=lambda x:(x[0],x[1]))
mydict = {}

c = 1
for i in range(len(order)-1):
    mydict[str(order[i])] = c
    if order[i][0] == order[i+1][0]:
        c += 1
    else:
        c = 1
if order[m-1][0] == order[m-2][0]:
    mydict[str(order[m-1])] = order[m-2][2]+1
else:
    mydict[str(order[m-1])] = 1

for i in range(m):
    val = mydict[str(lst[i])]
    p = lst[i][0]
    s='0'*(6-len(str(p)))+str(p)+'0'*(6-len(str(val)))+str(val)
    print(s)

Submission status: Runtime Error

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

c = 1
for i in range(len(order)-1):
    order[i].append(c)
    if order[i][0] == order[i+1][0]:
        c += 1
    else:
        c = 1
if order[m-1][0] == order[m-2][0]:
    order[m-1].append(order[m-2][2]+1)
else:
    order[m-1].append(1)


for i in range(m):
    p,y = lst[i][0],lst[i][1]
    for odr in order:
        if odr[0]==p and odr[1]==y:
            x = odr[2]
    s='0'*(6-len(str(p)))+str(p)+'0'*(6-len(str(x)))+str(x)
    print(s)

Submission status: Runtime Error

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

Submission status: Runtime Error

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

p_y_li = [list(map(int, (input() + " {}".format(i)).split())) for i in range(m)]

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

li = [0 for _ in range(m)]
for i in range(m):
    ans = ""
    p = p_y_li[i][0]
    li[p-1] += 1
    x = li[p-1]
    ans = str(p).zfill(6) + str(x).zfill(6)
    p_y_li[i].append(ans)

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

Submission status: Runtime Error

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

L.sort(key=lambda x:(x[0], x[1]))
before = L[0][0]
num = 1
for i in range(M):
  if L[i][0] == before:
    num += 1
    id = '{:06d}'.format(L[i][0]) + '{:06d}'.format(num)
    ans[L[i][2]] = id
  else:
    num = 1
    id = '{:06d}'.format(L[i][0]) + '{:06d}'.format(num)
    ans[L[i][2]] = id
    before = L[i][0]
for city in ans:
  print(city)

Submission status: Runtime Error

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

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

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

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

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

Submission status: Runtime Error

Solution code:
n, m = map(int, input().split())
py = [list(map(int, input().split()))for i in range(m)]
pre = [[] for i in range(n)]
for i in range(3): pre[py[i][0]-1].append(py[i][1])
for i in range(n): pre[i].sort()
for i in range(3):
    j = pre[py[i][0]-1].index(py[i][1])
    print("%06d%06d" % (py[i][0], j+1))

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
def pypri(p,y):print(str(p).zfill(6)+str(y).zfill(6))
n,m=map(int,input().split())
a=[[]for _ in range(n)]
b=[]
for i in range(m):
  p,y=map(int,input.split())
  b.append(p-1)
  a[p-1].append([y,len(a[p-1])+1])
for i in range(n):
  a[i].sort()
  for j in range(len(a[i])):
    a[i][j]=[a[i][j][1],j]
    a.sort()
for i in b:
  pypri(i+1,a[i][0][1]+1)
  del a[i][0]

Submission status: Runtime Error

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

ans = sorted(ls,key=lambda x:(x[0],x[1]))

dic = [[] for _ in range(m+1)]

for i in range(m):
    key = ans[i][0]
    value = ans[i][1]
    dic[key].append(value)

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

Submission status: Runtime Error

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

ans = sorted(ls,key=lambda x:(x[0],x[1]))

dic = [[] for _ in range(m+1)]

for i in range(m):
    key = ans[i][0]
    value = ans[i][1]
    dic[key+1].append(value)

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

Submission status: Runtime Error

Solution code:
N, M = map(int,input().split())
li = []
cnt = {}
ans = ["" for i in range(M)]
for i in range(M):
    p, y = list(map(int, input().split()))
    li.append([i,p,y])
    cnt[i+1] = 0

li.sort(key=lambda x: x[2])
for i in range(M):
    ans[li[i][0]] = "{0:06d}{1:06d}".format(li[i][1],cnt[li[i][1]]+1)
    cnt[li[i][1]] +=1

for i in ans:
    print(i)

Submission status: Runtime Error

Solution code:
N, M = map(int,input().split())
li = []
cnt = {}
ans = []
for i in range(M):
    p, y = list(map(int, input().split()))
    li.append([i,p,y])
    cnt[i+1] = 0

li.sort(key=lambda x: x[2])
for i in range(M):
    st = "{0:06d}{1:06d}".format(li[i][1],cnt[li[i][1]]+1)
    ans.append(st)
    cnt[li[i][1]] +=1

print(ans)

Submission status: Runtime Error

Solution code:
N, M = map(int, input().split())
A=[]
count=[1]*100000
ans=[]
for i in range(M):
    a, b, = map(int, input().split())
    A.append([b, a, i])

A.sort()

for i in range(M):
    number=A[i][1]*1000000+count[int(A[i][1])]
    ans.append([A[i][2],str(number).zfill(12)])
    count[int(A[i][1])] +=1
ans.sort()

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

Submission status: Runtime Error

Solution code:
N, M = map(int, input().split())
A=[]
count=[1]*100000
number=0
for i in range(M):
    a, b, = map(int, input().split())
    A.append([b, a])

A.sort()

for i in range(M):
    number=A[i][1]*1000000+count[int(A[i][1])]
    print(str(number).zfill(12))
    count[int(A[i][1])] +=1

Submission status: Runtime Error

Solution code:
n,m = map(int, input().split())
py = [[list(map(int, input().split()))] + [i] for i in range(m)]
py.sort(key=lambda x: [x[0], x[1]])
ans = []
P = [0] * (n + 1)
for p, y, i in py:
    P[p] += 1
    tmp = str(p).zfill(6) + str(P[p]).zfill(6)
    ans.append([i,tmp])
ans.sort()
for i,a in ans:
    print(a)

Submission status: Runtime Error

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

cnt = [[0] for _ in range(n+1)]

for i in range(m):
    idx = ls[i][0]
    cnt[idx].append(ls[i][1])

for i in range(m):
    cnt[i].sort()


for i in range(m):
    idx = ls[i][0]
    print("{:06d}{:06d}".format(idx,cnt[idx].index(ls[i][1])))

Submission status: Runtime Error

Solution code:
n,m = map(int,input().split())
lis = [[] for i in range(n)]
lnum = [0]*100001
query = []

for _ in range(m):
  tp = tuple(map(int,input().split()))
  query.append(tp)
  lis[tp[0]-1].append(tp[1])
  
for i in range(n):
  lis[i].sort()

for pref in lis:
  for i,city in enumerate(pref):
    lnum[city] = i+1
  
for item in query:
  print("{:06}{:06}".format(item[0],lnum[item[1]]))

Submission status: Runtime Error

Solution code:
n,m = map(int,input().split())
lis = [[] for i in range(n)]
lnum = [0]*100001
query = []

for _ in range(m):
  tp = tuple(map(int,input().split()))
  query.append(tp)
  lis[tp[0]-1].append(tp[1])
  
for i in range(n):
  lis[i].sort()

for pref in lis:
  for i,city in enumerate(pref):
    lnum[city] = i
  
for item in query:
  print("{:06}{:06}".format(item[0],lnum[item[1]]+1))

Submission status: Runtime Error

Solution code:
from heapq import heappush
N,M = map(int, input().split())
A = {}
prefs = []
years = []
for i in range(M):
    p,y = input().split()
    prefs.append(p)
    years.append(y)
    if p not in A:
        A[p] = [y]
    else:
        heappush(A[p], y)
res = {}
for k,v in A.items():
    for i in range(len(v)):
        res[k+v[i]] = str(i+1)
for p,y in zip(prefs, years):
    print(p.zfill(6) + res[k+y].zfill(6))

Submission status: Runtime Error

Solution code:
n,m=map(int,input().split())
cities=[[] for i in range(n)]
for i in range(1,m+1):
  p,y=map(int,input().split())
  cities[p-1].append(y)
  print(format(str(p),"0>6")+format(str(len(cities[p-1],"0>6"))))

Submission status: Runtime Error

Solution code:
#include "bits/stdc++.h"

#define REP(i,num) for(int i=0;i<(num);++i)
#define ALL(c) c.begin(),c.end()
#define PRINTALL(c) for(auto& x:c){cout<<x<<' ';}cout<<endl;

using namespace std;
using ll = long long;

template<typename T=int>
T in(){T x; cin >> x; return (x);}

class Data{
public:
	int n,p,y;
	bool operator<(const Data& rhs){return y<rhs.y;}
};

int main(){
	//cin.tie(0);
	//ios::sync_with_stdio(false);

	int N=in(),M=in();
	vector<Data*> D(M);
	vector<vector<Data>> S(N);
	REP(i,M){
		Data temp;
		temp.p=in(),temp.y=in();
		S[temp.p-1].emplace_back(temp);
		D[i]=&S[temp.p-1].back();
	}
	REP(i,N){
		sort(ALL(S[i]));
		int j=0;
		for(int j=0,ej=S[i].size();j!=ej;++j){
			S[i][j].n=j;
		}
	}
	REP(i,M){
		char str[128];
		sprintf(str,"%06d%06d",D[i]->p,D[i]->n+1);
		cout << str << endl;
	}
	return 0;
}

Submission status: Runtime Error

Solution code:
n,m=map(int,input().split())
hoge=[]
huga=[[] for i in range(100000)]
for i in range(m):
  a,b=map(int,input().split())
  hoge.append([a,b])
  huga[a].append(b)
  
for i in range(100000):
  huga[i]=sorted(huga[i])
  
for i in range(m):
  kari=str(hoge[i][0])
  print(kari.zfill(6),end="")
  kari=str(1+huga[hoge[i][0]].index(hoge[i][1]))
  print(kari.zfill(6),)

Submission status: Runtime Error

Solution code:
n,m=map(int,input().split())
hoge=[]
huga=[[] for i in range(10000)]
for i in range(m):
  a,b=map(int,input().split())
  hoge.append([a,b])
  huga[a].append(b)
  
for i in range(10000):
  huga[i]=sorted(huga[i])
  
for i in range(m):
  kari=str(hoge[i][0])
  print(kari.zfill(6),end="")
  kari=str(1+huga[hoge[i][0]].index(hoge[i][1]))
  print(kari.zfill(6),)

Submission status: Runtime Error

Solution code:
N, M = map(int, input().split())
d = {}
l = [[] for i in range(M)]
for i in range(M):
    P,Y = map(str, input().split())
    P = "0" * (6-len(P)) + P
    d[P] += [int(Y)]
    l[i] = [P,int(Y)]
for i in range(M):
    tmp = str((sorted(d[l[i][0]]).index(l[i][1]))+1)
    print(l[i][0] + "0" * (6-len(tmp)) + tmp)

Submission status: Runtime Error

Solution code:
N, M = map(int, input().split())
l = [None] * M
for i in range(M):
	p, y = map(int, input().split())
	l[i] = [p, y, i]
l.sort()
ans = []
t = l[0][0]
x = 0
for i in l:
	if t == i[0]:
		x += 1
		ans.append([l[2], i[0], x])
	else:
		t = i[0]
		x = 1
		ans.append([l[2], i[0], x])
ans.sort()
for i in ans:
	p = str(i[1])
	x = str(i[2])
	print('0' * (6 - len(p)) + p + '0' * (6 - len(x)) + x)

Submission status: Runtime Error

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

n, m = list(map(int, input().rstrip().split()))
ans = [""] * m
arr = []
cnt = 1
for i in range(m):
    p, y = map(int, input().split())
    arr += [(p, y, i)]
arr = sorted(arr)

ans[arr[0][2]] = "{:06}{:06}".format(arr[0][0], cnt)
for i in range(1, m):
    if arr[i - 1][0] == arr[i][0]:
        cnt += 1
    else:
        cnt = 1
    ans[arr[i][2]] = "{:06}{:06}".format(arr[i][0], cnt)

for i in asn:
    print(i)

Submission status: Runtime Error

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

n, m = list(map(int, input().rstrip().split()))
ans = [""] * m
arr = []
cnt = 1
for i in range(m):
    p, y = map(int, input().split())
    arr += [(p, y, i)]
arr = sorted(arr)

ans[arr[0][2]] = "{:06}{:06}".format(arr[0][0], cnt)
for i in range(1, m):
    if arr[i - 1][0] == arr[i][0]:
        cnt += 1
    else:
        cnt = 1
    ans[arr[i][2]] = "{:06}{:06}".format(arr[i][0], cnt)

for i in asn:
    print(i)
print(*ans, sep="\n")

Submission status: Runtime Error

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

city = py[1][2]
num = 0

for i in py:
    if i[1] == city:
        num += 1
    else:
        num = 1
        city = i[1]
    i.append(num)

py.sort()

for i in py:
    print('{:06}{:06}'.format(i[1], i[3]))

Submission status: Runtime Error

Solution code:
n, m = map(int, input().split())
py = sorted([[i] + list(map(int, input().split())) for i in range(m)], key=lambda x:(x[1], x[2]))

city = py[1][2]
num = 0

for i in py:
    if i[1] == city:
        num += 1
    else:
        num = 1
        city = i[1]
    i.append(num)

py.sort()

for i in py:
    print('{:06}{:06}'.format(i[1], i[3]))

Submission status: Runtime Error

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

PY = sorted(PY)

keyP = -1
for P, Y in PY:
  if keyP != P:
    keyP = P
    keyNo = 1

  print("{:0>6}{:0>6}", keyP, keyNo)
  keyNo += 1

Submission status: Runtime Error

Solution code:
from sys import stdin

def main():
    n,m = [int(x) for x in stdin.readline().split()]

    pys = [(i,*map(int, x.split())) for i,x in enumerate(stdin.readlines())]
    pys.sort(key=lambda x:x[1])

    count = [0] * (n + 1)
    ans = [None] * m
    for i, p,y in pys:
        count[p] += 1
        s = '%06d' % p + '%06d' % count[p]
        ans[i] = s
    print('\n'.join(ans))
    
if __name__=='__main__':
    main()

Submission status: Runtime Error

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

n, m = map(int, input().split())
data = [[] for i in xrange(n+1)]
data2 = []

for i in xrange(m):
  p, y = map(int, input().split())
  data[p].append(y)
  data2.append((p,y))

for i in xrange(m):
  p = data2[i][0]
  y = data2[i][1]
  data[p].sort()
  index = bisect.bisect_left(data[p], y) + 1
  print(str(p).zfill(6) + str(index).zfill(6))

Submission status: Runtime Error

Solution code:
from __future__ import print_function
import numpy as np
import sys
import math,string,itertools,fractions,heapq,collections,re,array,bisect,copy,functools
import heapq
from heapq import heappush
from heapq import heappop
import random


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

n,m = map(int, input().split())
p=np.zeros(m+1,dtype=int)
y=np.zeros(m+1,dtype=int)
for i in range(1,m+1):
    p[i],y[i] = map(int, input().split())


l_pref=[[] for _ in range(n+1)]    # 県の数(==n)だけ空リストを用意
for i in range(1,m+1):
    l_pref[p[i]].append((y[i],i))
for i in range(1,n+1):
    l_pref[i].sort()

# eprint(l_pref)


lll = np.zeros(m+1,dtype=(int,int))
for i in range(1,n+1):
    for j in range(len(l_pref[i])):
        lll[l_pref[i][j][1]] = p[l_pref[i][j][0]]
# eprint(lll)

        
for i in range(1,m+1):
    # temp =  l_pref[p[i]].index((y[i],i))  + 1
    print("0"*(6-len(str(p[i])))  +  str(p[i])  +  "0"*(6-len(str(lll[i]))) + str(lll[i]) )

Submission status: Runtime Error

Solution code:
from __future__ import print_function
import numpy as np
import sys
import math,string,itertools,fractions,heapq,collections,re,array,bisect,copy,functools
import heapq
from heapq import heappush
from heapq import heappop
import random


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

n,m = map(int, input().split())
p=np.zeros(n+1,dtype=int)
y=np.zeros(m+1,dtype=int)
for i in range(1,m+1):
    p[i],y[i] = map(int, input().split())


l_pref=[[] for _ in range(n+1)]    # 県の数(==n)だけ空リストを用意
for i in range(1,m+1):
    heappush(l_pref[p[i]],(y[i],i))



for i in range(1,m+1):
    temp =  l_pref[p[i]].index((y[i],i))  + 1
    print("0"*(6-len(str(p[i])))  +  str(p[i])  +  "0"*(6-len(str(temp))) + str(temp) )

Submission status: Runtime Error

Solution code:
from __future__ import print_function
import numpy as np
import sys
import math,string,itertools,fractions,heapq,collections,re,array,bisect,copy,functools
import heapq
from heapq import heappush
from heapq import heappop
import random


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

n,m = map(int, input().split())
p=np.zeros(m+1,dtype=int)
y=np.zeros(m+1,dtype=int)
for i in range(1,m+1):
    p[i],y[i] = map(int, input().split())


l_pref=[[] for _ in range(n+1)]    # 県の数(==n)だけ空リストを用意
for i in range(1,m+1):
    heappush(l_pref[p[i]],(y[i],i))



for i in range(1,m+1):
    temp =  l_pref[p[i]].index((y[i],i))  + 1
    print("0"*(6-len(str(p[i])))  +  str(p[i])  +  "0"*(6-len(str(temp))) + str(temp) )
v

Submission status: Runtime Error

Solution code:
from __future__ import print_function
import numpy as np
import sys
import math,string,itertools,fractions,heapq,collections,re,array,bisect,copy,functools
from dataclasses import dataclass, field
from typing import Any
import heapq
from heapq import heappush
from heapq import heappop
# from Queue import PriorityQueue

# from itertools import accumulate
# from collections import deque
import random


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

n,m = map(int, input().split())
p=np.zeros(m+1,dtype=int)
y=np.zeros(m+1,dtype=int)
for i in range(1,m+1):
    p[i],y[i] = map(int, input().split())

# l=[]
# for i in range(1,n+1):
#     l.append(PriorityQueue())

# for i in range(1,n+1):
#     q.put((i,p[i]))
# eprint("=======================")
# heapl=[y[i] for i in range(1,m+1)]
# heapq.heapify(heapl)
# for i in range(1,m+1):
#     eprint(heapq.heappop(heapl))



# eprint("=======================")
l_pref=[[] for _ in range(n+1)]    # 県の数(==n)だけ空リストを用意
for i in range(1,m+1):
    heappush(l_pref[p[i]],(y[i],i))
    # eprint(l_pref[p[i]])

# eprint(l_pref)

# eprint("=======================")
# dict={}
# for ll in l_pref:
#     i=1
#     for xx in ll:
#         dict[xx]=i
#         i+=1
# print(dict)

# eprint("=======================")
# for i in range(1,n+1):
#     eprint(l_pref[i])

# heappush(heapl2,(p[i],y[i]))

# eprint("=======================")

# const = np.zeros(n+1,dtype=int)
# for i in range(1,n+1):
#     const[i] = len(l_pref[i])
#     eprint(str(const[i]) +" "+  str(l_pref[i]))



# eprint("=======================")
# for i in range(1,m+1):
#     eprint(str(p[i]) + " " + str( l_pref[p[i]].index((y[i],i))  + 1 ) )
# eprint("=======================")
for i in range(1,m+1):
    print("0"*(6-len(str(p[i])))  +  str(p[i])  +  "0"*(6-len(str( l_pref[p[i]].index((y[i],i))  + 1 ))) + str(l_pref[p[i]].index((y[i],i))  + 1) )


# eprint("=======================")


# for i in range(1,m+1):
#     eprint(str(p[i])+" "+" " + str(heappop(l_pref[p[i]])))
# eprint("=======================")

# for i in range(1,m+1):
#     print("0"*(6-len(str(p[i]))) + str(p[i]) + "0"*(6-len(str(const[p[i]] - len(l_pref[p[i]])+1))) + str( heappop( l_pref[p[i]] ) ) )



# l = []
# for i in range(1,n+1):
#     l[i] =

# i -> p[i] -> vector[i]
# vector[i] += 1
# print(p[i],vector[ p[i] ] )


# heappush(heap, 6)
# heappush(heap, 5)
# heappush(heap, 4)
# heappush(heap, 3)
# heappush(heap, 2)
# heappush(heap, 1)
# heappush(heap, 0)


# for i in range(1,n+1):


# for i in range(1,n+1):
#     dict[i] = p[i]


# 市			i 	{0,1, ...,(n-1) }
# 県			  	{0,1, ...{m-1}}
# それぞれの市の所属県	p_{i}	{p_0, p_1, p_2, ..., p_(n-1)}
# それぞれの市の設立年	y_{i}	{y_0, y_1, y_2, ..., y_{n-1}}

Submission status: Runtime Error

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

X = [0] * M
for p in set(P):
    I = [i for i in range(M) if P[i] == p]
    Y = [Y[i] for i in I]
    earliest = min(Y)
    latest = max(Y)
    i = 0
    for y in range(earliest, latest + 1):
        if y in Y:
            X[I[i]] = Y.index(y) + 1
            i += 1

for i in range(M):
    print("{:06}{:06}".format(P[i], X[i]))

Submission status: Runtime Error

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

city = [[0] * 100000 for j in range(N)]
citynum = [0] * 100000
citynum_ = [0] * 100000

for i in range(M):
    p, y = map(int, input().split())
    city[p-1][y] = i+1
    citynum[i+1] = p
    citynum_[i+1] = y

rank = [[0] * 100000 for j in range(N)]

for i in range(N):
    count = 0
    for j in range(100000):
        if city[i][j] != 0:
            count += 1
            rank[i][j] = count

citynum2 = [0] * 100000

for i in range(M):
    citynum2[citynum[i+1]] += 1
    ansp = citynum[i+1]
    ansy = rank[ansp-1][citynum_[i+1]]

    print('{:06}'.format(ansp)+'{:06}'.format(ansy))

Submission status: Runtime Error

Solution code:
#include <iostream>
#include <cmath>
#include <string>
#include <cstring>
#include <utility>
#include <vector>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#define debug(x) cerr << #x << ':' << x << endl
#define REP(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
using namespace std;
typedef long long ll;

struct info{
    int ci;
    string pref;
    string year;
    string id="";
    info(int i, string p, string y){
        ci = i;
        pref = p;
        year = y;
    }
};

bool comp1(const info &a, const info &b){
    if(a.pref==b.pref){
        return a.year < b.year;
    }
    else
        return a.pref < b.pref;
}



bool comp2(const info &a, const info &b){
    return a.ci < b.ci;
}

int main(){
    int n,m;
    cin >> n >> m;
    vector<info> A;
    REP(i,m){
        string p, y;
        cin >> p >> y;
        string s;
        REP(i,6-p.size()) s.append("0");
        s.append(p);
        A.push_back(info(i, s, y));
    }
    sort(ALL(A), comp1);
    int order=0;
    string past="aa";
    for(int i=0; i<m; i++){
        if(A[i].pref==past)
            order+=1;
        else
            order = 1;

        string s;
        REP(i,6-to_string(order).size()) s.append("0");
        s.append(to_string(order));
        A[i].id = A[i].pref + s; 
        past = A[i].pref;
    }
    sort(ALL(A), comp2);

    for(auto x : A)
        cout << x.id<< endl;
    return 0;
}

Submission status: Runtime Error

Solution code:
def mks(num):
  s=str(num)
  if len(s)<6:
    s='0'*(6-len(s))+s
  return s

n,m=map(int,input().split())
arr=[]
for i in range(m):
  p,y=map(int,input().split)
  arr.append([p,y,i])
ans=[0]*m
arr=sorted(arr,key=lambda x:x[1])
arr=sorted(arr,key=lambda x:x[0])
tmp=arr[0][0]
cnt=1
for i in range(m):
  if arr[i][0]==tmp:
    s1,s2=mks(tmp),mks(cnt)
    ans[arr[i][2]]=s1+s2
    cnt+=1
  else:
    cnt=1
    tmp=arr[i][0]
    s1,s2=mks(tmp),mks(cnt)
    ans[arr[i][2]]=s1+s2
for i in range(m):
  print(ans[i])

Submission status: Runtime Error

Solution code:
a = list(map(int, input().split()))
x = []
y = []
order = {}
city = {}
city1 = {}
ans = []
for i in range(a[1]):
    x1, y1 = [int(i) for i in input().split()]
    x.append(x1)
    y.append(y1)

for i in range(a[1]):
    order[i] = y[i]

for i in range(1, a[0]+1):
    Prefecture = []
    for j in range(a[0]+1):
        if i == x[j]:
            Prefecture.append(y[j])
    else:
        Prefecture.sort()
        city[i] = Prefecture

for k, v in city.items():
    for i in range(len(v)):
        k1 = v[i]
        v[i] = str(k).zfill(6) + str(i + 1).zfill(6)
        city1[k1] = v[i]

for k1 in order.values():
    for k, v in city1.items():
        if k1 == k:
            ans.append(v)
for i in ans:
    print(i)

Submission status: Runtime Error

Solution code:
import sys
from collections import defaultdict
from copy import deepcopy

input = sys.stdin.readline
N, M = list(map(int, input().split()))

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

sorted_PY = deepcopy(PY)
sorted_PY.sort(key=lambda x: x[1])

p_count_dict = defaultdict(lambda: 0)
y_dict = {}

for py in sorted_PY:
    p_count_dict[py[0]] += 1
    y_dict[py[1]] = p_count_dict[py[0]]

for py in PY:
    print(f'{py[0]:0>6}{y_dict[py[1]]:0>6}')

Submission status: Runtime Error

Solution code:
# coding: utf-8

N, M = map(int, input().split())
p_dict = {}
for i in range(M):
	p, y = map(int, input().split())
	if p not in p_dict.keys():
		p_dict[p] = [[y, p, i]]
    else:
		# yとp元の順番を入れとく
		p_dict[p].append([y, p, i])
ans = []
for p in p_dict.keys():
    p_dict[p].sort()
    for i in range(len(p_dict[p])):
        # 昇順で並べたときの順番を入れとく
        p_dict[p][i].append(i+1)
        ans.append(p_dict[p][i])
# ans = [y, p, input_index, sorted_index]
ans.sort(key=lambda x: x[2])
for y, p, oi, si in ans:
    print("{:06d}{:06d}".format(p, si))

Submission status: Runtime Error

Solution code:
if __name__ == "__main__":
    N, M = map(int, input().split())
    city_list = []
    for i in range(M):
        city_list.append(list(map(int, input().split())))
    pref = {}
    pref_sort = {}
    for i in range(M):
        key = city_list[i][0]
        val = city_list[i][1]
        if str(key) in pref:
            pref[str(key)].append(val)
        else:
            pref[str(key)] = [val]
    ans = {}
    for i in range(N):
        pref[str(i+1)].sort()
    for i in range(M):
        key = city_list[i][0]
        val = city_list[i][1]
        output = str(key).zfill(6) + str(pref[str(key)].index(val)+1).zfill(6)
        print(output)

Submission status: Runtime Error

Solution code:
input sys
input = sys.stdin.readline
N, M = map(int, input().split())
City = []
for i in range(M):
	c = list(map(int, input().split()))
	c.append(0)
	City.append(c)
for i in range(N):
	yrs = []
	for j in City:
		if j[0] == i + 1:
			yrs.append(j[1])
	yrs.sort()
	for j in City:
		if j[0] == i + 1:
			j[2] = yrs.index(j[1]) + 1
for i in City:
	ID = ("0" * 6 + str(i[0]))[-6:] + ("0" * 6 + str(i[2]))[-6:]
	print(ID)

Submission status: Runtime Error

Solution code:
n, m = map(int, input().split())
cs = []
ps = {}
for _ in range(m):
  p, y = map(int, input().split())
  cs.appenyd([y, p])
css = sorted(cs)
for c in css:
  if c[1] in ps:
    ps[c[1]].append(c[0])
  else:
    ps[c[1]] = [c[0]]
[print('{:06}{:06}'.format(c[1], ps[c[1]].index(c[0])+1))for c in cs]

Submission status: Runtime Error

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

for i in range(1, N + 1):
    l = [city for city in C if city[0] == i]
    l.sort(key=lambda x: x[1])
    for j in range(M):
        for k in range(len(l)):
            if C[j] == l[k]:
                C[j] = (*C[j], k + 1)

for city in C:
    p = '{:0>6}'.format(city[0])
    n = '{:0>6}'.format(city[2])
    print(p + n)

Submission status: Runtime Error

Solution code:
n,m = map(int,input().split())
p,y = [],[]
for i in range(m):
    v1,v2 = map(int,input().split())
    p.append(v1)
    y.append(v2)
    
py = zip(p,y,range(m))
py = sorted(py)
p,y,index = zip(*py)
 
ans = []
start = p[0]
count = 1
for i in range(m):
    if start == p[i]:
        ans.append(str(p[i]).zfill(6) + str(count).zfill(6))
        count += 1
    else:
        count = 1
        start = p[i]
        ans.append(str(p[i]).zfill(6) + str(count).zfill(6))
        count += 1
 
ans = zip(index,ans)
ans = sorted(ans1)
index,ans = zip(*ans)
for i in ans:
    print(i)

Submission status: Runtime Error

Solution code:
import sys

s2nn = lambda s: [int(c) for c in s.split(' ')]

ss2nn = lambda ss: [int(s) for s in list(ss)]
ss2nnn = lambda ss: [s2nn(s) for s in list(ss)]

i2s = lambda: sys.stdin.readline().rstrip()
i2n = lambda: int(i2s())
i2nn = lambda: s2nn(i2s())

ii2ss = lambda n: [sys.stdin.readline() for _ in range(n)]

def main(N, M, PYm):
    # 県番号pと市誕生年yから認識番号を得られる辞書
    # dic[p][y] -> 認識番号
    dic = {}
    # 県ごとに、市誕生年を昇順ソートし、認識番号を1,2,...と対応づける
    # dic2[p] -> [(1, sorted_y1), (2, sorted_y2), ...]
    # dic2tmp[p] -> [y1, y2, ...]
    #dic2 = {}
    dic2tmp = {}
    for p in range(N+1):
        dic[p] = {}
        #dic2[p] = []
        dic2tmp[p] = []
    for p, y in PYm:
        dic2tmp[p].append(y)
    for p in range(N+1):
        dic2tmp[p].sort()
        nby = [(i+1, y) for i, y in enumerate(dic2tmp[p])]
        #dic2[p] = nby
        for nb, y in nby:
            dic[p][y] = nb
    # 表示
    for p, y in PYm:
        nb = dic[p][y]
        print('%06d%06d' % (p, nb))
N, M = i2nn()
PYs = ss2nnn(ii2ss())
main(N, M, PYs)

Submission status: Runtime Error

Solution code:
n, m= map(int, (input().split()))
pyi = [list(map(int, (input().split()))) + [i] for i in range(m)]
pyi.sort(key=itemgetter(1))
pyi.sort(key=itemgetter(0))
cityflag = 0
ans = []
for rep in range(m):
    if pyi[rep][0] != pyi[rep - 1][0]:
        cityflag = 0

    cityflag += 1
    ans += [[pyi[rep][0] , cityflag, pyi[rep][2]]]

for i in sorted(ans, key=itemgetter(2)):
    print(str(i[0]).zfill(6) + str(i[1]).zfill(6))

Submission status: Runtime Error

Solution code:
N, M = map(int, input().split())
PM = []
for i in range(N):
  PM = input().split()
  P = PM[0] + ""
  PP = P.zfill(6)
  M = PM[1] + ""
  MM = p.zfill(6)
  print(PP + MM)

Submission status: Runtime Error

Solution code:
N,M = map(int,input().split())
PY = [list(map(int,input().split())) for _ in range(M)]
for i in range(M):
    PY[i].append(i)
PY.sort(key=lambda x:x[1])
ans = [0]*M
num = [0]*max(N,M)
for p,y,i in PY:
    ans[i] = str(p).zfill(6) + str(num[p]+1).zfill(6)
    num[p] += 1
for s in ans:print(s)

Submission status: Runtime Error

Solution code:
N,M = map(int,input().split())
PY = [list(map(int,input().split())) for _ in range(M)]
for i in range(M):
    PY[i].append(i)
PY.sort(key=lambda x:x[1])
ans = [0]*M
num = [0]*N
for p,y,i in PY:
    ans[i] = str(p).zfill(6) + str(num[p]+1).zfill(6)
    num[p] += 1
for s in ans:print(s)