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:
S = input().split(" ")
n = int(S[0])
m = int(S[1])

py = []

for i in range(n+1):
    py.append([int(s) for s in input().split(" ")])

def prepare(n, data):
    result = [0 for i in range(n)]
    dict = {}
    data = sorted(data,key=lambda x:x[1])
    for d in data:
        i = d[0] - 1
        result[i] = result[i] + 1
        dict.__setitem__(generateID(d[0], d[1]), str(d[0]).zfill(6) + str(result[i]).zfill(6))

    return dict


def generateID(start, to):
    if start < to:
        start, to = to, start

    return start * 100000 + to

dict = prepare(n, py)

for p in py:
    print(dict[generateID(p[0],p[1])])

Submission status: Runtime Error

Solution code:
#include <bits/stdc++.h>
using namespace std;

#define pb push_back
typedef long long int ll;
typedef vector<ll> vl;
typedef map<ll,ll> ii;


//main code
int main() {
    ios_base::sync_with_stdio(false);
	cin.tie(0);cout.tie(0);
    ll x,y;cin>>x>>y;
    ii m;
    vl v;
    vector<pair<ll,ll>> v0;
    map<int,string> m0;
    for(int i=0;i<y;i++){
        ll a,b;cin>>a>>b;
        v.pb(b);
        v0.pb({a,b});
    }
    sort(v0.begin(),v0.end());
    for(auto i:v0){
        ll a=i.first;ll b=i.second;
        m[a]++;
        string s,s0,s1;
        s=to_string(a);
        for(int i=0;i<(6-s.size());i++){
            s1.pb('0');
        }
        s1+=s;
        s=to_string(m[a]);
        
        for(int i=0;i<6-s.size();i++){
            s0+='0';
        }
        s0+=s;
        s=s1.insert(6,s0);
        m0[b]=s;
    }




    for(ll i:v){
        cout<<m0[i]<<"\n";
    }
    return 0;
}

Submission status: Runtime Error

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

def zero(num):
    return str(num).zfill(6)


if m == 1:
    print(zero(py[0])+zero(1))
else:
    year_py = sorted(py, key=lambda x: x[1])
    dic = {str(x): 0 for x in range(1,m+1)}

    for i in range(m):
        dic[str(year_py[i][0])] += 1
        year_py[i].append(dic[str(year_py[i][0])])
    yb_py = sorted(year_py, key=lambda x: x[2])

    for i in range(m):
        print(zero(yb_py[i][0]) + zero(yb_py[i][3]))

Submission status: Runtime Error

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

def zero(num):
    return str(num).zfill(6)


if m == 1:
    print(zero(py[0])+zero(1))
else:
    year_py = sorted(py, key=lambda x: x[1])
    dic = {x: 0 for x in range(1,m+1)}

    for i in range(m):
        dic[year_py[i][0]] += 1
        year_py[i].append(dic[year_py[i][0]])
    yb_py = sorted(year_py, key=lambda x: x[2])

    #for i in range(m):
    #    print(zero(yb_py[i][0]) + zero(yb_py[i][3]))

Submission status: Runtime Error

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

def zero(num):
    return str(num).zfill(6)


if m == 1:
    print(zero(py[0])+zero(1))
else:
    year_py = sorted(py, key=lambda x: x[1])
    dic = {x: 0 for x in range(1,m+1)}

    for i in range(m):
        dic[year_py[i][0]] += 1
        year_py[i].append(dic[year_py[i][0]])
    yb_py = sorted(year_py, key=lambda x: x[2])

    for i in range(m):
        print(zero(yb_py[i][0]) + zero(yb_py[i][3]))

Submission status: Runtime Error

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

def zero(num):
    return str(num).zfill(6)


if m == 1:
    print(zero(n)+zero(1))
else:
    year_py = sorted(py, key=lambda x: x[1])
    dic = {x: 0 for x in range(m)}

    for i in range(m):
        dic[year_py[i][0]] += 1
        year_py[i].append(dic[year_py[i][0]])
    yb_py = sorted(year_py, key=lambda x: x[2])

    for i in range(m):
        print(zero(yb_py[i][0]) + zero(yb_py[i][3]))

Submission status: Runtime Error

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

def zero(num):
    return str(num).zfill(6)


