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: Wrong Answer

Solution code:
n,m=map(int,input().split())
e=[[]for _ in range(n)]
py=[]
for _ in range(m):
  p,y=map(int,input().split())
  py.append((p,y))
  e[p-1].append(y)
for i in range(n):e[i].sort()
xy=lambda x,y:x*1000000+y
d={}
for i in range(n):
  for j in range(len(e[i])):
    d[xy(i+1,e[i][j])]=str(i+1).zfill(6)+str(j+1).zfill(6)
for p,y in py:
  print(d[xy(p,y)])

Submission status: Wrong Answer

Solution code:
from math import ceil,floor,comb,factorial,gcd,pow,sqrt,log2,cos,sin,tan,acos,asin,atan,degrees,radians,pi,inf
from itertools import accumulate,permutations,combinations,product,combinations_with_replacement
from collections import deque,defaultdict,Counter
from bisect import bisect_left,bisect_right
from operator import itemgetter
from heapq import heappop,heappush
from copy import deepcopy
from time import time
import string
import sys
sys.setrecursionlimit(10 ** 7)
def input() : return sys.stdin.readline().strip()
def INT()   : return int(input())
def MAP()   : return map(int,input().split())
def LIST()  : return list(MAP())

n, m = MAP()
p = [[i]+LIST() for i in range(m)]
q = [0]*(n+1)

p.sort(key=itemgetter(2))
for x in p:
    q[x[1]] += 1
    x.append(q[x[1]])

p.sort(key=itemgetter(0))
for x in p:
    print(str(x[1]).zfill(6), str(x[3]).zfill(6))

Submission status: Wrong Answer

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

pref = [[] for _ in range(N+1)]
for i in range(M):
    pp, yy = map(int, input().split())
    pref[pp].append((yy, i))

names = ['']*(M+1)
for i in range(N):
    pref[i].sort()

for i in range(1, N+1):
    prefname = '{:06d}'.format(i)
    for k in range(len(pref[i])):
        _, id = pref[i][k]
        cityname = '{:06d}'.format(k+1)
        names[id] = prefname + cityname

for id in range(M):
    print(names[id])

Submission status: Wrong Answer

Solution code:
import numpy as np

n, m = list(map(int, input().split()))
py = [list(map(int, input().split())) + [i] for i in range(m)]
spy = sorted(py)

sspy = [0] * (m)
num = 1
cat = spy[0][0]
for i in range(m):
  if cat != spy[i][0]:
    cat += 1
    num = 1
  sspy[spy[i][2]] = "0" * (6 - len(str(cat))) + str(cat) + "0" * (6 - len(str(num))) + str(num)
  num += 1

for i in range(m):
  print(sspy[i])

Submission status: Wrong Answer

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

Turm = []

num  = []

for i in range(N):
    num.append([])

for i in range(M):
    n,v = map(int,input().split())
    Turm.append((n,v))
    num[n-1].append(v)
for i in range(N):
    num[i].sort()
for n,v in Turm:
    print('00000'+str(n)[-6::],'00000'+str(num[n-1].index(v)+1)[-6::])

Submission status: Wrong Answer

Solution code:
n,m = map(int,input().split())
pre = [[] for _ in range(n)]
num=[]
for i in range(m):
    p,y = map(int,input().split())
    pre[p-1].append([i,y])
for i in range(n):
    pre[i].sort(key=lambda x:x[1])
    for j in range(len(pre[i])):
        num.append([pre[i][j][0],('0'*5+str(i+1))[:6]+('0'*5+str(j+1))[:6]])
num.sort(key=lambda x:x[0])
for k in num:
    print(k[1])

Submission status: Wrong Answer

Solution code:
import bisect
def zaatu(a):
    b=list(set(a))
    for i in range(len(a)):
        a[i]=bisect.bisect_left(b,a[i])
    return a
n,m=map(int,input().split())
a=[[] for _ in range(n)]
b=[]
for i in range(m):
    p,y=map(int,input().split())
    a[p-1].append([p,y,i])
