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())
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]*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:
import sys
readline = sys.stdin.readline
write = sys.stdout.write

N, M = map(int,input().split())
cities = []
for i in range(M):
    p, y = map(int,readline().split())
    temp = [p, y, i]
    cities.append(temp)
id = [1 for i in range(M)]
sortedcities = sorted(cities, key=lambda x:x[1])
for i in range(M):
    sortedcities[i].append(id[sortedcities[i][0]-1])
    id[sortedcities[i][0]-1] += 1
originalcities = sorted(sortedcities, key=lambda x:x[2])
for i in range(M):
    write(str(originalcities[i][0]).zfill(6) + str(originalcities[i][3]).zfill(6) + "\n")

Submission status: Runtime Error

Solution code:
N,M = map(int,input().split())
lis  = [list(map(int,input().split())) for _ in range(M)]
ans_lis = [0] * M
lis_sort = sorted(lis)
i = 1
flag = 0
for _ in range(len(lis_sort)):
    if flag != lis_sort[_][0]:
        flag = lis_sort[_][0]
        i = 1
    ans_lis[lis.index(lis_sort[_])] = str(i)
    i += 1
for x,y in zip(lis,ans_beh_lis):
    print('0'*(6-len(str(x[0]))),x[0],'0'*(6-len(y)),y,sep='')

Submission status: Runtime Error

Solution code:
N, M = map(int, input().split())
p = [list(map(int, input().split())) + [i] for i in range(M)]
p.sort()
i = 0
for n in range(1, N + 1):
    count = 1
    while not(i > n or p[i][0] != n):
        p[i] += [str(n).zfill(6) + str(count).zfill(6)]
        i += 1
        count += 1
p.sort(key=lambda x: x[2])
for a in p:
    print(a[3])

Submission status: Runtime Error

Solution code:
N, M = map(int, input().split())
p = [list(map(int, input().split())) + [i] for i in range(M)]
p.sort()
print(p)
i = 0
for n in range(1, N + 1):
    count = 1
    print(i, p[2][0])
    while not(i > n or p[i][0] != n):
        p[i] += [str(n).zfill(6) + str(count).zfill(6)]
        i += 1
        count += 1
p.sort(key=lambda x: x[2])
for a in p:
    print(a[3])

Submission status: Runtime Error

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

counts = defaultdict(int)
numbers = {}

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

sorted_cities = sorted(cities, key=lambda x: x[2])
for city in sorted_cities:
    i, p, y = city
    counts[p] += 1
    numbers[i] = '{:06}{:06}'.format(p, counts[p])

for city in cities:
    print(numbers[city[0]])

Submission status: Runtime Error

Solution code:
#nm=list(map(int,input().split()))
#n=nm[0]
#m=nm[1]
n,m=map(int,input().split())
#py=[]
y=[]
#py=[[[]]*m]
py=[[]]*m
#y=[[]]*n
#print(py)
#for i in range(m):
#    py.append([])
for i in range (n):
    y.append([])
for i in range(m):
    py[i]=list(map(int,input().split()))
    y[py[i][0]-1].append(py[i][1])#yの初期化を＊でするとyの要素全てにappendされてしまう
for i in range(n):
    y[i].sort()
#print(py)
#print(y)
d_y={}
for i in range(m):
    for j in range(len(y[i])):
        d_y[y[i][j]]=j+1
for i in range(m):
    if py[i][0]<10:
        print("00000"+str(py[i][0]*10**6+d_y[py[i][1]]))
    elif  py[i][0]<100:
        print("0000"+str(py[i][0]*10**6+d_y[py[i][1]]))
    elif py[i][0]<1000:
        print("000"+str(py[i][0]*10**6+d_y[py[i][1]]))
    elif py[i][0]<10000:
        print("00"+str(py[i][0]*10**6+d_y[py[i][1]]))
    elif py[i][0]<100000:
        print("0"+str(py[i][0]*10**6+d_y[py[i][1]]))
    else:
        print(str(py[i][0]*10**6+d_y[py[i][1]]))