if m == 1:
    print(zero(1)+zero(1))
else:
    year_py = sorted(py, key=lambda x: x[1])
    dic = {x: 0 for x in range(m)}

    for i in range(m):
        dic[year_py[i][0]] += 1
        year_py[i].append(dic[year_py[i][0]])
    yb_py = sorted(year_py, key=lambda x: x[2])

    for i in range(m):
        print(zero(yb_py[i][0]) + zero(yb_py[i][3]))

Submission status: Runtime Error

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

def zero(num):
    return str(num).zfill(6)


if m == 1:
    print(zero(1)+zero(1))
else:
    year_py = sorted(py, key=lambda x: x[1])
    dic = {x: 1 for x in range(1,m+1)}

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

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

    for i in range(m):
        print(zero(yb_py[i][0]) + zero(yb_py[i][3]))

Submission status: Runtime Error

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

def zero(num):
    return str(num).zfill(6)


if m == 1:
    print(zero(1)+zero(1))
else:
    year_py = sorted(py, key=lambda x: x[1])
    dic = {x: 1 for x in range(1,m+1)}
    
    for i in range(m):
        year_py[i].append(dic[year_py[i][0]])
        dic[year_py[i][0]] += 1
    
    yb_py = sorted(year_py, key=lambda x: x[2])
    
    for i in range(m):
        print(zero(yb_py[i][0]) + zero(yb_py[i][3]))

Submission status: Runtime Error

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

def zero(num):
    return str(num).zfill(6)


year_py = sorted(py, key=lambda x: x[1])
dic = {x: 1 for x in range(1,m+1)}

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

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

for i in range(m):
    print(zero(yb_py[i][0]) + zero(yb_py[i][3]))

Submission status: Runtime Error

Solution code:
def zeroPadding(num):
    return "%06d"%num

class Row:
    def __init__(self, i, pref_id, year):
        self.i = i
        self.pref_id = pref_id
        self.year = year
        self.city_id = -1
        
    def __str__(self):
        return "{i: %d, pref_id: %d, year: %d, city_id: %d}"%(self.i, self.pref_id, self.year, self.city_id)
        
    def set_city_id(self, city_id):
        self.city_id = city_id
            
    def get_sort_key(self):
        return zeroPadding(self.pref_id ) + zeroPadding(self.year ) 
            
    def get_str(self):
        return zeroPadding(self.pref_id ) + zeroPadding(self.city_id)

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

row_list = []

for i in range(M):
    d = list(map(int,input().split())) 
    row_list.append(Row(i, d[0], d[1]))

row_list = sorted(row_list, key=lambda x: x.get_sort_key())

now_pref_id = -1a
cnt = 1

result = []
for i, row in enumerate(row_list):
    if row.pref_id != now_pref_id:
        now_pref_id = row.pref_id
        cnt = 1
    
    row.set_city_id(cnt)
    row_list[i] = row
    cnt += 1

[print(x.get_str()) for x in sorted(row_list, key=lambda x: x.i)]

Submission status: Runtime Error

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

row_list = []

for i in range(M):
    d = list(map(int,input().split())) 
    row_list.append(Row(i, d[0], d[1]))

def zeroPadding(num):
    return "%06d"%num

class Row:
    def __init__(self, i, pref_id, year):
        self.i = i
        self.pref_id = pref_id
        self.year = year
        self.city_id = -1
        
    def __str__(self):
        return "{i: %d, pref_id: %d, year: %d, city_id: %d}"%(self.i, self.pref_id, self.year, self.city_id)
        
    def set_city_id(self, city_id):
        self.city_id = city_id
            
    def get_sort_key(self):
        return zeroPadding(self.pref_id ) + zeroPadding(self.year ) 
            
    def get_str(self):
        return zeroPadding(self.pref_id ) + zeroPadding(self.city_id)

row_list = sorted(row_list, key=lambda x: x.get_sort_key())

now_pref_id = -1
cnt = 1

result = []
for i, row in enumerate(row_list):
    if row.pref_id != now_pref_id:
        now_pref_id = row.pref_id
        cnt = 1
    
    row.set_city_id(cnt)
    row_list[i] = row
    cnt += 1