for i in range(n):
    a[i].sort(key=lambda x:x[1])
for i in range(n):
    for j in range(len(a[i])):
        b.append([a[i][j],j+1])
b.sort(key=lambda x:x[0][2])
print(b)
for i in b:
    print('0'*(6-len(str(i[0][0])))+str(i[0][0])+'0'*(6-len(str(i[1])))+str(i[1]))

Submission status: Wrong Answer

Solution code:
def main():
  n, m = map(int, input().split())
  def zs(num):
    k = 6 - len(str(num))
    return '0' * k + str(num)
  lst = [[-1] for i in range(n + 1)]
  cities = []
  for i in range(m):
    temp = tuple(map(int, input().split()))
    lst[temp[0]].append(temp[1])
    cities.append(temp)
  for l in lst:
    l.sort()
  print(lst)
  for tpl in cities:
    a = lst[tpl[0]].index(tpl[1])
    print(zs(tpl[0]) + zs(a))
if __name__ == '__main__':
  main()

Submission status: Wrong Answer

Solution code:
def get_(i):
    zero_len = 6-len(str(i))
    return '0'*zero_len+str(i)

N,M = list(map(int,input().split()))
N_list=[[] for n in range(N)]
M_list=[]

for m in range(M):
    P,Y=list(map(int,input().split()))
    N_list[P-1].append(Y)
    M_list.append([P,Y])
    
for n in N_list:
    n.sort()
    
for m in M_list:
    p=get_(m[0])
    
    
    print(p)

Submission status: Wrong Answer

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

for m in range(M):
    P,Y=list(map(int,input().split()))
    N_list[P-1].append(Y)
    
for n in N_list:
    n.sort()

Submission status: Wrong Answer

Solution code:
from bisect import bisect_left
import heapq

def solve():
    N,M = map(int, input().split())
    cities_in_prefecture = [[] for _ in range(N)]
    city_ids = []
    PYs = []
    for _ in range(M):
        P,Y = map(int, input().split())
        PYs.append((P,Y))
        heapq.heappush(cities_in_prefecture[P-1], Y)
    for P, Y in PYs:
        x = bisect_left(cities_in_prefecture[P-1], Y)
        print('{0:06d}{1:06d}'.format(P, x+1), flush=True)
        
solve()

Submission status: Wrong Answer

Solution code:
from bisect import bisect_left
import heapq

def solve():
    N,M = map(int, input().split())
    cities_in_prefecture = [[] for _ in range(N)]
    city_ids = []
    for _ in range(M):
        P,Y = map(int, input().split())
        x = bisect_left(cities_in_prefecture[P-1], Y)
        heapq.heappush(cities_in_prefecture[P-1], Y)
        print('{0:06d}{1:06d}'.format(P, x+1), flush=True)
        
solve()

Submission status: Wrong Answer

Solution code:
from collections import defaultdict
n, m = map(int, input().split())
order = []
dd = defaultdict(int)

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

# 全体を年代順にソート
order.sort(key=lambda x: (x[2]))
ans = []
for ii, pp, yy in order:
    dd[pp] += 1
    ans.append('{:0>6}{:0>6}'.format(pp, dd[pp]))

print('\n'.join(ans))

Submission status: Wrong Answer

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

# 市番号
order = []
pre = [[0] for _ in range(n + 1)]

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

# 各県ごとにソート
for i in range(n + 1):
    pre[p].sort()

# 市番号順に，各県の何番目かをにぶたんで探す
for pp, year in order:
    print('{:0>6}'.format(pp) +
          '{:0>6}'.format(bisect.bisect_left(pre[pp], year)))

Submission status: Wrong Answer

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

# 市番号
order = []
pre = [[0] for _ in range(n + 1)]

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

# 各県ごとにソート
for i in range(n + 1):
    pre[p].sort()

# 市番号順に，各県の何番目かをにぶたんで探す

Submission status: Wrong Answer

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

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

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

prev_p, i = PY[0][0], PY[0][2]
out = [None] * len(PY)
out[i] = str(prev_p).zfill(6) + str(1).zfill(6)

