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())                                                                         |N, M = map(int, input().split())
order = []                                                                                               |order = []
result = {}                                                                                              |result = {}
city = {}                                                                                                |city = {}
for i in range(M):                                                                                       |for i in range(M):
    P, Y = map(int, input().split())                                                                     |    P, Y = map(int, input().split())
    order.append(Y)                                                                                      |    order.append(Y)
    if P in city:                                                                                        |    if P in city:
        city[P].append(Y)                                                                                |        city[P].append(Y)
    else:                                                                                                |    else:
        city[P] = [Y]                                                                                    |        city[P] = [Y]
                                                                                                         |
s_city = dict(sorted(city.items()))                                                                      |s_city = dict(sorted(city.items()))
for v in s_city.values():                                                                                |for v in s_city.values():
    v.sort()                                                                                             |    v.sort()
                                                                                                         |
for k, v in city.items():                                                                                |for k, v in city.items():
    i = 1                                                                                                |    i = 1
    for e in v:                                                                                          |    for e in v:
        order[order.index(e)] = str(k).zfill(8) + str(i).zfill(8)                                        |        order[order.index(e)] = str(k).zfill(8) + str(i).zfill(8)
        i += 1                                                                                           |        i += 1
                                                                                                         |
for r in order:                                                                                          |for r in order:
    print(r)                                                                                             |    print(r)

Submission status: Runtime Error

Solution code:
import numpy as np
n, m = map(int, input().split())
list = [[] for i in range(n)]
list2 = []
for i in range(m):
    t = [int(i) for i in input().split()]
    list2.append(t)
    t1 = list[t[0] - 1]
    t1.append(t)
    list[t[0] - 1] = t1
list = np.array(list)
result = []
for i in range(n):
    p = np.array(list[i])
    p.sort(axis=1)
    f = np.arange(1, p.shape[0]+1)
    f = f.reshape(p.shape[0], 1)
    p = np.hstack((p, f))
    result.extend(p.tolist())
result = np.array(result)
for i in list2:
    t = result[:, :2]
    t = t.tolist()
    e = t.index(i)
    s = format(result[e][0], '06') + format(result[e][-1], '06')
    print(s)

Submission status: Runtime Error

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

for i in range(m):
    l[i].append(i)
l = sorted(l,key=lambda x: (x[0],x[1]))

l[0].append(1)
for i in range(1,m):
    if l[i][0]!=l[i-1][0]:
        l[i].append(1)
    else:
        l[i].append(l[i-1][3]+1)

for i in range(m):
    l[i].append(str(l[i][0]).zfill(6) + l[i][3].zfill(6))

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

for i in range(m):
    print(l[i][4])

Submission status: Runtime Error

Solution code:
n,m=map(int, input().split())
l=[input().split() for i in range(m)]
m={}
for j in range(len(l)):
    if l[j][0] not in m.keys():
        m[l[j][0]]=[]
    m[l[j][0]].append(l[j][1])
lab=[0]*(n+1)
for k in m.keys():
    m[k] = sorted(m[k], reverse=False)
    p='0'*(6-len(k))+k
    for h in range(len(m[k])):
        q='0'*(6-len(str(h+1)))+str(h+1)
        key=l.index([k,m[k][h]])
        lab[key]=p+q
for v in lab:
    print(v)

Submission status: Runtime Error

Solution code:
nm_lst = list(map(int, input().split()))
city_lst = [list(map(int, (str(i)+' '+input()).split())) for i in range(nm_lst[1])]

city_lst = sorted(city_lst, key = lambda x: x[1]*10**7 + x[2])

ans_lst = []
num_num = 0
for n, city in enumerate(city_lst):
    prefec_num = city[1]
    prefec_str = '0' * (6-len(str(prefec_num))) + str(prefec_num)
    if n = 0 or (prefec_num != city_lst[n-1][1]):
        num_str = '000001'
        num_num = 1
    else:
        num_num += 1
        num_str = '0' * (6-len(str(num_num))) + str(num_num)
    ans_lst.append([city[0], prefec_str, num_str])
    