Submission status: Runtime Error

Solution code:
import sys
import bisect
n,m=map(int,input().split())
l=[[int(i) for i in l.split()] for l in sys.stdin]
s=[[0] for i in range(10**5+1)]
for i in l:
  s[i[0]].append(i[1])
for i in range(len(s)):
  s[i].sort()
for i in l:
  print('{:06}{:06}'.format(i[0],bisect.bisect_left(s[i[0]],i[1]))

Submission status: Runtime Error

Solution code:
import sys
n,m=map(int,input().split())
l=[[int(i) for i in l.split()] for l in sys.stdin]
s=[[0]*(10**5+1)]
for i in l:
  if s[i[0]].append(i[1])
for i in range(len(s)):
  s[i].sort()
for i in l:
  print('{:0>6}{:0>6}'.format(str(i[0]),str(s[i[0]].index(i[1]))))

Submission status: Runtime Error

Solution code:
#include <iostream>
#include <vector>
#include <algorithm>
#define rep(i, n) for(int i = 0; i < n; ++i)
using namespace std;

int main() {
    int N, M; cin >> N >> M;
    int P[10100];
    long long Y[10100];
    rep(i, M) cin >> P[i] >> Y[i];

    vector<vector<int>> PY(N+1);
    rep(i, M) PY[P[i]].push_back(Y[i]);

    rep(i, N) sort(PY[i].begin(), PY[i].end());
    rep(i, M) printf("%06d%06d\n", P[i], lower_bound(PY[P[i]].begin(), PY[P[i]].end(), Y[i])-PY[P[i]].begin() + 1);
}

Submission status: Runtime Error

Solution code:
N, M = map(int,input().split())
P_Y_list = np.array([input().split() for _ in range(0, M)], dtype='int')
years = [np.sort(P_Y_list[np.where(P_Y_list[:,0]==i)][:,1]) for i in set(P_Y_list[:, 0])]
for l in P_Y_list:
    left = str(l[0]).zfill(6)
    right = str(np.where(years[list(set(P_Y_list[:,0])).index(l[0])]==l[1])[0][0]+1).zfill(6)
    print(left+right)

Submission status: Runtime Error

Solution code:
n,m = map(int,input().split())
l = [tuple(map(int,input().split())) for _ in range(m)]
d = [list() for _ in range(n)]
for x in l:
  d[x[0]-1].append(x[1])
for r in d:
  r.sort()
for x in l:
  p = x[0]
  y = d[x[0]-1].index(x[1]) + 1
  print("{:06}{:06}".format(p,y)

Submission status: Runtime Error

Solution code:
debug = 0
"""
N: state num
M: city num
"""


if debug:
    N = 2
    m = 10
else:
    (N, M) = list(map(int, input().split()))

if debug:
    p_y_list = [
        [1, 30]
        ,[1, 20]
        ,[1, 10]
        ,[1, 3]
        ,[2, 63]
        ,[2, 33]
        ,[2, 23]
        ,[3, 21]
        ,[3, 7]
    ]

city_id_list = []
# for z in range(M):
for (P, Y) in p_y_list:
    
    if not debug:
        (P, Y) = list(map(int, input().split()))

    city_id_list.append([Y, P])
    
city_id_list = sorted( city_id_list, key= lambda x: x[0])

state_cnt = {}
tmp_list = []
for (Y, P) in city_id_list:
    
    if P not in state_cnt.keys():
        state_cnt[P] = 1
    elif P in state_cnt.keys():
        state_cnt[P] += 1
        
    tmp_id = str(P).zfill(6) + str(state_cnt[P]).zfill(6)
    
    tmp_list.append([state_cnt[P], tmp_id])
    
for cid in sorted(tmp_list, key=lambda x: x[0]):
    print(cid[1])

Submission status: Runtime Error

Solution code:
"""
N: state num
M: city num
"""

state_cnt = {}
city_id_dict = {}

(N, M) = list(map(int, input().split()))
# N = 3
# m = 3

for z in range(M):
# p_y_list = [
#     [1, np.random.randint(100)]
#     ,[3, np.random.randint(100)]
#     ,[2, np.random.randint(100)]
#     ,[2, np.random.randint(100)]
#     ,[1, np.random.randint(100)]
#     ,[2, np.random.randint(100)]
    
# ]
# for (P, Y) in p_y_list:
    (P, Y) = list(map(int, input().spilt()))

    if P not in state_cnt.keys():
        state_cnt[P] = 1
    elif P in state_cnt.keys():
        state_cnt[P] += 1
        
    state_num = str(P).zfill(6)
    city_num = str(state_cnt[P]).zfill(6)
    tmp_id = state_num + city_num
    city_id_dict[Y] = tmp_id
    
# get_state = set(map(int, state_cnt.keys()))
# all_state = set(range(1, N+1, 1))
# remain = set(all_state) - set(get_state)
# for num in ramain:
#     tmp_id = str(num).zfill(6) + "0"*6
#     city_id_list.append(tmp_id)
    
for _, city_id in sorted(city_id_dict.items()):
    print(city_id)

Submission status: Runtime Error

Solution code:
"""
N: state num
M: city num
"""

state_cnt = {}
city_id_dict = {}

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

for z in range(M):
    (P, Y) = list(map(int, input().spilt()))

    if P not in state_cnt.keys():
        state_cnt[P] = 1
    elif P in state_cnt.keys():
        state_cnt[P] += 1
        
    state_num = str(P).zfill(6)
    city_num = str(Y).zfill(6)
    tmp_id = state_num + city_num
    city_id_dict[Y] = tmp_id
    
# get_state = set(map(int, state_cnt.keys()))
# all_state = set(range(1, N+1, 1))
# remain = set(all_state) - set(get_state)
# for num in ramain:
#     tmp_id = str(num).zfill(6) + "0"*6
#     city_id_list.append(tmp_id)
    
[print(city_id) for _, city_id in sorted(city_id_dict.items())]

Submission status: Runtime Error

Solution code:
state_cnt = {}
city_id_dict = {}

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

for z in range(M):
    (P, Y) = list(map(int, input().spilt()))
    city_num_list.append(Y)

    if P not in state_cnt.keys():
        state_cnt[P] = 1
    elif P in state_cnt.keys():
        state_cnt[P] += 1
        
    state_num = str(P).zfill(6)
    city_num = str(state_cnt[P]).zfill(6)
    tmp_id = state_num + city_num
    city_id_dict[Y] = tmp_id
    
# get_state = set(map(int, state_cnt.keys()))
# all_state = set(range(1, N+1, 1))
# remain = set(all_state) - set(get_state)
# for num in ramain:
#     tmp_id = str(num).zfill(6) + "0"*6
#     city_id_list.append(tmp_id)
    
[print(city_id) for _, city_id in sorted(city_id_dict.items())]

Submission status: Runtime Error

Solution code:
n,m = map(int, input().split())
a = [list(map(int, input().split())) for i in range(m)]
c = [0]*n
for i in a:
  p,y = i[0],i[1]
  c[p-1] += 1
  num = c[p-1]
  print("0"*(6-len(p))+"0"*(6-len(num))+num)

Submission status: Runtime Error

Solution code:
N, M = map(int, input().split())
p = []
y = []
for i in range(M):
    p1,y1=[int(i) for i in input().split()]
    p.append(p1)
    y.append(y1)
for idx in range(M):
    ans[idx] = [idx, p[idx], y[idx]]
ans = sorted(ans, key=lambda x: x[1])
ans = sorted(ans, key=lambda x: x[2])
for idx in range(M):
    if idx == 0:
        ans[idx][2] = 1
    else:
        if ans[idx][1] == ans[idx-1][1]:
            ans[idx][2] = ans[idx-1][2] + 1
        else:
            ans[idx][2] = 1
ans = sorted(ans, key=lambda x: x[0])
for idx in range(M):
    print('{:0=6}{:0=6}'.format(ans[idx][1], ans[idx][2]))

Submission status: Runtime Error

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

N = int(input())
A = [int(input()) for _ in range(N)]

n, m = map(int, input().split())

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

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

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

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

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

Submission status: Runtime Error

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

cities = [[i, city[0], city[1]] for i, city in enumerate(cities)]
city_count = [0]*(M+1)
cities.sort(key=lambda x: x[2])
ids = []
for city in cities:
    city_count[city[1]] += 1
    ids.append([city[0], '{:0>6}{:0>6}'.format(city[1], city_count[city[1]])])
ids.sort(key=lambda x: x[0])
for city in ids:
    print(city[1])

Submission status: Runtime Error

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

cities = [[city[0], city[1], i] for i, city in enumerate(cities)]
city_count = [0]*(M+1)
cities.sort(key=lambda x: x[1])
ids = []
for city in cities:
    city_count[city[0]] += 1
    ids.append(['{:0>6}{:0>6}'.format(city[0], city_count[city[0]]), city[2]])
ids.sort(key=lambda x: x[1])
for city in ids:
    print(city[0])

Submission status: Runtime Error

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

cities = [[*city, i] for i, city in enumerate(cities)]
city_count = [0]*(M+1)
cities.sort(key=lambda x: x[1])
ids = []
for city in cities:
    city_count[city[0]] += 1
    ids.append(['{:0>6}{:0>6}'.format(city[0], city_count[city[0]]), city[2]])
ids.sort(key=lambda x: x[1])
for city in ids:
    print(city[0])

Submission status: Runtime Error

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

cities = [[*city, i] for i, city in enumerate(cities)]
city_count = [0]*(N+1)
cities.sort(key=lambda x: x[1])
ids = []
for city in cities:
    city_count[city[0]] += 1
    ids.append(['{:0>6}{:0>6}'.format(city[0], city_count[city[0]]), city[2]])
ids.sort(key=lambda x: x[1])
for city in ids:
    print(city[0])

Submission status: Runtime Error

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

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

def fill(t):
    s = str(t)
    while len(s) < 6:
        s = "0" + s
    return s

Pi.sort(key=lambda x: x[1])
counts = [1] * (M + 1)
for p in Pi:
    city = p[0]
    num = counts[city]
    counts[city] += 1
    p.append(fill(city) + fill(num))

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

Submission status: Runtime Error

Solution code:
n,m=map(int,input().split())
a=[[] for _ in range(n)]
ans=[None]*n

for i in range(m):
  p,y=map(int,input().split())
  a.append((y,i))
  
for i,b in enumerate(a):
  b.sort()
  for j,(y,k) in b:
    ans[k]='%06d%06d' % (i+1,j+1)
    
print(*ans,sep='\n')

Submission status: Runtime Error

Solution code:
N,M = map(int,input().split())
P=[map(int,input().split()) for _ in range(M)]
d = {}
for p,y in P:
  if p not in d:
    d[p]=[]
  d[p].append(y)
sd = {k:dict(zip(sorted(v),range(1,1+len(v))))
      for k,v in d.items()}
for p,y in P:
  print('%06d%06d' % (p, sd[p][y]))

Submission status: Runtime Error

Solution code:
from collections import defaultdict
from bisect import bisect_left
N, M = map(int, input().split())
A = []
B = defaultdict(list)
 
for i in range(M):
    p, y = map(int, input().split())
    A.append([p, y])
    B[p].append(y)
 
for key in B.keys():
    B[key].sort()

print(A,B)
for a in A:
    print(a[0],a[1],B[a[0]],bisect_left(B[a[0]],a[1]))
for a in A:
    print("%06d%06d" % (a[0], bisect_left(B[a[0]], a[1])+1))

Submission status: Runtime Error

Solution code:
N, M = map(int, input().split())
P, Y = zip(*(map(int, input().split()) for _ in range(M)))
ans = ['' for _ in range(M)]
c = [1 for _ in range(N + 1)]
for i, t in sorted(enumerate(zip(P, Y)), key=lambda t: t[1][1]):
    ans[i] = f'{t[0]:06}{c[t[0]]:06}'
    c[t[0]] += 1
print('\n'.join(ans))

Submission status: Runtime Error

Solution code:
2 3
2 55
2 77
2 99

Submission status: Runtime Error

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

rets = [""]*M
for i,P in enumerate(Ps):
    inds = np.array(P)[:,0]
    years = np.array(P)[:,1]
    sorts = np.argsort(years)
    for (j,y,s) in zip(inds,years,sorts):
        rets[j] = "{:06d}{:06d}".format(i+1,s+1)
for ret in rets:
    print(ret)

Submission status: Runtime Error

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


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


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


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

#  N = 10**5
#  M = 10**5
#  P, Y = [], []
#  for i in range(M):
#      P.append(10)
#      Y.append(i*100)

city_records = [[]for i in range(10**5)]
for p, y in zip(P, Y):
    #  print('p,y', p, y)
    #  print('city_records[p]', city_records[p])
    city_records[p].append(y)

#  print(city_records)

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

#  print(city_records)

for p, y in zip(P, Y):
    #  order = (city_records[p].index(y)) + 1
    order = bisect.bisect_left(city_records[p], y) + 1
    print(str(p).zfill(6) + str(order).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)]
x=collections.defaultdict(list)
for city,year in PY:
    x[city]+=[year]
for city,year in PY:
    num=bisect.bisect(x[city],year)
    print("%06d%06d"%(city,num))

Submission status: Runtime Error

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


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


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


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

#  N = 10**5
#  M = 10**5
#  P, Y = [], []
#  for i in range(M):
#      P.append(10)
#      Y.append(i*100)

city_records = [[]for i in range(10**5)]
for p, y in zip(P, Y):
    #  print('p,y', p, y)
    #  print('city_records[p]', city_records[p])
    city_records[p].append([p, y])

#  print(city_records)

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

#  print(city_records)

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

Submission status: Runtime Error

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

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

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

    input_order.append([P, Y])

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

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

Submission status: Runtime Error

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

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

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

    input_order.append([P, Y])

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

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

Submission status: Runtime Error

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

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

Submission status: Runtime Error

Solution code:
import numpy as np


n, m = map(int, input().split())
py = [list(map(int, input().split())) for _ in range(m)]
p = [[] for _ in range(n)]
start = time.time()
for _p, _y in py:
    p[_p - 1].append(_y)
for i in range(n):
    p[i] = np.argsort(np.argsort(p[i]))

counter = [0 for _ in range(n)]
for _p, _y in py:
    t = "{:06}{:06}".format(_p, p[_p - 1][counter[_p - 1]] + 1)
    print(t)
    counter[_p - 1] += 1

Submission status: Runtime Error

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

citys.sort(key = lambda x:x[1])
nums = [0]*(N+1)
states = [None]*(N+1)

for p,y,i in citys:
    nums[p] += 1
    states[i] = [str(p), str(nums[p])]

for s in states:
    print(s[0].zfill(6)+s[1].zfill(6))

Submission status: Runtime Error

Solution code:
import numpy as np


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


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

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

Submission status: Runtime Error

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

class ID:
    def __init__(self,p,y,i):
        self.p = p
        self.y = y
        self.i = i
        self.IDed = False
        self.ID1 = None
        self.ID2 = None

    def ID(self):
        for i in range(1,6):
            if self.ID1 < 10**i:
                self.ID1 = "0"*(6-i) + str(self.ID1)
                break
        for i in range(1,6):
            if int(self.ID2) < 10**i:
                self.ID2 = "0"*(6-i) + str(self.ID2)
                break
        
        return self.ID1 + self.ID2

cities = []
for i in range(0,M):
    P,Y = map(int,input().split())
    cities.append(ID(P,Y,i))
cities.sort(key = lambda x: x.y)
counter = [-1]

for i in range(0,N):
    counter.append(1)

for c in cities:
    c.ID1 = c.p
    c.ID2 = counter[c.p]
    counter[c.p] = counter[c.p] + 1

cities.sort(key = lambda x: x.i)

for i in range(0,M):
    print(cities[i].ID())

Submission status: Runtime Error

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

class ID:
    def __init__(self,p,y,i):
        self.p = p
        self.y = y
        self.i = i
        self.IDed = False
        self.ID1 = None
        self.ID2 = None

    def ID(self):
        for i in range(1,6):
            if self.ID1 < 10**i:
                self.ID1 = "0"*(6-i) + str(self.ID1)
                break
        for i in range(1,6):
            if int(self.ID2) < 10**i:
                self.ID2 = "0"*(6-i) + str(self.ID2)
                break
        
        return self.ID1 + self.ID2

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

for p in range(N+1,1,-1):
    pref = []
    for i in range(0,M):
        if not cities[i].IDed:
            if cities[i].p == p:
                pref.append([cities[i].y, cities[i].i])
                cities[i].IDed = True
    pref.sort()
    count = 1
    for i,j in pref:
        cities[j].ID2 = count
        count = count + 1
        cities[j].ID1 = p

for i in range(0,M):
    print(cities[i].ID())

Submission status: Runtime Error

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

class ID:
    def __init__(self,p,y,i):
        self.p = p
        self.y = y
        self.i = i
        self.IDed = False
        self.ID1 = None
        self.ID2 = None

    def ID(self):
        for i in range(1,6):
            if self.ID1 < 10**i:
                self.ID1 = "0"*(6-i) + str(self.ID1)
                break
        for i in range(1,6):
            if int(self.ID2) < 10**i:
                self.ID2 = "0"*(6-i) + str(self.ID2)
                break
        
        return self.ID1 + self.ID2

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

for p in range(1,N+1):
    pref = []
    for i in range(0,M):
        if not cities[i].IDed:
            if cities[i].p == p:
                pref.append([cities[i].y, cities[i].i])
                cities[i].IDed = True
    pref.sort()
    count = 1
    for i,j in pref:
        cities[j].ID2 = count
        count = count + 1
        cities[j].ID1 = p

for i in range(0,M):
    print(cities[i].ID())

Submission status: Runtime Error

Solution code:
n, m = map(int, input().split())
A = [list(input().split()) for i in range(m)]
for i in range(len(A)):
    A[i].append(i)
A.sort(key=lambda x:x[1])
B=[0 for i in range(n)]
for i in range(len(A)):
    for j in range(1,m+1):
        if(int(A[i][0])==j):
            j-=1
            B[j]+=1
            A[i].append(A[i][0].zfill(6)+str(B[j]).zfill(6))
A.sort(key=lambda x:x[2])
for a in A:
    print(a[3])

Submission status: Runtime Error

Solution code:
N, M = map(int, input().split())
PYI = []
for i in range(M):
  pi, yi = map(int, input().split())
  PYI.append("{:06}{:06}{:06}".format(pi, yi, i))
  
ID = ["" for i in range(M)]
PYI.sort()
count = 0
for i in range(M):
  y = int(PYI[i][6 : 12])
  if i == 0 or PYI[i][0 : 6] != PYI[i - 1][0 : 6]:
    count = 1
  else:
    count += 1
  ID[int(PYI[i][12 :])] = "{}{:06}".format(PYI[i][0 : 6], count)

for i in range(M):
  print(ID[i])

Submission status: Runtime Error

Solution code:
N, M = map(int, input().split())
PYI = []
for i in range(M):
  pi, yi = map(int, input().split())
  PYI.append("{:06}{:06}{:06}".format(pi, yi, i))
ID = ["" for i in range(M)]
PYI.sort()
count = 0
for i in range(M):
  y = int(PYI[i][6 : 12])
  if i == 0 or PYI[i][0 : 6] != PYI[i - 1][0 : 6]:
    count = 1
  else:
    count += 1
  ID[int(PYI[i][12 :])] = "{}{:06}".format(PYI[i][0 : 6], count)
for i in range(M):
  print(ID[i])

Submission status: Runtime Error

Solution code:

n, m = map(int, input().split())

l = [0 for i in range(n)]

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

def out(l, cnt):
    
    if any([True for i in l if i > 0]): 
        [print('{ken:06}{shi:06}'.format(ken=i+1, shi=l[i])) for i in range(len(l)) if l[i] > 0]
        return out([i - 1 for i in l], cnt+1)
    else:
        return

out(l, 1)

Submission status: Runtime Error

Solution code:

n, m = map(int, input().split())

l = [0 for i in range(n)]

for i in range(m):
    p, y = map(int, input().split())
    #print('p:{} y:{} i:{}'.format(p, y, i))
    l[ p - 1 ] += 1

shi = 1
def out(l, cnt):
    
    if any([True for i in l if i > 0]):
        global shi
        
        for i in range(len(l)):
            if l[i] > 0:
                print('{ken:06}{shi:06}'.format(ken=i+1, shi=shi)) 
                
        shi+=1
        return out([i - 1 for i in l], cnt+1)
    else:
        return

out(l, 1)

Submission status: Runtime Error

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

for i in range(M):
  C, Y = map(int, input().split(' '))
  cities.append((C, Y, i))
  
cities = sorted(cities, key=lambda x: x[1])

for c in cities:
  pref_index[c[0]] = pref_index.get(c[0], 1) + 1
  c.append(pref_index[c[0]])
  
cities = sorted(cities, key = lambda x:x[2])

for c in cities:
  print("%06d%06d" % (c[0], c[3]))

Submission status: Runtime Error

Solution code:
from collections import defaultdict

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

city = []

for i in range(M):
    P, Y = map(int, input().split())
    city.append([i, P, Y])
city.sort(key=lambda x: x[2])

count = defaultdict(lambda: 0)
for c in city:
    count[c[P]] += 1
    c.append(count[c[P]])
city.sort(key=lambda x: x[0])

for _, P, _, n in city:
    print(format(P, '06') + format(n, '06'))

Submission status: Runtime Error

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

PY_sort = sorted(PY)

tmp = dict()

before = 0
for py in PY_sort:
    if before != py[0]:
        count = 0
    count += 1
    tmp[py] = count

for py in PY:
    print("{:06}{:06}".format(tmp[py][0],tmp[py][1]))

Submission status: Runtime Error

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

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

Order = [None]*M

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

Submission status: Runtime Error

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

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

Order = [None]*M

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

Submission status: Runtime Error

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

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

Order = [None]*M

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

Submission status: Runtime Error

Solution code:
a,b=map(int,input().split())
L=[[] for i in range(a)]
u=0
# i番目の県の情報（[i，年，入力順]）をLのi番目に入れる
for i in range(b):
    u+=1
    c=list(map(int,input().split()))
    c.append(u)
    L[int(c[0])-1].append(c)
# Lの要素を年でソート
for i in L:
    i.sort(key=lambda x:x[1])
#　ソートしたので、要素ごとに何番目にできたかを末尾に付け加えておく
for i in L:
    e=0
    for j in i:
        e+=1
        j.append(e)
q=[]
for w in L:
   q.extend(w) #flatten
q.sort(key=lambda x:x[2])　#入力順に並べ替えて、入力した順に出力できるようにする
for r in range(b):
        print(str(q[r][0]).zfill(6)+str(q[r][3]).zfill(6))　#zfill