cnt = 1
for p, _, idx in PY[1:]:
    if p != prev_p:
        cnt = 0

    cnt += 1
    prev = p
    out[idx] = str(p).zfill(6) + str(cnt).zfill(6)


for x in out:
    print(x)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
N,M = map(int,input().split())
#P = [list(map(int,input().split())) for i in range(M)]
D = [[] for i in range(N)]
#print(P.sort())
for i in range(M):
    p,y = map(int,input().split())
    D[p-1].append((y,i))
    

#D = [[(32,0),(12,2)],[(63,1)]]
#print(D)
submit = [0]*M
for i,d in enumerate(D):
    #print(d)
    d.sort()
    #print(i,d)
    for k, (y,j) in enumerate(d):
        #print(k,y,j)
        submit[j] = str(i+1).zfill(6)+str(k+1).zfill(6)
        
print(submit)
print(*submit,sep = '\n')

Submission status: Wrong Answer

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

A = [[] for _ in range(N+1)]

for i, py in enumerate(PY):
    A[py[0]].append([py[1], i])

City = []
for i in range(N+1):
    A[i] = sorted(A[i])
    for j, a in enumerate(A[i]):
        pref = i
        city = j
        City.append([a[1], str(pref).zfill(6) + str(city).zfill(6)])

City = sorted(City)
for city in City:
    print(city[1])

Submission status: Wrong Answer

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


def solve(N: int, M: int, P: "List[int]", Y: "List[int]"):
    tuple = list(zip(P, Y, [i for i in range(M)]))
    tuple.sort()
    numbers = [0 for _ in range(M)]
    index = 0
    pre = tuple[0][0]
    for t in tuple:
        if pre != t[0]:
            index = 0
        index += 1
        numbers[t[2]] = f"{str(t[0]).zfill(6)}{str(index).zfill(6)}"
    for n in numbers:
        print(n)
    return


# Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    M = int(next(tokens))  # type: int
    P = [int()] * (M)  # type: "List[int]"
    Y = [int()] * (M)  # type: "List[int]"
    for i in range(M):
        P[i] = int(next(tokens))
        Y[i] = int(next(tokens))
    solve(N, M, P, Y)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

ids=[]

import heapq
import bisect

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

for i in range(n):
    heapq.heapify(arr[i])

for _ in range(m):
    p,y=map(int,input().split())
    ids.append([p,y])

    heapq.heappush(arr[p-1],y)

for info in ids:
    index = bisect.bisect_left(arr[info[0]-1],info[1])

    print(str(info[0]).zfill(6)+str(index+1).zfill(6))

Submission status: Wrong Answer

Solution code:
import sys
from io import StringIO
import unittest
import os

# 再帰処理上限(dfs作成時に設定するのが面倒なので限度近い値を組み込む)
sys.setrecursionlimit(999999999)


# 実装を行う関数
def resolve(test_def_name=""):
    # 数値取得サンプル
    #   1行1項目 n = int(input())
    #   1行2項目 x, y = map(int, input().split())
    #   1行N項目 x = list(map(int, input().split()))
    #   N行1項目 x = [int(input()) for i in range(n)]
    #   N行N項目 x = [list(map(int, input().split())) for i in range(n)]

    # 文字取得サンプル
    #   1行1項目 x = input()
    #   1行1項目(1文字ずつリストに入れる場合) x = list(input())
    n, m = map(int, input().split())
    py_s = [list(input().split()) for i in range(m)]

    num = 0
    city = ""
    numdict = {}

    for i in sorted(py_s, key=lambda x: [x[0], x[1]]):
        if city != i[0]:
            city = i[0]
            num = 0
        num += 1
        numdict[i[1]] = "".join([i[0].zfill(6), format(num, '06')])

    for i in py_s:
        print(numdict[i[1]])