ans_lst = sorted(ans_lst, key = lambda x:x[0])

for city in ans_lst:
    print(city[1]+city[2])

Submission status: Runtime Error

Solution code:
nm_lst = list(map(int, input().split()))
city_lst = [list(map(int, (str(i)+' '+input()).split())) for i in range(nm_lst[1])]

city_lst = sorted(city_lst, key = lambda x: x[1]*10**7 + x[2])

ans_lst = []
num_num = 0
for n, city in enumerate(city_lst):
    prefec_num = city[1]
    if len(str(prefec_num)) < 6:
        prefec_str = '0' * (6-len(str(prefec_num))) + str(prefec_num)
    if prefec_num != city_lst[n-1][1]:
        num_str = '000001'
        num_num = 1
    else:
        num_num += 1
        num_str = '0' * (6-len(str(num_num))) + str(num_num)
    ans_lst.append([city[0], prefec_str, num_str])
    
ans_lst = sorted(ans_lst, key = lambda x:x[0])

for city in ans_lst:
    print(city[1]+city[2])

Submission status: Runtime Error

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

count = 1
for i in range(m):
    p,y = map(int, input().split())
    a[p-1].append([y, count])
    count += 1
b = []
for i,j in enumerate(a):
    j_sort = sorted(j)
    for k,l in enumerate(j_sort):
        b.append([l[1],str(i+1).zfill(6)+str(k+1).zfill(6)])
        
for i in sorted(b):
    print(i[1])

Submission status: Runtime Error

Solution code:
import sys
input = sys.stdin.readline
 
N, M = (int(i) for i in input().split())
input_list = [[int(i) for i in input().split()] for i in range(M)] 
 
m_list = [[] for j in range(N+1)]
 
for inputs in input_list:
    m_list[inputs[0]].append(inputs[1])
 
for arr in m_list:
    arr.sort()
    arr.insert(-10000)
 
for inputs in input_list:
    num = m_list[inputs[0]].index(inputs[1])
    print(str(inputs[0]).zfill(6) + str(num).zfill(6))

Submission status: Runtime Error

Solution code:
N, M = map(int, input().split())
PY = [None for _ range(M)]
ken_d = {k:[]  for k in range(1, N+1)}

for i in range(M):
    p = list(map(int,input().split()))
    PY[i] = p
    ken_d[p[0]].append(p[1])

for k in ken_d.keys():
    ken_d[k].sort()

for p in PY:
    x = ken_d[p[0]].index(p[1]) + 1
    print(str(p[0]).zfill(6) + str(x).zfill(6))

Submission status: Runtime Error

Solution code:
#!/usr/bin/env python3

class City:
    def __init__(self, i1, p, y, o=None):
        self.i1 = i1
        self.p = p
        self.y = y
        self.o = o

    def __repr__(self):
        return f"City({self.i1}, {self.p}, {self.y}, {self.o})"

    def get_id(self):
        return "%06d%06d" % (self.p, self.o)

def put_ids(n, cities):
    years = {i: [] for i in range(1, n + 1)}
    for c in cities:
        years[c.p].append(c.y)

    year_to_order = {i: {} for i in range(1, n + 1)}
    for i in range(1, n + 1):
        ys = sorted(years[i])
        for j0, y in enumerate(ys):
            year_to_order[i][y] = j0 + 1

    for c in cities:
        c.o = year_to_order[c.p][c.y]

def main():
    n, m = map(int, input().split())
    cities = []
    for i0 in range(m):
        p, y = map(int, input().split())
        city = City(i0, p, y)
        cities.append(city)
    put_ids(n, cities)
    for c in cities:
        print(c.get_id())

main()

Submission status: Runtime Error

Solution code:
#!/usr/bin/env python3