[print(x.get_str()) for x in sorted(row_list, key=lambda x: x.i)]

Submission status: Runtime Error

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

row_list = []

for i in range(M):
    d = list(map(int,input().split())) 
    row_list.append(Row(i, d[0], d[1]))

def zeroPadding(num):
    return "%06d"%num

class Row:
    def __init__(self, i, pref_id, year):
        self.i = i
        self.pref_id = pref_id
        self.year = year
        self.city_id = -1
        
    def __str__(self):
        return "{i: %d, pref_id: %d, year: %d, city_id: %d}"%(self.i, self.pref_id, self.year, self.city_id)
        
    def set_city_id(self, city_id):
        self.city_id = city_id
            
    def get_sort_key(self):
        return zeroPadding(self.pref_id ) + zeroPadding(self.year ) 
            
    def get_str(self):
        return zeroPadding(self.pref_id ) + zeroPadding(self.city_id)

row_list = sorted(row_list, key=lambda x: x.get_sort_key())

now_pref_id = -1
cnt = 1

result = []
for i, row in enumerate(sorted_row_list):
    if row.pref_id != now_pref_id:
        now_pref_id = row.pref_id
        cnt = 1
    
    row.set_city_id(cnt)
    sorted_row_list[i] = row
    cnt += 1

[print(x.get_str()) for x in sorted(sorted_row_list, key=lambda x: x.i)]

Submission status: Runtime Error

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

def zeroPadding(num):
    return "%06d"%num

class Row:
    def __init__(self, i, pref_id, year):
        self.i = i
        self.pref_id = pref_id
        self.year = year
        self.city_id = -1
        
    def __str__(self):
        return "{i: %d, pref_id: %d, year: %d, city_id: %d}"%(self.i, self.pref_id, self.year, self.city_id)
        
    def set_city_id(self, city_id):
        self.city_id = city_id
            
    def get_sort_key(self):
        return zeroPadding(self.pref_id ) + zeroPadding(self.year ) 
            
    def get_str(self):
        return zeroPadding(self.pref_id ) + zeroPadding(self.city_id)

row_list = [Row(i, d[0], d[1]) for i,d in enumerate(P)]
del P
row_list = sorted(row_list, key=lambda x: x.get_sort_key())

now_pref_id = -1
cnt = 1

result = []
for i, row in enumerate(sorted_row_list):
    if row.pref_id != now_pref_id:
        now_pref_id = row.pref_id
        cnt = 1
    
    row.set_city_id(cnt)
    sorted_row_list[i] = row
    cnt += 1

[print(x.get_str()) for x in sorted(sorted_row_list, key=lambda x: x.i)]

Submission status: Runtime Error

Solution code:
N, M = map(int, input().split())
arr = [0 for _ in range(M)]
for i in range(M):
    p, y = map(int, input().split())
    arr[i] = [p, y, i]

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

arr[0][1] = 1
P_cnt = [1 for _ in range(10 ** 5)]
ans_list = [0] * M
for p, y, i in arr:
    ans_list[i] = [str(p).zfill(6) + str(P_cnt[p]).zfill(6), i]
    P_cnt[p] += 1

ans_list.sort(key=lambda x: x[1])
for i in range(M):
    print(ans_list[i][0])

Submission status: Runtime Error

Solution code:
n,m=map(int,input().split())
li=[]
city_counter = [1] * (m+1)
ans=[]

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

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

for i in range(len(li)):
    tmp = str(li[i][0]).zfill(6) + str(city_counter[li[i][0]]).zfill(6)
    ans.append((tmp,li[i][2]))
    city_counter[li[i][0]] += 1

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

for i in range(len(ans)):
    print(ans[i][0])

Submission status: Runtime Error

Solution code:
n,m = map(int,input().split())
py = []
li = [1] * 10**5

for i in range(m):
    p,y = map(int,input().split())
    py.append((p,y,i))

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

ans = []

for p,y,i in py:
    ans_tmp = '0' * (6 - len(str(p))) + str(p) + '0' * (6 - len(str(li[p]))) + str(li[p])
    li[p] += 1
    ans.append([ans_tmp, i])

ans.sort(key = lambda x: x[1])
for i in range(m):
    print(ans[i][0])

Submission status: Runtime Error

