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:
import sys
from operator import itemgetter

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

Submission status: Runtime Error

Solution code:
from operator import itemgetter
N, M = map(int, input().split())
iPY = [0]*M
res = [0]*M
for i in range(M):
    iPY[i] = (i, *map(int, input().split()))
iPY.sort(key=itemgetter(2))
iPY.sort(key=itemgetter(1))
j = 1
p = iPY[0][1]
for i, P, Y in iPY:
    if P != p:
        j = 1
        p = P
    res[i] = "{:06}{:06}".format(P, j)
    j += 1
for s in res:
    print(s)

Submission status: Runtime Error

Solution code:

N, M = map(int, input().split())
pref_dict = {}

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

sorted_dict = sorted(pref_dict.items(), key= lambda x: (x[1][0], x[1],[1]))
ans_dict = {}
buf = ""
count = 1

for tup in sorted_dict:

    row = tup[0]
    pref_name = f"00000{tup[1][0]}"[-6:]

    if pref_name == buf:
        count += 1
    else:
        count = 1

    pref_id = f"00000{count}"[-6:]
    ans_dict[row] = [pref_name, pref_id]
    buf = pref_name

for key, value in sorted(ans_dict.items(), key=lambda x: x[0]):
    print(*value, sep="")

Submission status: Runtime Error

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

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

sorted_dict = sorted(pref_dict.items(), key= lambda x: (x[1][0], x[1],[1]))
print(sorted_dict)

ans_dict = {}
buf = ""
count = 1

for tup in sorted_dict:

    row = tup[0]
    pref_name = f"00000{tup[1][0]}"[-6:]

    if pref_name == buf:
        count += 1
    else:
        count = 1

    pref_id = f"00000{count}"[-6:]
    ans_dict[row] = [pref_name, pref_id]
    buf = pref_name

for key, value in sorted(ans_dict.items(), key=lambda x: x[0]):
    print(*value, sep="")

Submission status: Runtime Error

Solution code:
n,m=map(int,input().split())
lst=[]
for i in range(m):
  p,y=map(int,input().split())
  lst.append([i,p,y])
lst.sort(key=lambda x:(x[1],x[2]))
j=1
Lst=[]
for i in range(m):
  if lst[i][1]==lst[min(m-1,i+1)][1]:
    s=str(lst[i][1])
    t=str(j)
    u=s.zfill(6)+t.zfill(6)
    j+=1
    Lst.append([lst[i][0],u])
  else:
    s=str(lst[i][1])
    t=str(j)
    u=s.zfill(6)+t.zfill(6)
    j-=j-1
    Lst.append([lst[i][0],u])
Lst.sort(lambda x:x[0])
for k in range(m):
  print(Lst[k][1])

Submission status: Runtime Error

Solution code:
n,m=map(int,input().split())
lst=[]
for i in range(m):
  p,y=map(int,input().split())
  lst.append([i,p,y])
lst.sort(lambda x:(x[1],x[2]))
j=1
Lst=[]
for i in range(m):
  if lst[i][1]==lst[min(m-1,i+1)][1]:
    s=str(lst[i][1])
    t=str(j)
    u=s.zfill(6)+t.zfill(6)
    j+=1
    Lst.append([lst[i][0],u])
  else:
    s=str(lst[i][1])
    t=str(j)
    u=s.zfill(6)+t.zfill(6)
    j-=j-1
    Lst.append([lst[i][0],u])
Lst.sort(lambda x:x[0])
for k in range(m):
  print(Lst[k][1])

Submission status: Runtime Error

Solution code:
n,m=map(int,input().split())
lst=[]
for i in range(m):
  p,y=map(int,input().split())
  lst.append([p,y])
lst.sort(lambda x:(x[0],x[1]))
j=1
for i in range(m):
  if lst[i][0]==lst[min(m-1,i+1)][0]:
    s=str(lst[i][0])
    t=str(j)
    u=s.zfill(6)+t.zfill(6)
    j+=1
    print(int(u))
  else:
    s=str(lst[i][0])
    t=str(j)
    u=s.zfill(6)+t.zfill(6)
    j-=j-1
    print(int(u))