class City:
    def __init__(self, i1, p, y, o=None):
        self.i1 = i1
        self.p = p
        self.y = y
        self.o = o

    def __repr__(self):
        return f"City({self.i1}, {self.p}, {self.y}, {self.o})"

    def get_id(self):
        return f"{self.p:06}{self.o:06}"

def put_ids(n, cities):
    years = {i: [] for i in range(1, n + 1)}
    for c in cities:
        years[c.p].append(c.y)

    year_to_order = {i: {} for i in range(1, n + 1)}
    for i in range(1, n + 1):
        ys = sorted(years[i])
        for j0, y in enumerate(ys):
            year_to_order[i][y] = j0 + 1

    for c in cities:
        c.o = year_to_order[c.p][c.y]

def main():
    n, m = map(int, input().split())
    cities = []
    for i0 in range(m):
        p, y = map(int, input().split())
        city = City(i0, p, y)
        cities.append(city)
    put_ids(n, cities)
    # for c in cities:
    #     print(c.get_id())

main()

Submission status: Runtime Error

Solution code:
#!/usr/bin/env python3

class City:
    def __init__(self, i1, p, y, o=None):
        self.i1 = i1
        self.p = p
        self.y = y
        self.o = o

    def __repr__(self):
        return f"City({self.i1}, {self.p}, {self.y}, {self.o})"

    def get_id(self):
        return f"{self.p:06}{self.o:06}"

def put_ids(n, cities):
    years = {i: [] for i in range(1, n + 1)}
    for c in cities:
        years[c.p].append(c.y)

    year_to_order = {i: {} for i in range(1, n + 1)}
    for i in range(1, n + 1):
        ys = sorted(years[i])
        for j0, y in enumerate(ys):
            year_to_order[i][y] = j0 + 1

    for c in cities:
        c.o = year_to_order[c.p][c.y]

def main():
    n, m = map(int, input().split())
    cities = []
    for i0 in range(m):
        p, y = map(int, input().split())
        city = City(i0, p, y)
        cities.append(city)
    put_ids(n, cities)
    for c in cities:
        print(c.get_id())

main()

Submission status: Runtime Error

Solution code:
n,m = (int(i) for i in input().split())
res = list([] for i in range(n))
p,y = [],[]
for i in range(m):
    tmp = list(int(i) for i in input().split())
    p.append(tmp[0])
    y.append(tmp[1])
    res[tmp[0]-1].append(tmp[1])

for i in range(n):
    res[i] = sorted(res[i])

for i in range(n):
    print("{0:06d}{1:06d}".format(p[i], res[p[i]-1].index(y[i])+1))

Submission status: Runtime Error

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

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

    pref_sorted = sorted(enumerate(pref), key=lambda x: x[1])

    idx = [1 for _ in range(M)]
    res = ['' for _ in range(M)]
    for j, (p, y) in pref_sorted:
        res[j] = str(p).zfill(6) + str(idx[p]).zfill(6)
        idx[p] += 1
    for r in res:
        print(r)


if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
def main():
  # N個の県，M個の市，
  # 市iが誕生したのはY_i年で県P_iに属す
  # 市iが県P_iの中でx番目にできた市だと、市iの認識番号の上6桁はP_i,下6桁はx
  # 6桁以下だと6桁になるように左に0詰める

  N, M = map(int, input().split())
  iPY = []
  for i in enumerate(range(M)):
    p, y = map(int, input().split())
    iPY.append([i, p, y])
  # PY = [list(map(int, input().split())) for _ in range(M)]
  iPY_sorted = sorted(iPY, key=lambda x: x[2])

  city_count = {}
  order = {}
  for i, p, y in iPY_sorted:
    if not p in city_count:
      city_count[p] = 0
    city_count[p] += 1
    order[p, i] = city_count[p]
    
  for i, p, y in enumerate(iPY):
    print('{:06}{:06}'.format(p, order[p, i]))

main()

Submission status: Runtime Error