Solution code:
n,m = map(int,input().split())
lst = [[] for _ in range(m+1)]
lst2 = []
for i in range(m):
  p,y = map(int,input().split())
  lst[p].append(y)
  lst2.append([p,y])
for i in range(1,m+1):
  lst[i].sort()
for l in lst2:
  num = lst[l[0]].index(l[1])+1
  print("0"*(6-len(str(l[0])))+str(l[0])+"0"*(6-len(str(num)))+str(num))

Submission status: Runtime Error

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

ans=[[] for i in range(m)]
p_list=[[] for i in range(n)]

for i in range(m):
 p,y=map(int,input().split())

 ans[i]=str(p).zfill(6)
 p_list[p].append([i,y])

for pp in p_list:
 pp=sorted(pp,key=lambda x:x[1])
 num=0
 for ppp in pp:
  num+=1
  ans[ppp[0]]+=str(num).zfill(6)
 num=0

for i in ans:
 print(i)

Submission status: Runtime Error

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

ans=[[] for i in range(m)]
p_list=[[] for i in range(m)]

for i in range(m):
 p,y=map(int,input().split())

 ans[i]=str(p).zfill(6)
 p_list[p].append([i,y])

for pp in p_list:
 pp=sorted(pp,key=lambda x:x[1])
 num=0
 for ppp in pp:
  num+=1
  ans[ppp[0]]+=str(num).zfill(6)
 num=0

for i in ans:
 print(i)

Submission status: Runtime Error

Solution code:
n,m = [int(i) for i in input().split()]
a = [[]for i in range(n)]


for i in range(m):
    c,d = map(int,input().split())
    a =[c-1].append((d,i))
ans = [0]*m
for i,b in enumerate(a):
    b.sort()
    for k,(d,j) in enumerate(b):
        ans[j] = str(i+1).zfill(6)+str(k+1).zfill(6)
print(*ans,sep="\n")

Submission status: Runtime Error

Solution code:
n,m = [int(i) for i in input().split()]
a = [[]for i in range(n)]
b = []

for i in range(m):
    c,d = [int(i)for i in input().split()]
    a =[c-1].append((d,i))
ans = [None]*m
for j,b in enumerate(a):
    b.sort()
    for k,(d,i) in enumerate(b):
        ans[i] = str(j+1).zfill(6)+str(k+1).zfill(6)
print(*ans,sep="\n")

Submission status: Runtime Error

Solution code:
#include<iostream>
#include<cmath>
#include<algorithm>
#include<string>
#include<map>
#include<utility>
#include<vector>
using namespace std;
typedef long long ll;
ll deg(ll n){
    ll count = 0;
    while(n!= 0){
        n/=10;
        count++;
    }
    return count;
}

int main(){
    ll n,m;
    cin >> n >> m;
    ll y[m],p[m];
    for(int i = 0;i < m;i++) cin >> p[i] >> y[i];
    vector<pair<ll,ll> > pi(m);
    for(int i = 0;i < m;i++){
        pi[i] = make_pair(p[i],y[i]);
    }
    sort(pi.begin(), pi.end());
    map<pair<ll,ll>, ll>mp;
    int cur = 1;
    for(int i = 0;i < m;i++){
        if(i-1 >= 0)
        if(pi[i-1].first != pi[i].first){
            cur = 1;
        }
        mp[pi[i]] = cur;
        cur++;
    }

    for(int i = 0;i < m;i++){
        int id = mp[make_pair(p[i],y[i])];
        printf("%0.6lld ", p[i]);
        printf("%0.6d\n", id);
    } 

    
}

Submission status: Runtime Error

Solution code:
import numpy as np
from itertools import accumulate

N, M = map(int, input().split())
P = []
p = [0] * (N+1)
for i in range(M):
    p1, y1 = map(str, input().split())
    p[int(p1)] += 1
    P.append(int(p1+y1.rjust(10,"0")))
    
ans = np.argsort(P)
ans = np.argsort(ans)
p = list(accumulate(p))

for i in range(M):
    a = P[i] // 10 ** 6 
    print(str(a).rjust(6,"0") + str(ans[i] - p[a-1] + 1).rjust(6,"0"))

Submission status: Runtime Error

Solution code:
import numpy as np
from itertools import accumulate