# テストクラス
class TestClass(unittest.TestCase):
    def assertIO(self, assert_input, output):
        stdout, sat_in = sys.stdout, sys.stdin
        sys.stdout, sys.stdin = StringIO(), StringIO(assert_input)
        resolve(sys._getframe().f_back.f_code.co_name)
        sys.stdout.seek(0)
        out = sys.stdout.read()[:-1]
        sys.stdout, sys.stdin = stdout, sat_in
        self.assertEqual(out, output)

    def test_input_1(self):
        test_input = """2 3
1 32
2 63
1 12"""
        output = """000001000002
000002000001
000001000001"""
        self.assertIO(test_input, output)

    def test_input_2(self):
        test_input = """2 3
2 55
2 77
2 99"""
        output = """000002000001
000002000002
000002000003"""
        self.assertIO(test_input, output)

    # 自作テストパターンのひな形(利用時は「tes_t」のアンダーバーを削除すること
    def test_original1(self):
        test_input = """100000 3
100000 1000000000‬
2 77
2 99
"""
        output = """100000000001
000002000001
000002000002"""
        self.assertIO(test_input, output)

    # 自作テストパターンのひな形(利用時は「tes_t」のアンダーバーを削除すること
    def t_est_original2(self):
        test_input = """4 1
1 20
"""
        output = """000001000001"""
        self.assertIO(test_input, output)


# 実装orテストの呼び出し
if __name__ == "__main__":
    if os.environ.get("USERNAME") is None:
        # AtCoder提出時の場合
        resolve()

    else:
        # 自PCの場合
        unittest.main()

Submission status: Wrong Answer

Solution code:
import sys
from io import StringIO
import unittest
import os

# 再帰処理上限(dfs作成時に設定するのが面倒なので限度近い値を組み込む)
sys.setrecursionlimit(999999999)


# 実装を行う関数
def resolve(test_def_name=""):
    # 数値取得サンプル
    #   1行1項目 n = int(input())
    #   1行2項目 x, y = map(int, input().split())
    #   1行N項目 x = list(map(int, input().split()))
    #   N行1項目 x = [int(input()) for i in range(n)]
    #   N行N項目 x = [list(map(int, input().split())) for i in range(n)]

    # 文字取得サンプル
    #   1行1項目 x = input()
    #   1行1項目(1文字ずつリストに入れる場合) x = list(input())
    n, m = map(int, input().split())
    py_s = [list(input().split()) for i in range(m)]

    num = 0
    city = ""
    numdict = {}

    for i in sorted(py_s, key=lambda x: [x[0], x[1]]):
        if city != i[0].zfill(6):
            city = i[0].zfill(6)
            num = 0
        num += 1
        numdict[i[1]] = "".join([city, format(num, '06')])

    for i in py_s:
        print(numdict[i[1]])


# テストクラス
class TestClass(unittest.TestCase):
    def assertIO(self, assert_input, output):
        stdout, sat_in = sys.stdout, sys.stdin
        sys.stdout, sys.stdin = StringIO(), StringIO(assert_input)
        resolve(sys._getframe().f_back.f_code.co_name)
        sys.stdout.seek(0)
        out = sys.stdout.read()[:-1]
        sys.stdout, sys.stdin = stdout, sat_in
        self.assertEqual(out, output)

    def test_input_1(self):
        test_input = """2 3
1 32
2 63
1 12"""
        output = """000001000002
000002000001
000001000001"""
        self.assertIO(test_input, output)

    def test_input_2(self):
        test_input = """2 3
2 55
2 77
2 99"""
        output = """000002000001
000002000002
000002000003"""
        self.assertIO(test_input, output)

    # 自作テストパターンのひな形(利用時は「tes_t」のアンダーバーを削除すること
    def t_est_original1(self):
        test_input = """
"""
        output = """000001000002
000002000003
000003000001
000001000001
000002000001
000002000002"""
        self.assertIO(test_input, output)

    # 自作テストパターンのひな形(利用時は「tes_t」のアンダーバーを削除すること
    def t_est_original2(self):
        test_input = """4 1
1 20
"""
        output = """000001000001"""
        self.assertIO(test_input, output)