Solution code:
def main():
  # N個の県，M個の市，
  # 市iが誕生したのはY_i年で県P_iに属す
  # 市iが県P_iの中でx番目にできた市だと、市iの認識番号の上6桁はP_i,下6桁はx
  # 6桁以下だと6桁になるように左に0詰める

  N, M = map(int, input().split())
  # PY = []
  # for _ in range(M):
  #   a = list(map(int, input().split()))
  #   PY.append(a)
  PY = [list(map(int, input().split())) for _ in range(M)]
  PY_sorted = sorted(PY, key=lambda x: x[1])

  city_count = {}
  order = {}
  for i, (p, y) in enumerate(PY_sorted):
    if not p in city_count:
      city_count[p] = 0
    city_count[p] += 1
    order[p, i] = city_count[p]
    
  for i, (p, y) in enumerate(PY):
    print('{:06}{:06}'.format(p, order[p, i]))

main()

Submission status: Runtime Error

Solution code:
def main():
  # N個の県，M個の市，
  # 市iが誕生したのはY_i年で県P_iに属す
  # 市iが県P_iの中でx番目にできた市だと、市iの認識番号の上6桁はP_i,下6桁はx
  # 6桁以下だと6桁になるように左に0詰める

  N, M = map(int, input().split())
  PY = []
  for _ in range(M):
    a = list(map(int, input().split()))
    PY.append(a)
  PY_sorted = sorted(PY, key=lambda x: x[1])

  city_count = {}
  order = {}
  for i, (p, y) in enumerate(PY_sorted):
    if not p in city_count:
      city_count[p] = 0
    city_count[p] += 1
    order[p, i] = city_count[p]
    
  for i, (p, y) in enumerate(PY):
    print('{:06}{:06}'.format(p, order[p, i]))

main()

Submission status: Runtime Error

Solution code:
from bisect import bisect_left


def index(a, x):
    i = bisect_left(a, x)
    if i != len(a) and a[i] == x:
        return i
    raise ValueError

py = [ [] for _ in range(10**5+10)]
p=[]
y=[]
n,m = map(int,input().split())
for _ in range(m):
        pp,yy = map(int,input().split())
        p.append(pp)
        y.append(yy)
        py[pp-1].append(yy)

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

for i in range(m):
        id = index(py[p[i]-1],y[i]) + 1
        print("{0:06d}{1:06d}".format(p[i],id))

Submission status: Runtime Error

Solution code:
from bisect import bisect_left


def index(a, x):
    i = bisect_left(a, x)
    if i != len(a) and a[i] == x:
        return i
    raise ValueError

py = [ [] for _ in range(100010)]
p=[]
y=[]
n,m = map(int,input().split())
for _ in range(m):
        pp,yy = map(int,input().split())
        p.append(pp)
        y.append(yy)
        py[pp].append(yy)

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

for i in range(m):
        id = index(py[p[i]],y[i]) + 1
        print("{0:06d}{1:06d}".format(p[i],id))

Submission status: Runtime Error

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

d = dict(s)
for i in d.keys():
    d[i] = [0]
for si in s:
    d[si[0]] += [si[1]]

def pcod(a, b):
    c = 6-len(str(a))
    d = 6-len(str(b))
    return ('0'*c + str(a) + '0'*d + str(b))