N, M = map(int, input().split())
P = []
p = [0] * (N+1)
for i in range(M):
    p1, y1 = map(str, input().split())
    p[int(p1)] += 1
    P.append(int(p1+y1.rjust(6,"0")))
    
ans = np.argsort(P)
ans = np.argsort(ans)
p = list(accumulate(p))

for i in range(M):
    a = P[i] // 10 ** 6 
    print(int(str(a).rjust(6,"0") + str(ans[i] - p[a-1] + 1).rjust(6,"0")))

Submission status: Runtime Error

Solution code:
import numpy as np
from itertools import accumulate

N, M = map(int, input().split())
P = []
p = [0] * (N+1)
for i in range(M):
    p1, y1 = map(str, input().split())
    p[int(p1)] += 1
    P.append(int(p1+y1.rjust(6,"0")))
    
ans = np.argsort(P)
ans = np.argsort(ans)
p = list(accumulate(p))

for i in range(M):
    a = int(P[i]) // 10 ** 6 
    print(str(a).rjust(6,"0") + str(ans[i] - p[a-1] + 1).rjust(6,"0"))

Submission status: Runtime Error

Solution code:
import numpy as np
from itertools import accumulate

N, M = map(int, input().split())
P = []
p = [0] * (N+1)
for i in range(M):
    p1, y1 = map(str, input().split())
    p[int(p1)] += 1
    P.append(p1+y1.rjust(6,"0"))
    
ans = np.argsort(P)
ans = np.argsort(ans)
p = list(accumulate(p))

for i in range(M):
    a = int(P[i]) // 10 ** 6 
    print(str(a).rjust(6,"0") + str(ans[i] - p[a-1] + 1).rjust(6,"0"))

Submission status: Runtime Error

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

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

for i in range(N):
    PY[i].sort()

for i in range(M):
    p,y=py.pop(0)
    #print(PY[p].index(y))
    p_zero=6-len(str(p))
    y_zero=6-len(str(PY[p].index(y)))
    print("0"*p_zero + str(p) + "0"*y_zero + str(PY[p].index(y)+1))

Submission status: Runtime Error

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

dic = {}
for i in range(m):
    c,y = map(int,input().split())
    dic[y] = c
#print(dic)

dic2 = copy.deepcopy(dic)
#print(dic)
dic2 = sorted(dic2.items(),key=lambda x:x[1],reverse=True)
dic2 = sorted(dic2.items(),key=lambda x:x[0])#,reverse=True)
#print(dic2)
#[(32, 1), (12, 1), (63, 2)]

ken = dic2[0][1]
counter = 0
ans = {}

for y,k in dic2:
    if ken == k:
        counter +=1
    else:
        counter = 1
    tmp = str(k).zfill(6) + str(counter).zfill(6)
    ans[y] = tmp

for i in dic.keys():
    print(ans[i])

Submission status: Runtime Error

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

li = [[] for i in range(n+10)]
memo = [0 for i in range(m+10)]

def search(p,y):
    fst = 0
    lst = len(li[p])-1

    while(fst <= lst):
        mid = (fst+lst)//2
        if li[p][mid] == y:
            return mid

        elif li[p][mid] < y:
            fst = mid+1
        
        elif li[p][mid] > y:
            lst = mid-1


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

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

for i in range(m):
    a = memo[i][0]
    b = search(memo[i][0],memo[i][1])
    print("{:0>6}".format(a),end ="")
    print("{:0>6}".format(b+1))

Submission status: Runtime Error

Solution code:
import collections
City = collections.namedtuple("City", ("number", "pref", "year"))

n, m = [int(i) for i in input().split()]
cities = []
for i in range(m):
    pref, year = input().split()
    city = City(i, int(pref), int(year))
    cities.append(city)
id_numbers = []
cities.sort(key=lambda x: x.year)
cities.sort(key=lambda x: x.pref)
prev_pref = None
for city in cities:
    if prev_pref is None or city.pref != prev_pref:
        rank = 1
    else:
        rank += 1
    id_numbers.append((city.number, city.pref, rank))
    prev_pref = city.pref
id_numbers.sort(key=lambda x: x[0])
for i in id_numbers:
    print(f"{i[1]:0>6}{i[2]:0>6}")