Submission status: Runtime Error

Solution code:
n,m=map(int,input().split())
lst=[]
for i in range(m):
  p,y=map(int,input().split())
  lst.append([p,y])
lst.sort(lambda x:(x[0],x[1]))
j=1
for i in range(m):
  if i<m-1:
    if lst[i][0]==lst[i+1][0]:
      s=str(lst[i][0])
      t=str(j)
      s.zfill(6)
      t.zfill(6)
      u=s+t
      j+=1
      print(int(u))
    else:
      s=str(lst[i][0])
      t=str(j)
      s.zfill(6)
      t.zfill(6)
      u=s+t
      j-=j-1
      print(int(u))

Submission status: Runtime Error

Solution code:
n,m=map(int,input().split())
lst=[]
for i in range(m):
  p,y=map(int,input().split())
  lst.append([p,y])
lst.sort(lambda x:(x[0],x[1]))
j=1
for i in range(m):
  if lst[i][0]==lst[min(m-1,i+1)][0]:
    s=str(lst[i][0])
    t=str(j)
    s.zfill(6)
    t.zfill(6)
    u=s+t
    j+=1
    print(int(u))
  else:
    s=str(lst[i][0])
    t=str(j)
    s.zfill(6)
    t.zfill(6)
    u=s+t
    j-=j-1
    print(int(u))

Submission status: Runtime Error

Solution code:
n,m=map(int,input().split())
lst=[]
for i in range(m):
  p,y=map(int,input().split())
  lst.append([p,y])
lst.sort(lambda x:(x[0],x[1]))
for i in range(m):
  j=1
  while lst[i][0]==lst[min(m-1,i+1)][0]:
    s=str(lst[i][0])
    t=str(j)
    s.zfill(6)
    t.zfill(6)
    u=s+t
    j+=1
    print(int(u))

Submission status: Runtime Error

Solution code:
N, M = map(int, input().split())
ken = [[] for _ in range(N)]
shi = [tuple(map(int, input().split())) for _ in range(M)]
for s1, s2 in shi:
    ken[s1-1].append(s2)
for k in ken:
    k.sort()
for s1, s2 in shi:
    print("{:06}{:06}".format(s1, ken[s1-1].index(s2+1)))

Submission status: Runtime Error

Solution code:
from sys import stdin
import bisect

n,m = [int(x) for x in stdin.readline().rstrip().split()]
li = [list(map(int,stdin.readline().rstrip().split())) for _ in range(m)]

lin = [[]for _ in range(n)]
lin2 = []
for i in range(m):
    lin[li[j][0]-1].append(li[i][1])

for j in range(n):
    liv = sorted(lin[j])
    lin2.append(liv)

for k in range(m):
    tosi = str(li[k][0]).zfill(6)
    ban =  str(bisect.bisect(lin2[li[k][0]-1],li[k][1])).zfill(6)
    print(tosi+ban)

Submission status: Runtime Error

Solution code:
from sys import stdin
import bisect

n,m = [int(x) for x in stdin.readline().rstrip().split()]
li = [list(map(int,stdin.readline().rstrip().split())) for _ in range(m)]

lin = [[]for i in range(n)]
lin2 = []
li3 = []
for j in range(m):
    lin[li[j][0]-1].append(li[j][1])
    lin2.append(li[j][0]-1)

for j in range(n):
    liv = sorted(lin[j])
    li3.append(liv)

for k in range(m):
    s = len(str(li[k][1]))
    v = len(str(li[j][0]))
    print("0"*(6-v)+str(li[k][0])+"0"*(6-s)+str(bisect.bisect(li3[li[k][0]-1],li[k][1])))

Submission status: Runtime Error

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

for i in range(m):
    lst[i] = {v: i for i, v in enumerate(sorted(lst[i]))}

for i, j in py:
    print(str(i).zfill(6) + str(lst[i][j]+1).zfill(6))

Submission status: Runtime Error

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

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

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:
n,m = map(int, input().split())
info = [[i] + list(map(int, input().split())) for i in range(1, m+1)]
city = sorted(set([info_i[0] for info_i in info]))