# 実装orテストの呼び出し
if __name__ == "__main__":
    if os.environ.get("USERNAME") is None:
        # AtCoder提出時の場合
        resolve()

    else:
        # 自PCの場合
        unittest.main()

Submission status: Wrong Answer

Solution code:
import sys
from io import StringIO
import unittest
import os

# 再帰処理上限(dfs作成時に設定するのが面倒なので限度近い値を組み込む)
sys.setrecursionlimit(999999999)


# 実装を行う関数
def resolve(test_def_name=""):
    # 数値取得サンプル
    #   1行1項目 n = int(input())
    #   1行2項目 x, y = map(int, input().split())
    #   1行N項目 x = list(map(int, input().split()))
    #   N行1項目 x = [int(input()) for i in range(n)]
    #   N行N項目 x = [list(map(int, input().split())) for i in range(n)]

    # 文字取得サンプル
    #   1行1項目 x = input()
    #   1行1項目(1文字ずつリストに入れる場合) x = list(input())
    n, m = map(int, input().split())
    py_s = [list(input().split()) for i in range(m)]

    num = 0
    city = ""
    numdict = {}

    for i in sorted(py_s, key=lambda x: [x[0], x[1]]):
        if city != i[0].zfill(6):
            city = i[0].zfill(6)
            num = 0
        num += 1
        numdict["-".join(i)] = "".join([city, format(num, '06')])

    for i in py_s:
        print(numdict["-".join(i)])


# テストクラス
class TestClass(unittest.TestCase):
    def assertIO(self, assert_input, output):
        stdout, sat_in = sys.stdout, sys.stdin
        sys.stdout, sys.stdin = StringIO(), StringIO(assert_input)
        resolve(sys._getframe().f_back.f_code.co_name)
        sys.stdout.seek(0)
        out = sys.stdout.read()[:-1]
        sys.stdout, sys.stdin = stdout, sat_in
        self.assertEqual(out, output)

    def test_input_1(self):
        test_input = """2 3
1 32
2 63
1 12"""
        output = """000001000002
000002000001
000001000001"""
        self.assertIO(test_input, output)

    def test_input_2(self):
        test_input = """2 3
2 55
2 77
2 99"""
        output = """000002000001
000002000002
000002000003"""
        self.assertIO(test_input, output)

    # 自作テストパターンのひな形(利用時は「tes_t」のアンダーバーを削除すること
    def test_original1(self):
        test_input = """4 6
1 20
2 30
3 99999999
1 10
2 10
2 20"""
        output = """000001000002
000002000003
000003000001
000001000001
000002000001
000002000002"""
        self.assertIO(test_input, output)


# 実装orテストの呼び出し
if __name__ == "__main__":
    if os.environ.get("USERNAME") is None:
        # AtCoder提出時の場合
        resolve()

    else:
        # 自PCの場合
        unittest.main()

Submission status: Wrong Answer

Solution code:
import sys
from io import StringIO
import unittest
import os

# 再帰処理上限(dfs作成時に設定するのが面倒なので限度近い値を組み込む)
sys.setrecursionlimit(999999999)


# 実装を行う関数
def resolve(test_def_name=""):
    # 数値取得サンプル
    #   1行1項目 n = int(input())
    #   1行2項目 x, y = map(int, input().split())
    #   1行N項目 x = list(map(int, input().split()))
    #   N行1項目 x = [int(input()) for i in range(n)]
    #   N行N項目 x = [list(map(int, input().split())) for i in range(n)]

    # 文字取得サンプル
    #   1行1項目 x = input()
    #   1行1項目(1文字ずつリストに入れる場合) x = list(input())
    n, m = map(int, input().split())
    py_s = [list(input().split()) for i in range(m)]

    num = 0
    city = ""
    numdict = {}

    for i in sorted(py_s, key=lambda x: [x[0], x[1]]):
        if city != i[0].zfill(6):
            city = i[0].zfill(6)
            num = 0
        num += 1
        numdict["-".join(i)] = "".join([city, format(num, '06')])

    for i in py_s:
        print(numdict["-".join(i)])