Submission status: Runtime Error

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

# for i in range(M):
#     P_num,Y_num = map(int,input().split(" "))
#     P.append(P_num)
#     Y.append(Y_num)

Py = [input().split(" ") for i in range(M)]
P = [int(Py[i][0]) for i in range(len(Py))]
Y = [int(Py[i][1]) for i in range(len(Py))]

#辞書を作成
city = []

for i in range(M):
    city.append({"prefecture":P[i], "year":Y[i]})

#識別番号を作成

#県iのの市のデータのみを集める
order = []
calc_city_num = {}
for i in range(1,N+1):
    for j in range(len(city)):
        if city[j]["prefecture"] == i:
            calc_city_num.setdefault(f"{j+1}",city[j]["year"])


    #この中で創設時期が早い順に並べ替え、つまり、yearを並び替え
    order.append(sorted(calc_city_num.items(), key=lambda x:x[1]))
    calc_city_num.clear()


#県iの市の番号を作成する
for i in range(1,len(order)+1):
    for j in range(len(order[i-1])):
        result = str(str(i).zfill(6) + str(j+1).zfill(6))
        city[int(order[i-1][j][0])-1].setdefault("num",result)

for i in range(M):
    print(city[i]["num"])

Submission status: Runtime Error

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

Py = [input().split(" ") for i in range(M)]
P = [int(Py[i][0]) for i in range(len(Py))]
Y = [int(Py[i][1]) for i in range(len(Py))]

#辞書を作成
city = []

for i in range(M):
    city.append({"prefecture":P[i], "year":Y[i]})

#識別番号を作成

#県iのの市のデータのみを集める
order = []
calc_city_num = {}
for i in range(1,N+1):
    for j in range(len(city)):
        if city[j]["prefecture"] == i:
            calc_city_num.setdefault(f"{j+1}",city[j]["year"])


    #この中で創設時期が早い順に並べ替え、つまり、yearを並び替え
    order.append(sorted(calc_city_num.items(), key=lambda x:x[1]))
    calc_city_num.clear()


#県iの市の番号を作成する
for i in range(1,len(order)+1):
    for j in range(len(order[i-1])):
        result = str(str(i).zfill(6) + str(j+1).zfill(6))
        city[int(order[i-1][j][0])-1].setdefault("num",result)

for i in range(M):
    print(city[i]["num"])

Submission status: Runtime Error

Solution code:
P = []
Y = []

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

# for i in range(M):
#     P_num,Y_num = map(int,input().split(" "))
#     P.append(P_num)
#     Y.append(Y_num)

Py = [input().split(" ") for i in range(M)]
P = [int(Py[i][0]) for i in range(len(Py))]
Y = [int(Py[i][1]) for i in range(len(Py))]

#辞書を作成
city = []

for i in range(M):
    city.append({"prefecture":P[i], "year":Y[i]})

#識別番号を作成

#県iのの市のデータのみを集める
order = []
calc_city_num = {}
for i in range(1,N+1):
    for j in range(len(city)):
        if city[j]["prefecture"] == i:
            calc_city_num.setdefault(f"{j+1}",city[j]["year"])


    #この中で創設時期が早い順に並べ替え、つまり、yearを並び替え
    order.append(sorted(calc_city_num.items(), key=lambda x:x[1]))
    calc_city_num.clear()


#県iの市の番号を作成する
for i in range(1,len(order)+1):
    for j in range(len(order[i-1])):
        result = str(str(i).zfill(6) + str(j+1).zfill(6))
        city[int(order[i-1][j][0])-1].setdefault("num",result)

for i in range(M):
    print(city[i]["num"])

Submission status: Runtime Error

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

P = []
Y = []

for i in range(M):
    P_num,Y_num = map(int,input().split(" "))
    P.append(P_num)
    Y.append(Y_num)

#辞書を作成
city = []

for i in range(M):
    city.append({"prefecture":P[i], "year":Y[i]})

#識別番号を作成

#県iのの市のデータのみを集める
order = []
calc_city_num = {}
for i in range(1,N+1):
    for j in range(len(city)):
        if city[j]["prefecture"] == i:
            calc_city_num.setdefault(f"{j+1}",city[j]["year"])


    #この中で創設時期が早い順に並べ替え、つまり、yearを並び替え
    order.append(sorted(calc_city_num.items(), key=lambda x:x[1]))
    calc_city_num.clear()