def order(si, dc):
#    dso = sorted(dc[si[0]])
    return dc[si[0].index(si[1])

for si in s:
    print(pcod(si[0], order(si, d)))

Submission status: Runtime Error

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

d = dict(s)
for i in d.keys():
    d[i] = [0]
for si in s:
    d[si[0]] += [si[1]]

def pcod(a, b):
    c = 6-len(str(a))
    d = 6-len(str(b))
    return ('0'*c + str(a) + '0'*d + str(b))

def order(si, dc):
    return dc[si[0].index(si[1])

for si in s:
    print(pcod(si[0], order(si, d)))

Submission status: Runtime Error

Solution code:
def FillZero(num,f=6):
    s = ""
    s += (f - len(str(num))) * "0"
    s += str(num)
    return(s)

for i in range(M):
    l[i].append(i)

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

key0 = l[0][0]
key1 = 0
for i in range(M):
    if key0 == l[i][0]:
        key1 += 1
        l[i][1] = key1
    else:
        key1 = 1
        l[i][1] = key1
        key0 += 1

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

for i in range(M):
    print(FillZero(l[i][0]) + FillZero(l[i][1]))

Submission status: Runtime Error

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

def FillZero(num,f=6):
    s = ""
    s += (f - len(str(num))) * "0"
    s += str(num)
    return(s)

for i in range(M):
    l[i].append(i)

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

key0 = l[0][0]
key1 = 0
for i in range(M):
    if key0 == l[i][0]:
      	key1 += 1
        l[i][1] = key1
    else:
        key1 = 1
        l[i][1] = key1
        key0 += 1

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

for i in range(M):
    print(FillZero(l[i][0]) + FillZero(l[i][1]))

Submission status: Runtime Error

Solution code:
from operator import itemgetter
import  numpy as np
import sys

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

in_p = []
in_y = []
in_num = [0] * n

p = np.zeros((n,m))

for i in range(m):
    a,b = map(int,input().split())
    in_p.append(a)
    in_y.append(b)
    p[a-1,i]= b
    in_num[a-1]+=1

p_sort=np.sort(p,axis=1)
in_num = np.array(in_num)
in_num = m - in_num
for i in range(m):
    year=str(in_p[i]).zfill(6)
    a =  np.where(p_sort == in_y[i])
    b = int(a[1] - in_num[int(a[0])]+1 )
    print("{0}{1}\n".format(year,str(b).zfill(6)))

Submission status: Runtime Error

Solution code:
from operator import itemgetter
import  numpy as np
import sys

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

in_p = []
in_y = []
in_num = [0] * n

p = np.zeros((n,m))

for i in range(m):
    a,b = map(int,input().split())
    in_p.append(a)
    in_y.append(b)
    p[a-1,i]= b
    in_num[a-1]+=1

p_sort=np.sort(p,axis=1)
in_num = np.array(in_num)
in_num = m - in_num
for i in range(m):
    year=str(in_p[i]).zfill(6)
    a =  np.where(p_sort == in_y[i])
    b = int(a[1] - in_num[int(a[0])]+1 )
    print("{0}{1}".format(year,str(b).zfill(6)))

Submission status: Runtime Error

Solution code:
from operator import itemgetter
import  numpy as np
import sys

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

in_p = []
in_y = []
in_num = [0] * n

p = np.zeros((n,m))
print(p)

for i in range(m):
    a,b = map(int,input().split())
    in_p.append(a)
    in_y.append(b)
    p[a-1,i]= b
    in_num[a-1]+=1

p_sort=np.sort(p,axis=1)
in_num = np.array(in_num)
print(p_sort)
in_num = m - in_num
for i in range(m):
    year=str(in_p[i]).zfill(6)
    a =  np.where(p_sort == in_y[i])
    b = int(a[1] - in_num[int(a[0])]+1 )
    print("{0}{1}".format(year,str(b).zfill(6)))

Submission status: Runtime Error

Solution code:
from operator import itemgetter
import sys

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

in_p = []
in_y = []
p = []

for _ in range(n):
    p.append([])

for i in range(m):
    a,b = map(int,input().split())
    in_p.append(a)
    in_y.append(b)
    p[a-1].append(b)  

for i in range(n):
    p[i].sorted()

for i in range(m):
    year=str(in_p[i]).zfill(6)
    a = p[in_p[i]-1].index(in_y[i]) 
    num=str(a).zfill(6)
    print("{0}{1}".format(year,num))

Submission status: Runtime Error

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

in_p = []
in_y = []
p = []

for i in range(n):
    p.append([])

for i in range(m):
    a,b = map(int,input().split())
    in_p.append(a)
    in_y.append(b)
    p[a-1].append(b)  

p = sorted(p, key = lambda x:x[:])

for i in range(m):
    year=str(in_p[i]).zfill(6)
    a = p[in_p[i]-1].index(in_y[i]) + 1
    num=str(a).zfill(6)
    print("{0}{1}".format(year,num))

Submission status: Runtime Error

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

in_p = []
in_y = []
p = []

for i in range(n):
    p.append([])

for i in range(m):
    a,b = map(int,input().split())
    in_p.append(a)
    in_y.append(b)
    p[a-1].append(b)  

    p = sorted(p, key = lambda x:x[:])

for i in range(m):
    year=str(in_p[i]).zfill(6)
    a = p[in_p[i]-1].index(in_y[i]) + 1
    num=str(a).zfill(6)
    print("{0}{1}".format(year,num))

Submission status: Runtime Error

Solution code:
N,M=map(int,input().split())
P=[[] for i in range(M)]
Y=[1 for i in range(M)]
id=[0 for i in range(M)]
for i in range(M):
    a,b=map(int,input().split())
    P[i].append(i)
    P[i].append(a)
    P[i].append(b)
P.sort(key=lambda x:x[2])
for i in range(M):
    P[i].append(str(P[i][1]*1000000+Y[P[i][1]]))
    Y[P[i][1]]+=1
P.sort(key=lambda x:x[0])
for i in range(M):
    print(P[i][3].zfill(12))

Submission status: Runtime Error

Solution code:
N,M=map(int,input().split())
P=[[] for i in range(N+1)]
Y=[]
id=[]
for i in range(M):
    a,b=map(int,input().split())
    P[a].append(b)
    Y.append(b)
for i in range(N+1):
    P[i].sort()
for i in range(1,N+1):
    j=1
    for p in P[i]:
        id[Y.index(p)]=str(i*1000000+j)
        j+=1
for i in range(M):
    print(id[i].zfill(12))

Submission status: Runtime Error

Solution code:
N,M=map(int,input().split())
P=[[] for i in range(N+1)]
Y=[]
id=[[] for i in range(N+1)]
for i in range(M):
    a,b=map(int,input().split())
    P[a].append(b)
    Y.append(b)
for i in range(N+1):
    P[i].sort()
for i in range(1,N+1):
    j=1
    for p in P[i]:
        id[Y.index(p)]=str(i*1000000+j)
        j+=1
for i in range(M):
    print(id[i].zfill(12))

Submission status: Runtime Error

Solution code:


if __name__ == '__main__':
    ken_num, city_num = list(map(int, input().split()))
    data = [list(map(int, input().split())).append(i) for i in range(city_num)]

    # ken_num, city_num = 2, 3
    # data = [[1,32,0], [2,63,1],[1,12,2]]

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

    count = 1
    ken_num = 1
    ans_data = {}

    for i in range(city_num):
        number = data[i][2]
        if data[i][0] != ken_num:
            count = 1
            ken_num = data[i][0]
        chr = "{0:06d}".format(ken_num) + "{0:06d}".format(count)
        ans_data.update({number:chr})
        count += 1

    for i in range(city_num):
        print(ans_data[i])

Submission status: Runtime Error

Solution code:
# -*- coding: utf-8 -*-
a = int(input().split()[1])
c = [int(input().split()[0]) for i in range(a)]
import collections
c = collections.Counter(c)
for k,v in sorted(c.items()):
    for i in range(v):
        j = i+1
        print(f'{k:08}{j:08}')

Submission status: Runtime Error

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

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

answer_list = [0] * M
prefectures = [0] * (M+1)
data_set = [0] * M

data_set_dict = {}

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

data_set.sort()

for i in range(M):
	answer = ''
	P, Y, a = data_set[i]
	prefectures[P] += 1

	for j in range(6-len(list(str(P)))):
		answer += '0'

	answer += str(P)

	for k in range(6-len(list(str(prefectures[P])))):
		answer += '0'

	answer += str(prefectures[P])

	answer_list[a] = answer

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

Submission status: Runtime Error

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

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

answer_list = [0] * M
prefectures = [0] * (M+1)
data_set = [0] * M

data_set_dict = {}

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

data_set.sort()

for i in range(M):
	answer = ''
	P, Y, a = data_set[i]
	prefectures[P] += 1

	for j in range(6-len(list(str(P)))):
		answer += '0'

	answer += str(P)

	for j in range(6-len(list(str(prefectures[P])))):
		answer += '0'

	answer += str(prefectures[P])

	answer_list[a] = (answer)

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

Submission status: Runtime Error

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

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

answer_list = []

prefectures = [0] * (M+1)
data_set = [0] * M

data_set_dict = {}

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

data_set.sort()

for i in range(M):
	answer = ''
	P, Y = data_set[i]
	prefectures[P] += 1

	for j in range(6-len(list(str(P)))):
		answer += '0'

	answer += str(P)

	for j in range(6-len(list(str(prefectures[P])))):
		answer += '0'

	answer += str(prefectures[P])

	answer_list.append([data_set_dict[P, Y], answer])

answer_list.sort()

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

Submission status: Runtime Error

Solution code:
n,m = list(map(int,input().split()))
a = [[None] for i in range(n+1)]
b = [None]*m
for i in range(m):
    p,s = list(map(int,input().split()))
    a[p].append(s)
    b[i] = [p,s]
print(a)
for i in a:
    a[i].sort()
print(a)
for i in b:
    ken = b[i][0]
    si = a[ken].index(b[i][1]) +1
    ken = str(ken).zfill(6)
    si = str(si).zfill(6)
    print("".join([ken,si]))

Submission status: Runtime Error

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

dict_p = {}
dict_c = {}

for i, p, y in sorted(ipy, key=lambda x: x[2]):
  if not p in dict_p:
    dict_p[p] = 0
  dict_p[p] += 1
  dict_c[p,i] = dict_p[p]

for i, p, y in ipy:
  print(f'{p:06}{dict_c[p,i]:06}')

Submission status: Runtime Error

Solution code:
import time as time

lines =  input().split()
n = int(lines[0])
m = int(lines[1])
#n,m = map(int,input().split())

py = []
od = [[]*1 for i in range(n)]

#print ("create list: " + str(time.time() - s) )

s = time.time()
for i in range(0,m):

    lines =  input().split()
    p = int(lines[0])
    y = int(lines[1])
    py.append([p,y])
       
    odlen = len(od[p-1])
    od[p-1].append(y)
    od[p-1].sort()
    """ if odlen >= 1 :

        low = 0
        high = odlen - 1
        mid = odlen >> 1

        while low <= high:
            mid = (low + high) >> 1
            guess = od[p-1][mid]
            if guess == y:
                break
            if guess > y :
                high = mid - 1
            else:
                low  = mid + 1
        od[p-1].insert(low,y)

    else:
        od[p-1].append(y) """

#print ("sort: " + str(time.time() - s) )
#exit(0)

s = time.time()
for i in range(0,m):
    py0 = py[i][0]
    
    low = 0
    high = odlen - 1
    mid = odlen >> 1
    while low <= high:
        mid = (low + high) >> 1
        guess = od[py0-1][mid]
        if guess == py[i][1]:
           break
        if guess > py[i][1]:
           high = mid - 1
        else:
           low  = mid + 1
    r = low
    #print(r)
    #r = od[py0-1].index(py[i][1])

    tmp = py0
    digit = 0
    while tmp > 0 :        
        digit += 1
        tmp = tmp // 10
    
    l = 6-digit
    for j in range(l):
        print('0',end="")
    print(py0,end="")

    tmp = r + 1
    digit = 0
    while tmp > 0 :        
        digit += 1
        tmp = r // 10

    l = 6-digit
    for j in range(l):
        print('0',end="")
    print(r+1)

#print ("index: " + str(time.time() - s) )

Submission status: Runtime Error

Solution code:
def ins(arr, x):
    b=len(arr)-1
    a=0
    if not b+1:
        return 0
    while (b-a)>1:
        m=int((a+b)/2)
        if x>=arr[m]:
            a=m
        else:
            b=m      
    if arr[b]<x:
        return b+1
    elif arr[a]>x:
        return a
    return b

N,M=map(int,input().split(' '))
ys=[tuple(map(int,input().split(' '))) for i in range(M)]

citys=[[] for i in range(N)]
dic={}
for y in ys:
    ci=y[0]-1
    index=ins(citys[ci], y[1])
    citys[ci].insert(index, y[1])
    y[0]=10**12+y[0]*10**6

for city in citys:
    if len(city)!=0:
        for i in range(len(city)):
            dic[city[i]]=i+1
    
for y in ys:
    number=str(y[0]+dic[y[1]])[-12:]
    print(number)

Submission status: Runtime Error

Solution code:
def ins(arr, x):
    b=len(arr)-1
    a=0
    if b==-1:
        return 0
    
    while (b-a)>1:
        m=int((a+b)/2)
        if x>=arr[m]:
            a=m
        else:
            b=m      
    
    elif arr[b]<x:
        return b+1
    elif arr[a]>x:
        return a
    
    return b

N,M=map(int,input().split(' '))
ys=[tuple(map(int,input().split(' '))) for i in range(M)]

citys=[[] for i in range(N)]
dic={}
for y in ys:
    ci=y[0]-1
    index=ins(citys[ci], y[1])
    citys[ci].insert(index, y[1])

for city in citys:
    for i in range(len(city)):
        dic[city[i]]=i+1
        
for y in ys:
    number=str(10**12+y[0]*10**6+dic[y[1]])[-12:]
    print(number)

Submission status: Runtime Error

Solution code:
N,M=map(int,input().split(' '))
citys=[[] for i in range(N+1)]
citynum=[0 for i in range(M)]
dic={}
ys=[tuple(map(int,input().split(' '))) for i in range(M)]
for y in ys:
    citys[y[0]-1].insert(ins(citys[y[0]-1],y[1]), y[1])

for city in citys:
    for i in range(len(city)):
        dic[city[i]]=i+1

for y in ys:
    number=str(10**12+dic[y[1]]+y[0]*10**6)[1:]
    print(number)

Submission status: Runtime Error

Solution code:
N,M=map(int,input().split(' '))
results=[]
citys=[[] for i in range(N)]
for i in range(M):
    Pi,Yi=map(int,input().split(' '))
    citys[Pi].append(Yi) 
for city in citys:
    for i in range(len(city)):
        city[i]+=10**12+(i+1)*10**6
        print(str(city[i])[1:])

Submission status: Runtime Error

Solution code:
def ins(arr, x):
    b=len(arr)
    a=0
    while abs(b-a)>1:
        m=int((a+b)/2)
        if x>=arr[m]:
            a=m
        else:
            b=m
    return a

N,M=map(int,input().split(' '))
results=[]
citys=[[] for i in range(N)]
for i in range(M):
    Pi,Yi=map(int,input().split(' '))
    index=ins(citys[Pi],Yi)
    citys[Pi].insert(index,Yi) 
for city in citys:
    for i in range(len(city)):
        city[i]+=10**12+(i+1)*10**6
        print(str(city[i])[1:])

Submission status: Runtime Error

Solution code:
NM = list(map(int, input().split()))
pre = []
for i in range(NM[1]):
    PY = list(map(int, input().split()))
    pre.append([PY[0], PY[1], i])

pre = sorted(pre, key=lambda x: x[1], reverse=False)
pre = sorted(pre, key=lambda x: x[0], reverse=False)

k = 0
for i in range(1, NM[0] + 1):
    num = 1
    while pre[k][0] == i :
        pre[k][1] = num
        num += 1
        k += 1
        if k == NM[1]:
            break
pre = sorted(pre, key=lambda x: x[2], reverse=False)

for j in pre:
    print(str(j[0]).zfill(6) + str(j[1]).zfill(6))