# テストクラス
class TestClass(unittest.TestCase):
    def assertIO(self, assert_input, output):
        stdout, sat_in = sys.stdout, sys.stdin
        sys.stdout, sys.stdin = StringIO(), StringIO(assert_input)
        resolve(sys._getframe().f_back.f_code.co_name)
        sys.stdout.seek(0)
        out = sys.stdout.read()[:-1]
        sys.stdout, sys.stdin = stdout, sat_in
        self.assertEqual(out, output)

    def test_input_1(self):
        test_input = """2 3
1 32
2 63
1 12"""
        output = """000001000002
000002000001
000001000001"""
        self.assertIO(test_input, output)

    def test_input_2(self):
        test_input = """2 3
2 55
2 77
2 99"""
        output = """000002000001
000002000002
000002000003"""
        self.assertIO(test_input, output)

    # 自作テストパターンのひな形(利用時は「tes_t」のアンダーバーを削除すること
    def tes_t_1original_1(self):
        test_input = """データ"""
        output = """データ"""
        self.assertIO(test_input, output)


# 実装orテストの呼び出し
if __name__ == "__main__":
    if os.environ.get("USERNAME") is None:
        # AtCoder提出時の場合
        resolve()

    else:
        # 自PCの場合
        unittest.main()

Submission status: Wrong Answer

Solution code:
# coding: utf-8
# Your code here!

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

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

now=0
p1=items[0][0]
ans=[]
for p,y,ind in items:
    
    if p==p1:
        now+=1
        tmp=str(p*10**6+now)
        tmp=(12-len(tmp))*"0"+tmp
        
        ans.append((ind,tmp))
    else:
        now=1
        tmp=str(p*10**6+now)
        tmp=(12-len(tmp))*"0"+tmp
        ans.append((ind,tmp))
        
ans.sort()
for _ , j in ans:
    print(j)

Submission status: Wrong Answer

Solution code:
import sys, re
from math import ceil, floor, sqrt, pi, factorial, gcd
from copy import deepcopy
from collections import Counter, deque
from heapq import heapify, heappop, heappush
from itertools import accumulate, product, combinations, combinations_with_replacement
from bisect import bisect, bisect_left
from functools import reduce
from decimal import Decimal, getcontext
# input = sys.stdin.readline 
def i_input(): return int(input())
def i_map(): return map(int, input().split())
def i_list(): return list(i_map())
def i_row(N): return [i_input() for _ in range(N)]
def i_row_list(N): return [i_list() for _ in range(N)]
def s_input(): return input()
def s_map(): return input().split()
def s_list(): return list(s_map())
def s_row(N): return [s_input for _ in range(N)]
def s_row_list(N): return [s_list() for _ in range(N)]
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
def lcm(a, b): return a * b // gcd(a, b)
sys.setrecursionlimit(10 ** 6)
INF = float('inf')
MOD = 10 ** 9 + 7
num_list = []
str_list = []

def main():
    n, m = i_map()
    for i in range(m):
        p, y = i_map()
        num_list.append([p, y, i])

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

    ans_list = []
    count_index = 0
    for num in sorted_data:
        if count_index != num[0]:
            count_index = num[0]
            count_num = 1
        else:
            count_num += 1
        ans_num = str(num[0]).zfill(6) + str(count_num).zfill(6)
        ans_list.append([num[2], ans_num])

    ans_list.sort()

    for ans in ans_list:
        print(ans[1])
 
if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
n,m=map(int,input().split())
pre=[[] for _ in range(n)]
for _ in range(m):
    p,y=map(int,input().split())
    pre[p-1].append([y,_,p])
for p in range(n):
    pre[p].sort(key=lambda x:x[0])
    for i in range(len(pre[p])):
        pre[p][i].append(i)
lis=[]
for i in pre:
    for j in i:
        lis.append(j)
lis.sort(key=lambda x:x[1])
for i in lis: print("{:06}{:06}".format(i[3]+1,i[2]))