sorted_info = sorted(info, key=lambda x:x[1])

print(sorted_info)

counter = 0

p = city.pop(0)

for i in range(m):
  if sorted_info[i][1] == p:
    counter += 1
    sorted_info[i].append(counter)
  else:
    p =  city.pop(0)
    counter = 1
    sorted_info[i].append(counter)

result = sorted(sorted_info, key=lambda x:x[0])

for res_i in result:
  print(str(res_i[1]).zfill(6) + str(res_i[3]).zfill(6))

Submission status: Runtime Error

Solution code:
n, m = (int(x) for x in input().split())
d = [[] for _ in range(m)]
py = []
for i in range(m):
    py.append([int(x) for x in input().split()])
    d[py[i][0]-1].append(py[i][1])
for li in d:
    li.sort()
for li in py:
    print(str(li[0]).zfill(6) + str(d[li[0]-1].index(li[1])+1).zfill(6))

Submission status: Runtime Error

Solution code:
n,m = map(int, input().split())
info = [[i] + list(map(int, input().split())) for i in range(1, m+1)]
city = sorted(set([info_i[0] for info_i in info]))

sorted_info = sorted(info, key=lambda x: [x[1], x[2]])
counter = 0

p = city.pop(0)

for i in range(m):
  if sorted_info[i][1] == p:
    counter += 1
    sorted_info[i].append(counter)
  else:
    p =  city.pop(0)
    counter = 1
    sorted_info[i].append(counter)

result = sorted(sorted_info, key=lambda x:x[0])

for res_i in result:
  print(str(res_i[1]).zfill(6) + str(res_i[3]).zfill(6))

Submission status: Runtime Error

Solution code:
N, M = [int(i) for i in input().split(" ")]
p = list()
y = list()
yd = {}
for i in range(0, M):
    pi, yi = [int(i) for i in input().split(" ")]
    p.append(pi)
    y.append(yi)
    if pi in yd.keys():
        yd[pi].append(yi)
    else:
        yd[pi] = [yi]

ydid = {}
for i in yd.keys():
    num = 1
    for j in sorted(yd[p[i]]):
        ydid[j] = num
        num = num + 1

for i in range(0, M):
    print("{:06}{:06}".format(p[i], ydid[y[i]]))

Submission status: Runtime Error

Solution code:
for i in range(M):
    P,Y=map(int,input().split())
    L.append([P,Y])
    if P not in D:
        D[P]=[]
    D[P].append(Y)
    
for v in D.values() :
    v.sort()

for i in L:
    print("00000"+str(i[0]*1000000 + D[i[0]].index(i[1])+1))

Submission status: Runtime Error

Solution code:
N, M = map(int, input().split())
l = [list(map(int, input().split())) for i in range(M)]
l_ = [[] for i in range(N)]
for i in range(M):
    l_[l[i][0] - 1].append(l[i][1])
l_[:] = sorted(l_[:])
print("\n".join([str(l[i][0]).zfill(6) + str(l_[l[i][0]-1].index(l[i][1]) + 1).zfill(6) for i in range(M)]))

Submission status: Runtime Error

Solution code:
import numpy as np
n,m=map(int,input().split())
d=[[] for i in range(n)]
l=[]
for i in range(m):
    a,b=map(int,input().split())
    d[a-1].append(b)
    l.append(a)