#県iの市の番号を作成する
for i in range(1,len(order)+1):
    for j in range(len(order[i-1])):
        result = str(str(i).zfill(6) + str(j+1).zfill(6))
        city[int(order[i-1][j][0])-1].setdefault("num",result)

for i in range(M):
    print(city[i]["num"])

Submission status: Runtime Error

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

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

#辞書を作成
city = []

for i in range(M):
    city.append({"prefecture":P[i], "year":Y[i]})

#識別番号を作成

#県iのの市のデータのみを集める
order = []
calc_city_num = {}
for i in range(1,N+1):
    for j in range(len(city)):
        if city[j]["prefecture"] == i:
            calc_city_num.setdefault(f"{j+1}",city[j]["year"])


    #この中で創設時期が早い順に並べ替え、つまり、yearを並び替え
    order.append(sorted(calc_city_num.items(), key=lambda x:x[1]))
    calc_city_num.clear()


#県iの市の番号を作成する
for i in range(1,len(order)+1):
    for j in range(len(order[i-1])):
        result = str(str(i).zfill(6) + str(j+1).zfill(6))
        city[int(order[i-1][j][0])-1].setdefault("num",result)

for i in range(M):
    print(city[i]["num"])

Submission status: Runtime Error

Solution code:
N, M = map(int, input().split())
cy = [1] * M
city = []

for i in range(M):
  p, y = map(int, input().split())
  city.append((y, p, i))
city.sort()

ans = [""] * M

for y, p, i in city:
  ans[i] = ("000000" + str(p))[-6:] + ("000000" + str(cy[p-1]))[-6:]
  cy[p-1] += 1

print(*ans, sep="\n")

Submission status: Runtime Error

Solution code:
n,m=map(int,input().split())
P=[[] for _ in range(n+1)]
for i in range(m):
    p,y=map(int,input().split())
    P[p].append([y,i+1])
ans=[]
for j in range(m):
    if P[j]:
        P[j].sort()
        for i in range(len(P[j])):
            #print(P[j])
            ans.append([P[j][i][1],str((j*10**6+i+1)).zfill(12)])
ans.sort()
for i in range(m):
    print(ans[i][1])

Submission status: Runtime Error

Solution code:
n,m = map(int,input().split())
a = []
b = []
for i in range(n):
    P,Y = map(int,input().split())
    a.append(P)
    b.append(Y)
#ここまで情報のインプット

#基本方針はまだ扱っていない最小のお金を持つ栄養ドリンクをとっていく。
#つまりは値がちいさいものから順に在庫が切れるまで選択するということ。

count = 0
ans = 0
i = 0
A = sorted(a)
while True:
    if m-b[a.index(A[i])] > 0:
        m -= b[a.index(A[i])]
        ans += A[i] * b[a.index(A[i])]
    else:
        ans += A[i]* m
        break
    i+=1
print(ans)

Submission status: Runtime Error

Solution code:
N,M = map(int,input().split())
A = [[] for i in range(N+1)]
B = []
d = {}
for i in range(M):
    p,y = map(int,input().split())
    B.append((p,y))
    A[p].append(y)
for i in range(N+1):
    A[i].sorted
    n = len(A[i])
    for j in range(n):
        d[A[i][j]] = j+1
for i in range(M):
    p,y = B[i]
    q = d[y]
    m = 6 - len(str(p))
    n = 6 - len(str(q))
    ans = "0"*m + str(p) + "0"*m + str(q)
    print(ans)

Submission status: Runtime Error

Solution code:
N,M = map(int,input().split())
A = [[] for i in range(N+1)]
B = []
d = {}
for i in range(M):
    p,y = map(int,input().split())
    B.append((p,y))
    A[p].append(y)
for i in range(N+1):
    A[i].sorted
    n = len(A[i])
    for j in range(n):
        d[A[i][j]] = j+1
for i in range(M):
    p,y = B[i]
    q = d[y]
    m = 6 - len(str(p))
    n = 6 - len(str(q))
    ans = "0"*m + str(p) + "0"*m + str(q)