Submission status: Wrong Answer

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

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

city_count = [0]*(N+1)
for p, y in PY:
    city_count[p] += 1
for ken, count in enumerate(city_count):
    [print(str(1*10**12+ken*10**6+i)[1:]) for i in range(1,count+1)]

Submission status: Wrong Answer

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

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

city_count = [0]*(N+1)
for p, y in PY:
    city_count[p] += 1
for ken, count in enumerate(city_count):
    [print(str(1*10**12+ken*10**6+count)[1:]) for i in range(1,count+1)]

Submission status: Wrong Answer

Solution code:
n,m = map(int,input().split())
pyl = [list(map(int,input().split())) for nesya in range(m)]
predic = dict()
pyl = sorted(pyl,key = lambda x:x[1])
for py in pyl:
  p = py[0]
  if p in predic:
    predic[p] += 1
  else:
    predic[p] = 1
  print((str(p).zfill(6))+(str(predic[p]).zfill(6)))

Submission status: Wrong Answer

Solution code:
dict={}
dict2={}
n,m=map(int,input().split())
for i in range(m):
	p,m=map(int,input().split())
	dict[i]=[p,m]
	if p not in dict2:
		dict2[p]=[m]
	else:
		dict2[p].append(m)
dict2[p].sort()
for d in dict:
	a='{:0=6}'.format(dict[d][0])
	c=(dict2[dict[d][0]]).index(dict[d][1])+1
	c='{:0=6}'.format(c)
	print(a+c)

Submission status: Wrong Answer

Solution code:
import bisect

def main():
    n, m = map(int, input().split())
    py = [list(map(int, input().split())) for _ in range(m)]
    x = [[0] for _ in range(n+1)]
    for p, y in py:
        x[p].append(y)
    for i in range(n):
        x[i] = sorted(x[i])
    for p, y in py:
        num = x[p].index(y)
        print('{:0=6}{:0=6}'.format(p, num))
         
    
if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
N, M = map(int, input().split())
city = [input().split() for i in range(M)]
city_sorted = sorted(city, key=lambda x: (x[0],x[1]))

for i in range(M):
    A = city_sorted.index(city[i]) + 1
    pre = ['0', '0', '0', '0', '0', '0']
    C = ['0', '0', '0', '0', '0', '0']
    print(''.join((pre+list(city[i][0]))[-6:]+ (C+list(str(A)))[-6:]))

Submission status: Wrong Answer

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

i=0
for c in py:
    c.append(i)
    i+=1


ans=[[0,""] for _ in range(m)]

py.sort()

precity=py[0][0]
i=0
j=1
for city in py:
    if city[0]==precity:
        ans[i][1]=str(city[0]).zfill(6)+str(j).zfill(6)
        ans[i][0]=city[2]
        j+=1
        i+=1
    else:
        j=1
        ans[i][0]=city[2]
        ans[i][1]=str(city[0]).zfill(6)+str(j).zfill(6)
        i+=1
ans.sort()
for i in range(m):
    print(ans[i][1])

Submission status: Wrong Answer

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

for i in range(m):
    p, y = input().split()
    l.append([p, y, i])

l.sort()

l[0][1] = 1

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

sortthird = lambda val: val[2]
l.sort(key = sortthird)

for i in l:
    ans = "0"*(6 - len(i[0])) + i[0] + "0"*(6 - len(str(i[1]))) + str(i[1])
    print(ans)

Submission status: Wrong Answer

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

for i in range(m):
    p, y = input().split()
    l.append([p, y, m])

l.sort()

l[0][1] = 1

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

sortthird = lambda val: val[2]
l.sort(key = sortthird)


for i in l:
    ans = "0"*(6 - len(i[0])) + i[0] + "0"*(6 - len(str(i[1]))) + str(i[1])
    print(ans)

Submission status: Wrong Answer

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

for i in range(m):
    p, y = input().split()
    l.append([p, y])

l.sort()

l[0][1] = 1

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