x=[[] for i in range(n)]
for i in range(n):
    d[i]=list(np.argsort(d[i]))
    tmp=[0]*len(d[i])
    for j in range(len(d[i]):
        tmp[d[i][j]]=j+1
    x[i]=tmp
for i in range(m):
    b=x[l[i]-1].pop(0)
    b+=1
    p=len(list(str(l[i])))
    q=len(list(str(b)))
    ans=''
    for j in range(6-p):
        ans+='0'
    ans+=str(l[i])
    for j in range(6-q):
        ans+='0'
    ans+=str(b)
    print(ans)

Submission status: Runtime Error

Solution code:
import numpy as np
n,m=map(int,input().split())
d=[[]*m for i in range(n)]
l=[]
for i in range(m):
    a,b=map(int,input().split())
    d[a-1].append(b)
    l.append(a)

for i in range(n):
    d[i]=np.argsort(d[i])
    
for i in range(m):
    b=d[l[i]-1].pop(0)
    b+=1
    p=len(list(str(l[i])))
    q=len(list(str(b)))
    ans=''
    for j in range(6-p):
        ans+='0'
    ans+=str(l[i])
    for j in range(6-q):
        ans+='0'
    ans+=str(b)
    print(ans)

Submission status: Runtime Error

Solution code:
from sys import stdin
input = stdin.readline
n, m = map(int, input().split())

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

built = [1]*m
for i in range(m):
    ans[i][1] = built[ans[i][0]-1]
    built[ans[i][0]-1] += 1

for i in sorted(ans,key=lambda x:x[2]): print("%06d%06d" % (i[0],i[1]))

Submission status: Runtime Error

Solution code:
n,m = map(int, input().split())
py = []
for i in rante(m):
  a,b = map(int, input.split())
  py.append([a,b,i])
py.sort()
p = 1
y = 1
for i in range(m):
  if py[i][0] == p:
    py[i][1] = y
    y += 1
  else:
    py[i][1] = 1
    y = 1
    p = py[i][0]
py = sorted(py, key=lambda x:x[2])
for p,y,i in py:
  print("{06}{06}".format(p,y))

Submission status: Runtime Error

Solution code:
n,m = map(int, input().split())
py = []
for i in rante(m):
  a,b = map(int, input.split())
  py.append([a,b,i])
py.sort()
p = 1
y = 1
for i in range(m):
  if py[i][0] == p:
    py[i][1] = y
    y += 1
  else:
    py[i][1] = 1
    y = 1
    p = py[i][0]
py.sort(key=lambda x:x[2])
for p,y,i in py:
  print("{06}{06}".format(p,y))

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
def slove():
    import sys
    input = sys.stdin.readline
    n, m = list(map(int, input().rstrip('\n').split()))
    py = []
    ls = [1] * (n + 1)
    for i in range(m):
        p, y = list(map(int, input().rstrip('\n').split()))
        py.append([p, y, 0, i])
    py.sort()
    for i in range(m):
        py[i][2] = ls[py[i][0]]
        ls[py[i][0]] += 1
    py.sort(key=lambda x: x[3])
    for i in range(len(py)):
        a = ["0"] * 6
        a.append(list(str(py[i][0])))
        a = a[-6:]
        b = ["0"] * 6
        b.append(list(str(py[i][2])))
        b = b[-6:]
        print("".join(a + b))


if __name__ == '__main__':
    slove()

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
import numpy as np


def solve(N, M):
    _p, _y = 0, 0
    py = []
    ans = np.zeros(M,dtype=object)
    rank = [1]*(M+1)

    for i in range(M):
        _p, _y = map(int, input().split())
        py.append((_y, _p, i))
    py.sort()

    for pyi in py:
        pi = pyi[1]
        ans[pyi[2]] = str(pi).zfill(6) + str(rank[pi]).zfill(6)
        rank[pi] += 1

    return ans


if __name__ == "__main__":
    N, M = map(int, input().split())
    ans = solve(N, M)
    for a in ans:
        print(a)

Submission status: Runtime Error

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

PY_list=[[] for _ in range(n)]

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

for p,y in PY:
    p_str=str(p)
    index_str=str(PY_list[p-1].index(y)+1)
    print(p_str.zfill(6)+index_str.zfill(6))

Submission status: Runtime Error

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

for i in range(m):
    lst[i] = sorted(lst[i])

for i, j in py:
    print(str(i).zfill(6) + str(lst[i].index(j)+1).zfill(6))

Submission status: Runtime Error

Solution code:
import bisect

n, m = map(int, input().split())
data = [list(map(int, input().split())) for _ in range(m)]  # 市iの順番を保つ
py_list = [[] for _ in range(m)]  # 市iの(属する県, 誕生年)

for p, y in data:
    py_list[p-1].append(y)

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

for p, y in data:
    pos = bisect.bisect_left(py_list[p-1], y) + 1
    print("%06d%06d" % (p, pos))

Submission status: Runtime Error

Solution code:
import bisect

n, m = map(int, input().split())
data = [list(map(int, input().split())) for _ in range(m)]  # 市iの順番を保つ
py_list = [[] for _ in range(m)]  # 市iの(属する県, 誕生年)

for p, y in data:
    py_list[p-1].append(y)

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

for p, y in data:
    pos = bisect.bisect_left(py_list[p-1], y) + 1
    print("%06d%06d" % (p, pos))

Submission status: Runtime Error

Solution code:
from operator import itemgetter

N,M = map(int,input().split())
cities = [ 0 for _ in range(M) ]

for i in range(M):
    p,y = map(int,input().split())
    cities[i] = [p,y,i]
cities = sorted(cities,key=itemgetter(1))
cities = sorted(cities,key=itemgetter(0))

out = ["*" for _ in range(M)]

beforeCity = cities[0][0]
cityCnt = 1
for i in range(M):
    if beforeCity != cities[i][0]:
        cityCnt = 1
    if len(str(cities[i][0])) < 6:
        cityNo1 = "0"*(6 - len(str(cities[i][0])))+str(cities[i][0])
    if len(str(cityCnt)) < 6:
        cityNo2 = "0"*(6 - len(str(cityCnt)))+str(cityCnt)
    out[cities[i][2]] = cityNo1+cityNo2
    cityCnt += 1
for a in out:
    print(a)

Submission status: Runtime Error

Solution code:
import sys
class City:
  def __init__(self, index, pref, time):
    self.index = index
    self.pref = pref
    self.time = time
    self.sort_res = None
  def get_id(self):
    str1 = "0"*(6-len(str(self.pref)))+str(self.pref)
    str2 = "0"*(6-len(str(self.sort_res)))+str(self.sort_res)
    return str1 + str2
if __name__ == '__main__':
  nm = list(sys.stdin,readline().split(" "))
  N = int(nm[0])
  M = int(nm[1])
  prefs = [[]] * N
  cities = []
  for i in range(M):
    info = list(sys.stdin,readline().split(" "))
    newcity = City(i,int(info[0]),int(info[1]))
    prefs[int(info[0])].append(newcity)
  for i in range(N):
    prefs[i].sort(key = lambda x: x.time)
  	for j in range(len(prefs[i])):
      prefs[i][j].sort_res = j+1
  for i in prefs:
    for j in i:
      cities.append(i)
  cities.sort(key = lambda x:x.index)
  for i in cities:
    print(i.get_id())

Submission status: Runtime Error

Solution code:
# -*- coding: utf-8 -*-
n,m = map(int, input().split())
i=0
lst = []
while i < m: 
    lst.append(list(map(int, input().split())) + [i])
    i+=1
lst = sorted(lst)
j=1

i=1
for k in lst:
    if i != k[0]:
        i==k[0]
        j=1
        k[1]=i*1000000+j
    else:
        j+=1
        k[1]=i*1000000+j

#ans
for ans in sorted(ll, key=lambda x:x[2]):
    print('{0:012d}'.format(ans[1]))

Submission status: Runtime Error

Solution code:
# -*- coding: utf-8 -*-
n,m = map(int, input().split())
i=0
lst = []
while i < m: 
    lst.append(list(map(int, input().split())) + [i])
    i+=1
lst.sort()
j=1

i=1
for k in lst:
    if i != k[0]:
        i==k[0]
        j=1
        k[1]=i*1000000+j
    else:
        j+=1
        k[1]=i*1000000+j


#ans
for ans in sorted(ll, key=lambda x:x[2]):
    print('{0:012d}'.format(ans[1]))

Submission status: Runtime Error

Solution code:
# -*- coding: utf-8 -*-
#import numpy as np

def func1(lst, value):
    return [i for i, x in enumerate(lst) if x == value]

n,m = map(int, input().split())
i=0
lst = []
while i < m: 
    l = list(map(int, input().split()))
    l.append(i)
    lst.append(l)
    i+=1
i=1
res=[]
for i in range(1,n+1):
    j=1
    for k in lst.sort():
        if i == k[0]:
            res.append([k[2],str(k[0]).rjust(6,'0') + str(j).rjust(6,'0')])
            j+=1
#ans
for ans in res.sort():
    print(ans[1])

Submission status: Runtime Error

Solution code:
# -*- coding: utf-8 -*-
#import numpy as np

def func1(lst, value):
    return [i for i, x in enumerate(lst) if x == value]

n,m = map(int, input().split())
i=0
lst = []
while i < m: 
    l = list(map(int, input().split()))
    l.append(i)
    lst.append(l)
    i+=1
i=1
res=[]
for i in range(1,n+1):
    j=1
    for k in sort(lst):
        if i == k[0]:
            res.append([k[2],str(k[0]).rjust(6,'0') + str(j).rjust(6,'0')])
            j+=1
#ans
for ans in sort(res):
    print(ans[1])

Submission status: Runtime Error

Solution code:
# -*- coding: utf-8 -*-
#import numpy as np
n,m = map(int, input().split())
i=0
lst = []
while i < m: 
    l = map(int, input().split())
    lst.append(list(l))
    i+=1

sort_lst = sorted(lst)
i=1
res=[]
for i in range(1,n+1):
    j=1
    for k in sort_lst:
        if i == k[0]:
            res.append([str(k[0])+str(k[1]),str(res[0]).rjust(6,'0') + str(res[2]).rjust(6,'0')])
            j+=1

#ans
for ans in lst:
    for res in sort_lst:
        if str(ans[0])+str(ans[1]) == res[0]:
            print(res[1])

Submission status: Runtime Error

Solution code:
import numpy as np
n,m = map(int, input().split())
count = [0]*n
py = []

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

li = sorted(py)
count = np.cumsum(count)

for i in range(m):
    num = li.index(py[i]) + 1
    pref = str(py[i][0])
    if py[i][0] == 1:
        print(pref.zfill(6) + str(num).zfill(6))
    else:
        print(pref.zfill(6) + str(num - count[i]).zfill(6))

Submission status: Runtime Error

Solution code:
n,m = map(int, input().split())
count = [0]*m
py = []

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

li = sorted(py)

for i in range(m):
    num = li.index(py[i]) + 1
    pref = str(py[i][0])
    print("0"*(6-len(pref)) + pref + "0"*(6-len(str(num))) + str(num - sum(count[:py[i][0]-1])))

Submission status: Runtime Error

Solution code:
somelists=[]

for i in range(m):
    a,b=map(int,input().split())
    somelists.append([i,a,b])

somelists.sort(key=lambda x:(x[1],x[2]))

prefs=1
numbers=0

for x in somelists:
    
    if x[1]==prefs:
        numbers+=1
        
        x.append(numbers)
    if x[1]!=prefs:
        prefs=x[1]
        numbers=1
        x.append(numbers)

somelists.sort(key=lambda x:x[0])
for _ in range(m):
    print(str(somelists[_][1]).zfill(6)+str(somelists[_][3]).zfill(6))

Submission status: Runtime Error

Solution code:
import sys
readline = sys.stdin.readline
n,m = list(map(int, readline().split()))
py = []
for _ in range(m):
    py.append(list(map(int, readline().split())))

spy = sorted(py, key=lambda x: x[1])
M = len(spy)

Y = {}
for i in range(M):
    Y[spy[i][1]] = 0

P = [0 for _ in range(M+1)]

for i in range(M):
    P[spy[i][0]] += 1
    Y[spy[i][1]] = P[spy[i][0]]

for i in range(m):
    print(str(py[i][0]).zfill(6) + str(Y[py[i][1]]).zfill(6))

Submission status: Runtime Error

Solution code:
import sys
readline = sys.stdin.readline
n,m = list(map(int, readline().split()))
py = []
for _ in range(m):
    py.append(list(map(int, readline().split())))

spy = sorted(py, key=lambda x: x[1])

Y = {}
for i in range(m):
    Y[spy[i][1]] = 0

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

for i in range(m):
    P[spy[i][0]] += 1
    Y[spy[i][1]] = P[spy[i][0]]

for i in range(m):
    print(str(py[i][0]).zfill(6) + str(Y[py[i][1]]).zfill(6))

Submission status: Runtime Error

Solution code:
import collections
import bisect

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

ans = collections.defaultdict(list)

for p, y in sorted(P):
    ans[p] += [y]
for p, y in P:
    print("%06d%06d"%(p, bisect.bisect(a[p], y)))

Submission status: Runtime Error

Solution code:
import collections
import bisect
n,m = map(int, input().split())
p = [list(map(int,input().split())) for i in range(m)]
a = collections.defaultdict(list)
for x,y in sorted(p):
  a[x]+=[y]
for x,y in p:
  print("%06d%06d"%(x,bisect.bisect(a[x],y))

Submission status: Runtime Error

Solution code:
n, m = map(int, input().split())
p = [[i] + list(map(int, input().split())) for i in range(m)]
r = [0]*n
p.sort(key=lambda x:(x[1],x[2]))
j = 0
k = 0
q = []
for i in range(m):
    if j==p[i][1]:
        k+=1
    else:
        k = 1
    q.append([p[i][0],k])
    j = p[i][1]
q.sort()
p.sort()
for i in range(m):
    print(f"{p[i][1]:0>6}{q[i][1]:0>6}")

Submission status: Runtime Error

Solution code:
n, m = map(int, input().split())
p = [list(map(int, input().split())) for _ in range(m)]
r = [0]*n
for i in range(m):
    r[p[i][0]-1]+=1
    print(f"{p[i][0]:0>6}{r[p[i][0]-1]:0>6}")

Submission status: Runtime Error

Solution code:
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
import math
import bisect
import random
from itertools import permutations, accumulate, combinations
import sys
import string
from bisect import bisect_left, bisect_right
from math import factorial


INF = float('inf')
def LI(): return list(map(int, sys.stdin.readline().split()))
def I(): return int(sys.stdin.readline())
def LIM(): return list(map(lambda x:int(x) - 1, sys.stdin.readline().split()))
def LS(): return sys.stdin.readline().split()
def S(): return sys.stdin.readline().strip()
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def LIRM(n): return [LIM() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def LSR(n): return [LS() for i in range(n)]
def SRL(n): return [list(S()) for i in range(n)]
mod = 1000000007


n, m = LI()
L = LIR(m)
for i in range(m):
    L[i] = [i, f'{L[i][0]:0>6}', L[i][1]]


L.sort(key=lambda x:x[1:])
cnt = 1
L[0][2] = f'{1:0>6}'
for i in range(1, m):
    if L[i][1] != L[i-1][1]:
        cnt = 1
    else:
        cnt += 1
    L[i][2] = f'{cnt:0>6}'



L.sort(key=lambda x:x[0])
for i in L:
    print(i[1] + i[2])

Submission status: Runtime Error

Solution code:
n, m = map(int, input().split())
cities = []
for i in range(m):
    p, y = map(int, input().split())
    cities.append([p, y, i])
cities = sorted(cities, key=lambda x: (x[0], x[1]))

prev = 0
count = 0
res = []
for city in cities:
    if city[0] != prev:
        count = 0
        prev = city[0]
    count += 1
    res.append([f'{city[0]:06d}{count:06d}', city[2]])
res = sorted(res, key=lambda x: x[1])

for x in res:
    print(x[0])

Submission status: Runtime Error

Solution code:
N,M = map(int, input().split())
PY = [list(map(int,input().split())) for _ in range(M)]
PY_originals = tuple(PY)
N_counter = [0] * N
M_counter = [0] * M

PY.sort(key=lambda val: val[1])

for i in range(M):
    N_counter[PY[1]-1] += 1
    M_counter[i] = N_counter[PY[1]-1]

for i in PY_originals:
    ans = str(i[0]).zfill(6)+str(M_counter[PY.index(i)]).zfill(6)
    print(ans)

Submission status: Runtime Error

Solution code:
n,m = map(int,input().split())
C = [[i,*map(int,input().split())] for i in range(m)]
C.sort(key=lambda c:c[1:])
prev = 0
count = 0
for c in C:
    if prev==c[1]: count+=1
    else: count=1
    c.append(format(c[1],'0>6')+format(count,'0>6'))
    prev=c[1]

for c in sorted(C, key=lambda c:c[0]):
    print(c[3])

Submission status: Runtime Error

Solution code:
n,m = list(map(int, input().split()))
cities = defaultdict(list)
cities = [ list(map(int, input().split())) for _ in range(m)]
sorted = sorted(
  cities,
  key = lambda x: (x[0], x[1])
)
hoge = 0
first_code = 0
fuga = 0
second_code = 0
for city in sorted:
  if(hoge < city[0]):
    hoge = city[0]
    first_code += 1
    fuga = 0
    seconde_code = 0
  if(fuga < city[1]):
    fuga = city[1]
    seconde_code += 1    
  print(format(first_code, '06'), format(second_code, '06'),sep="")

Submission status: Runtime Error

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

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

l = [0]*(n)
for i in range(m):
  l[PY[i][1]-1]+=1

for i in range(n):
  j = 0
  while j < l[i]:
    list(filter(lambda x:x[1]==i+1,PY))[j].append(j+1)
    j += 1
  
PY.sort(key = lambda x:x[0])
for i in range(m):
  print('{:0=6}'.format(PY[i][1])+'{:0=6}'.format(PY[i][3]))

Submission status: Runtime Error

Solution code:
def main():
    n, m = map(int, input().split())
    query = []
    result =  [[] for i in range(n)]
    for i in range(m):
        qList = list(map(int, input().split()))
        query.append(qList)
        result[qList[0]-1].append(qList[1])
 
    for i in result:
        i.sort()
 
    for city in query:
        rank = bisect.bisect_left(result[city[0]-1], city[1])
        ans = "%06d%06d"%(city[0],rank+1)
        print(ans)
 
if __name__ == "__main__":
    main()

Submission status: Runtime Error

Solution code:
def main():

    input = sys.stdin.readline

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

    result = [sorted(i) for i in result]
 
    for city in query:
        rank = result[city[0]-1].index(city[1])+1
        resultStr = "{}{}".format(str(city[0]).zfill(6), str(rank).zfill(6))
        print(resultStr)

main()

Submission status: Runtime Error

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

for city in query:
    result[city[0]-1].append(city[1])

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

for city in query:
    rank = result[city[0]-1].index(city[1])+1
    prefStr = "0"*(6-len(str(city[0]))) + str(city[0])
    rankStr = "0"*(6-len(str(rank))) + str(rank)
    resultStr = "{}{}".format(prefStr, rankStr)
    print(resultStr)

Submission status: Runtime Error

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

PY1 = sorted(PY)
#print(PY)

for i in range(M):
  X = str(PY1[i][0])#県の番号
  if i >= 1:#市の番号
    #print(PY)
    if PY1[i][0] == PY1[i-1][0]:
      Y = int(Y) + 1
    else:
      Y = 1
  else:
    Y = 1
  while len(str(X)) <= 5:#6桁にするための処理
    X = "0" + X
  while len(str(Y)) <= 5:
    Y = "0" + str(Y)
  PY1[i][1] = X + Y#文字列の結合
#print(PY)
PY2 = sorted(PY1, key = lambda x:x[2])

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

Submission status: Runtime Error

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

PY = sorted(PY)
#print(PY)

for i in range(M):
  X = str(PY[i][0])#県の番号
  if i >= 1:#市の番号
    #print(PY)
    if PY[i][0] == PY[i-1][0]:
      Y = int(Y) + 1
    else:
      Y = 1
  else:
    Y = 1
  while len(str(X)) <= 5:#6桁にするための処理
    X = "0" + X
  while len(str(Y)) <= 5:
    Y = "0" + str(Y)
  PY[i][1] = X + Y#文字列の結合
#print(PY)
PY = sorted(PY, key = lambda x:x[2])

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