Submission status: Runtime Error

Solution code:
import bisect
N, M = (int(i) for i in input().split()) 
PY = [[int(i) for i in input().split()] for i in range(M)] 
d = {}

for i in range(M):
  p, y = [int(i) for i in input().split()]
  if p not in d:
    d[p] = [y]
  else:
    #d[p] = (d[p] + [y])
    index = bisect.bisect_left(d[p], y)
    d[p].insert(index, y)

 #for x in d:
 # d[x].sort()

for p, y in PY:
  print('{}{}'.format(str(p).zfill(6), str(d[p].index(y) + 1).zfill(6)))9

Submission status: Runtime Error

Solution code:
n, m = map(int, input().split())
queue = []
for i in range(m):
    c, y= map(int, input().split())
    queue.append([c, y, i])

queue = sorted(queue)

index = 0
keep = 1
for i in range(m):
    if keep != queue[1][0]:
        index = 0
    index += 1
    queue[i][0] = str(queue[i][0]).zfill(6)
    queue[i][1] = str(index).zfill(6)

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

for data in queue:
    cn, yn, i = data
    print(cn + yn)

Submission status: Runtime Error

Solution code:
n,m=map(int,input().split())
alis=[]
for i in range(m):
	a=list(map(int,input().split()))
	a.append(i+1)
	alis.append(a)
alis.sort(key=lambda List:(List[0],List[1],List[2]))
for i in range(1,n+1):
	counter=0
	for j in range(m):
		if alis[j][0]==i:
			counter+=1
			alis[j][1]=counter
for i in range(m):
	for j in range(n):
		while len(str(alis[i][j])) <6 :
			alis[i][j]="0"+str(alis[i][j])
for i in range(0,m+1):
	for j in range(m):
		if alis[j][2]==i:
			print(*alis[j][:2],sep="")

Submission status: Runtime Error

Solution code:
from operator import itemgetter
N , M = map(int, input().split(' '))

city = []
for i in range(M):
    lscity = list(map(int, input().split(' ')))
    city.append([*lscity, i])

city_y = sorted(city, key = itemgetter(1))
city_num = [0 for _ in range(N+1)]
city_ID = {}

for i in range(M):
    city_num[city_y[i][0]] += 1
    city_ID[city_y[i][2]] = ("{:0=6}{:0=6}".format(city_y[i][0], city_num[city_y[i][0]]))

for i, j in sorted(city_ID.items()):
    print(j)

Submission status: Runtime Error

Solution code:
from operator import itemgetter
N , M = map(int, input().split(' '))

city = []
for i in range(M):
    lscity = list(map(int, input().split(' ')))
    city.append([*lscity, i])

city_y = sorted(city, key = itemgetter(1))
city_num = [0 for _ in range(N+1)]
city_ID = {}

for i in range(M):
    city_num[city_y[i][0]] += 1
    city_ID[city_y[i][2]] = ("{:06d}{:06d}".format(city_y[i][0], city_num[city_y[i][0]]))

for i, j in sorted(city_ID.items()):
    print(j)

Submission status: Runtime Error

Solution code:
from operator import itemgetter
N , M = map(int, input().split(' '))

city = []
for i in range(M):
    lscity = list(map(int, input().split(' ')))
    city.append([*lscity, i])

city_y = sorted(city, key = itemgetter(1))
city_num = [0 for _ in range(N+1)]
city_ID = {}

for i in range(M):
    city_num[city[i][0]] += 1
    city_ID[city_y[i][2]] = ("{:06d}{:06d}".format(city_num[city[i][0]], city[i][0]))

for i, j in sorted(city_ID.items()):
    print(j)

Submission status: Runtime Error

Solution code:
import sys
from operator import itemgetter

def main():
    input = sys.stdin.readline
    n, m = map(int, input().split())

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

    sorted_p_y = p_y.sort(key=itemgetter(0, 1))

    for row in p_y:
        count = 0
        for sorted_row in sorted_p_y:
            if row[0] == sorted_row[0]:
                count += 1

            if row[0] == sorted_row[0] and row[1] == sorted_row[1]:
                print(str(row[0]).zfill(6), str(count).zfill(6), sep="")
                break


if __name__ == '__main__':
    main()