for i in l:
    ans = "0"*(6 - len(i[0])) + i[0] + "0"*(6 - len(str(i[1]))) + str(i[1])
    print(ans)

Submission status: Wrong Answer

Solution code:
from operator import itemgetter

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


A = sorted(A,key=itemgetter(1),reverse = False)
A = sorted(A,key=itemgetter(0),reverse = False)

pref = 0
city = 0
B = []
for i in range(M):
    if A[i][0] != pref:
        pref += 1
        city = 1 
        B.append([A[i][0],A[i][2],str(A[i][0]).rjust(6, '0') , str(city).rjust(6, '0')])
    else:
        city+=1
        B.append([A[i][0],A[i][2],str(A[i][0]).rjust(6, '0') , str(city).rjust(6, '0')])
B = sorted(B,key=itemgetter(1),reverse = False)

for i in range(M):
    print(B[i][2] +B[i][3] )

Submission status: Wrong Answer

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

from operator import itemgetter
PY= sorted(PY,key=itemgetter(1),reverse = False)
PY = sorted(PY,key=itemgetter(0),reverse = False)

B= []
pre = 0
city = 1
for i in range(M):
    if pre != PY[i][0]:
        pre =  PY[i][0]
        #B.append([pre,1,PY[i][2]])
        B.append([str(pre).rjust(6, '0') + str(1).rjust(6, '0') ,PY[i][2]])
        city += 1
    else:
        #B.append([pre,city,PY[i][2]])
        B.append([str(pre).rjust(6, '0') + str(city).rjust(6, '0') ,PY[i][2]])
        city += 1

B= sorted(B,key=itemgetter(1),reverse = False)        
for i in range(M):
    print(B[i][0])

Submission status: Wrong Answer

Solution code:
from collections import defaultdict

n, m = map(int, input().split())
PY = [tuple(map(int, input().split())) for _ in range(m)]
sorted_PY = sorted(PY)
cnt = 1
now = sorted_PY[0][0]
d = defaultdict(int)
for p, y in sorted_PY:
    if now != p:
        cnt = 1
    d[y] = (p, cnt)
    cnt += 1

for p, y in PY:
    l, r = map(str, d[y])
    if len(l) < 6:
        light = '0'*(6-len(l)) + str(l)
    else:
        light = str(l)
    if len(r) < 6:
        right = '0'*(6-len(r)) + str(r)
    else:
        right = str(r)
    print(light+right)

Submission status: Wrong Answer

Solution code:
from collections import defaultdict
n, m = map(int, input().split())

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

for i in range(1, n + 1):
    tmp = d[i]
    tmp.sort(key=lambda x: x[1])
    for i, j in enumerate(tmp):
        j.append(i + 1)

ans = []
for a, b in d.items():
    for i in b:
        i.append(a)
        ans.append(i)

for _, _, c, p in sorted(ans):
    len_p = p // 10 + 1
    len_c = c // 10 + 1
    print("0" * (6 - len_p) + str(p) + "0" * (6 - len_c) + str(c))

Submission status: Wrong Answer

Solution code:
N, M = map(int, input().split())
result = []
count = 1
for i in range(M):
  P, Y = map(int, input().split())
  result.append([P, Y, i])
result = sorted(result, key=lambda x:x[0] and x[1])
for i in range(len(result)):
  if i == len(result)-1:
    result[i].append(str(result[i][0]).zfill(6) + str(count).zfill(6))
    continue
  if i == 0:
    result[i].append(str(result[i][0]).zfill(6) + str(count).zfill(6))
    count += 1
  elif result[i][0] == result[i+1][0]:
    result[i].append(str(result[i][0]).zfill(6) + str(count).zfill(6))
    count += 1
  else:
    if count > 1:
      result[i].append(str(result[i][0]).zfill(6) + str(count).zfill(6))
      count = 1
    else:
      result[i].append(str(result[i][0]).zfill(6) + str(count).zfill(6))
result = sorted(result, key=lambda x: x[2])
for i in range(len(result)):
  print(result[i][3])