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())
G=[]
for _ in range(m):
  p,y=map(int,input().split())
  G.append([p,y,_])
  
G.sort(key=lambda x:x[0])
G.sort(key=lambda x:x[1])
p=G[0][0]
cnt=0
A=[None]*m
for i in range(m):
  if p<G[i][0]:
    p+=1
    cnt=1
  else:
    cnt+=1
  P=str(p).zfill(6)
  Y=str(cnt).zfill(6)
  A[G[i][2]]=P+Y

for a in A:
  print(a)

Submission status: Wrong Answer

Solution code:
if __name__ == '__main__':
    N, M = map(int, input().split())
    PY = []
    for i in range(1, M+1):
        p, y = map(int, input().split())
        PY.append((y, p, i))
    PY.sort()
    ANS = [""]*(M+1)
    P = [0]*(N+1)
    for y, p, i in PY:
        P[p] += 1
        print(y, p, i)
        ANS[i] = "{0:06d}".format(p) + "{0:06d}".format(P[p])
    
    for ans in ANS:
        if ans=="": continue
        print(ans)

Submission status: Wrong Answer

Solution code:
n,m = map(int,input().split())
l = [[] for i in range(m)]
for i in range(m):
    a,b = map(int,input().split())
    l[i] = [a,b,i]
l = list(sorted(l,key=lambda x: x[0]))
ans = [[] for i in range(m)]
x = 0
y = 1
for i in range(m):
    if x != l[i][0]:
        x = l[i][0]
        y = 1
    else:
        y += 1
    a = str(x).zfill(6)
    b = str(y).zfill(6)
    ans[i] = [a+b,l[i][2]]
ans = list(sorted(ans,key=lambda x: x[1]))
for i in range(m):
    print(ans[i][0])

Submission status: Wrong Answer

Solution code:
n,m = map(int,input().split())
l = [[] for i in range(m)]
for i in range(m):
    a,b = map(int,input().split())
    l[i] = [a,b,i]
l = list(sorted(l,key=lambda x: x[1]))
ans = [[] for i in range(m)]
x = 0
y = 0
for i in range(m):
    if x != l[i][0]:
        x = l[i][0]
        y = 1
    else:
        y += 1
    a = str(x).zfill(6)
    b = str(y).zfill(6)
    ans[i] = [a+b,l[i][2]]
ans = list(sorted(ans,key=lambda x: x[1]))
for i in range(m):
    print(ans[i][0])

Submission status: Wrong Answer

Solution code:
def main():
    # n = int(input())
    n, m = map(int, input().split())
    # v = list(map(int, input().split()))
    # s = input()
    py = []
    for i in range(m):
        p, y = map(int, input().split())
        py.append([i, p, y])
    print(py)

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

    num = 1
    for i in range(0, m):
        if i == 0:
            py[i].append(num)
        else:
            if py[i][1] == py[i-1][1]:
                num += 1
            else:
                num = 1
            py[i].append(num)
    print(py)

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

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


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import math
from math import gcd,pi,sqrt
INF = float("inf")

import sys
sys.setrecursionlimit(10**6)
import itertools
from collections import Counter,deque
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_str(N): return [s_list() for _ in range(N)]
def s_row_list(N): return [list(s_input()) for _ in range(N)]

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

    l.sort(key = lambda x :(x[1], x[2]))
    ken = l[0][1]
    cnt = 1
    for i in l:
        if i[1] == ken:
            i[3] = cnt
            cnt += 1
        else:
            i[3] = 1
            cnt = 2
    l.sort(key = lambda x:x[0])

    ans = []
    for i in l:
        ans.append(str(i[1]).zfill(6) + str(i[3]).zfill(6))
    for i in ans:
        print(i)

if __name__=="__main__":
    main()

Submission status: Wrong Answer

Solution code:
def make_code(prifacture_num, city_num):
    s1 = str(prifacture_num)
    while len(s1) != 6:
        s1 = '0' + s1
    s2 = str(city_num)
    while len(s2) != 6:
        s2 = '0' + s2
    return s1 + s2


prifacture_cnt, city_cnt = map(int, input().split())
data = [list(map(int, input().split())) for i in range(city_cnt)]
city_data = []

for i in range(city_cnt):
    city_data.append([data[i][0], data[i][1], i])

city_data.sort()
city_code = []
prifacture = city_data[0][0]
cnt = 1
for city in city_data:
    if prifacture == city[0]:
        s = make_code(prifacture, cnt)
        city_code.append([city[2], s])
        cnt += 1
    else:
        cnt = 1
        prifacture = city[0]
        s = make_code(prifacture, cnt)
        city_code.append([city[2], s])

city_code.sort()
for num,code in city_code:
    print(code)

Submission status: Wrong Answer

Solution code:
# ABC113 D 

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

P=[[] for _ in [0]*(N+1)]

for i in range(M):
    p,y=map(int,input().split())
    P[p].append((y,i))
    
from bisect import bisect_left as bl

res=[]
for p in range(N+1):
    Y=P[p][:]
    if not Y:
        continue
    
    sortY=sorted(list(set([y for y,i in Y])))

    zatY=[]
    for y,i in Y:
        zatY.append(bl(sortY,y))
    
    for index in zatY:
        y,i=Y[index]
        num=10**12+p*10**6+index+1
        res.append((str(num)[1:],i))

res=[y for y,i in sorted(res,key=lambda x:x[1])]
print(*res,sep='\n')

Submission status: Wrong Answer

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

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

sorted_cities = sorted(cities, key=lambda x: (x[0], x[1]))
print(sorted_cities)
cnt = 1
ans = []
for i in range(m-1):
    p_id = str(sorted_cities[i][0]).rjust(6, '0')
    c_id = str(cnt).rjust(6, '0')
    ans.append([sorted_cities[i][2], p_id+c_id])
    if sorted_cities[i][0] != sorted_cities[i+1][0]:
        cnt = 1
    else:
        cnt += 1

p_id = str(sorted_cities[m-1][0]).rjust(6, '0')
c_id = str(cnt).rjust(6, '0')
ans.append([sorted_cities[m-1][2], p_id+c_id])
ans.sort()

for id in ans:
    print(id[1])

Submission status: Wrong Answer

Solution code:
import heapq


def make_ans(str1, str2):
    while len(str1) < 6:
        str1 = '0' + str1
    while len(str2) < 6:
        str2 = '0' + str2
    return str1 + str2


n, m = map(int, input().split())
ken = [[] for _ in range(n + 1)]
for i in range(1, n + 1):
    heapq.heapify(ken[i])
memo = []
for i in range(1, m + 1):
    p, y = map(int, input().split())
    heapq.heappush(ken[p], y)
    memo.append((p, y))
for q in memo:
    ans_left = str(q[0])
    begin = 0
    end = len(ken[q[0]]) - 1
    ans_index = -1
    while True:
        mid = (end + begin) // 2
        if ken[q[0]][mid] > q[1]:
            end = mid
        elif ken[q[0]][mid] < q[1]:
            begin = mid
        else:
            ans_index = mid
            break
        if ken[q[0]][end] == q[1]:
            ans_index = end
            break
        elif ken[q[0]][begin] == q[1]:
            ans_index = begin
            break
    ans_right = str(ans_index + 1)
    print(make_ans(ans_left, ans_right))

Submission status: Wrong Answer

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

#p = [-1]*m
#y = [-1]*m
ipy=[]

for i in range(m):
    ipy.append(list(map(int,(str(i) + " " + input()).split())))


print(ipy)

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

print(ipy)

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

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

for i in range(m):
    print(f'{ipy[i][1]:06}'+f'{ipy[i][2]:06}')

Submission status: Wrong Answer

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

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

a = P[0][0]
c = 0
for i in range(M):
    #print(P[i])
    if P[i][0] == a:
        c += 1
        P[i].append(c)
    else:
        c = 1
        a = P[i][0]
        P[i].append(c)
    print(P[i])

P = sorted(P, key = lambda x: x[2])
for i in range(M):
    s = str(P[i][0]).zfill(6)
    ss = str(P[i][3]).zfill(6)
    print(s + ss)

Submission status: Wrong Answer

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

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

a = P[0][0]
c = 0
for i in range(M):
    if P[i][0] == a:
        c += 1
        P[i].append(c)
    else:
        c = 1
        P[i].append(c)

P = sorted(P, key = lambda x: x[2])
for i in range(M):
    s = str(P[i][0]).zfill(6)
    ss = str(P[i][3]).zfill(6)
    print(s + ss)

Submission status: Wrong Answer

Solution code:
def main():
    import bisect
    n,m = map(int,input().split())
    d = [[] for i in range(n)]
    ans = [0 for i in range(m)]
    for i in range(m):
        p,y = map(int,input().split())
        d[p-1].append((y,i))
    for i,d_ in enumerate(d):
        d_.sort()
        for c, d__ in enumerate(d_):
            ans[d__[1]-1] = str(i+1).zfill(6) + str(c+1).zfill(6)
    for i in range(m):
        print(ans[i])

if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
def main():
    import bisect
    n,m = map(int,input().split())
    ids = [0 for i in range(m)]
    his = [[] for i in range(n)]
    city = [[] for i in range(n)]
    for i in range(m):
        p,y = map(int,input().split())
        ids[i] = p
        b = bisect.bisect_right(city[p-1],y)
        city[p-1].insert(b,y)
        his[p-1].insert(b,len(his[p-1]))
    c = [0 for i in range(n)]
    for i in range(m):
        nm = his[ids[i]-1][c[ids[i]-1]] + 1
        print(str(0) * (6 - len(str(ids[i])))+ str(ids[i])+str(0) * (6-len(str(nm))) + str(nm))
        c[ids[i]-1]+=1

if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
def main():
    import bisect
    n,m = map(int,input().split())
    ids = [0 for i in range(m)]
    his = [[] for i in range(n)]
    city = [[] for i in range(n)]
    for i in range(m):
        p,y = map(int,input().split())
        ids[i] = p
        b = bisect.bisect_right(city[p-1],y)
        city[p-1].insert(b,y)
        his[p-1].insert(b,len(his[p-1]))
    print(ids,city,his)
    c = [0 for i in range(n)]
    for i in range(m):
        nm = his[ids[i]-1][c[ids[i]-1]] + 1
        print(str(0) * (6 - len(str(ids[i])))+ str(ids[i])+str(0) * (6-len(str(nm))) + str(nm))
        c[ids[i]-1]+=1

if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
from sys import stdin

n,m = map(int,input().split())
cities = [list(map(int,stdin.readline().split())) + [i] for i in range(m)]
for i in range(m):
    cities[i][0] -= 1
state = [[] for i in range(n)]
for i in cities:
    state[i[0]].append([i[1],i[2]])
for i in range(n):
    state[i].sort()
ans = []
for i in range(n):
    temp = "0"*(6-len(str(i))) + str(i+1)
    for j in range(len(state[i])):
        s = temp + "0"*(6-len(str(j))) + str(j+1)
        ans.append([state[i][j][1],s])
ans.sort()
for i in ans:
    print(i[1])

Submission status: Wrong Answer

Solution code:
import sys
import math
import itertools
import collections
from collections import deque
from collections import defaultdict

sys.setrecursionlimit(1000000)
MOD = 10 ** 9 + 7
MOD2 = 998244353
INF = float('inf')
input = lambda: sys.stdin.readline().strip()

NI = lambda: int(input())
NMI = lambda: map(int, input().split())
NLI = lambda: list(NMI())
SI = lambda: input()

def main():

    N, M = NMI()
        
    PY = [[m,NLI()] for m in range(M)]
    
    PY = list(sorted(list(sorted(PY,key = lambda x : x[1][0])),key = lambda x : x[1][1]))
    
    city = PY[0][1][0]
    cnt = 0

    for m in range(M):
        if PY[m][1][0] == city:
            cnt += 1
        else:
            city = PY[m][1][0]
            cnt = 1
            
        PY[m][1] = str(PY[m][1][0]).zfill(6) + str(cnt).zfill(6)
    
    PY = list(sorted(PY))
    for m in range(M):
        print(PY[m][1])


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import sys;      from decimal import Decimal
import math;     from itertools import combinations, product
import bisect;   from collections import Counter, deque, defaultdict

# sys.setrecursionlimit(10 ** 6)
MOD = 10 ** 9 + 7
INF = 10 ** 9
PI = 3.14159265358979323846

def read_str():      return sys.stdin.readline().strip()
def read_int():      return int(sys.stdin.readline().strip())
def read_ints():     return map(int, sys.stdin.readline().strip().split())
def read_str_list(): return list(sys.stdin.readline().strip().split())
def read_int_list(): return list(map(int, sys.stdin.readline().strip().split()))
def lcm(a: int, b: int) -> int: return (a * b) // math.gcd(a, b)

def Main():
    n, m = read_ints()
    py = []
    for i in range(m):
        p, y = read_ints()
        py.append([y, p, i])
    py.sort(key=lambda x: x[0])  
    cnt = [0] * n
    
    for year, prefecture, idx in py:
        cnt[prefecture - 1] += 1
        print(f'{prefecture:06d}{cnt[prefecture-1]:06d}')

if __name__ ==  '__main__':
    Main()

Submission status: Wrong Answer

Solution code:
import numpy as np

def print_info(x,y):
  zero = "000000"
  city = str(x)
  txt_c = zero[0:6-len(city)] + city
  rank = str(y)
  txt_y = zero[0:6-len(rank)] + rank
  print(txt_c + txt_y)

line = [int(i) for i in input().rstrip().split()]
N = line[0]
M = line[1]
L = [[] for i in range(N)]
info_M = [[] for i in range(M)]
for i in range(M):
  line = [int(i) for i in input().rstrip().split()]
  num_c = line[0]
  num_y = line[1]
  info_M[i].append(num_c)
  info_M[i].append(num_y)
  L[num_c-1].append(num_y)
  
for i in range(N):
  L[i].sort
  
for i in range(M):
  num_c = info_M[i][0]
  num_y = info_M[i][1]
  pos = L[num_c-1].index(num_y)+1
  print_info(num_c, pos)

Submission status: Wrong Answer

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

li = []
for i,j in enumerate(L):
    li.append(j+[i])
li.sort(key = lambda x:(x[0],x[1]))
li.append([0,0,0])

k,r = li[0][0],1
for i in range(m):
    if li[i][0] == k:
        if li[i+1][1] == li[i][1]:
            li[i][1] = r
            li[i+1][1] = r
        else:
            li[i][1] = r
            r +=1
    else:
        k = li[i][0]
        r = 1
        li[i][1] = r
li.pop()
li.sort(key = lambda x:x[2])

for i in range(m):
    print("{:06d}".format(li[i][0])+"{:06d}".format(li[i][1]))

Submission status: Wrong Answer

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

li = []
for i,j in enumerate(L):
    li.append(j+[i])
li.sort(key = lambda x:(x[0],x[1]))

k,r = li[0][0],1
for i in range(m):
    if li[i][0] == k:
        li[i][1] = r
        r +=1
    else:
        k = li[i][0]
        r = 1
        li[i][1] = r
li.sort(key = lambda x:x[2])

for i in range(m):
    print("{:06d}".format(li[i][0])+"{:06d}".format(li[i][1]))

Submission status: Wrong Answer

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

li = []
for i,j in enumerate(L):
    li.append(j+[i])
li.sort(key = lambda x:(x[0],x[1]))

k,r = li[0][0],1
for i in range(m):
    if li[i][0] == k:
        li[i][1] = r
        r +=1
    else:
        k +=1
        r = 1
        li[i][1] = r
li.sort(key = lambda x:x[2])

for i in range(m):
    print("{:06d}".format(li[i][0])+"{:06d}".format(li[i][1]))

Submission status: Wrong Answer

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

li = []
for i,j in enumerate(L):
    li.append(j+[i])
li.sort()

i = 1
ans = []
while i <= n:
    l = []
    for j in range(m):
        if li[j][0] == i:
            l.append(li[j])
    l.sort(key = lambda x:x[1])
    for k,v in enumerate(l):
        l[k][1] = k+1
    ans += l
    i +=1
ans.sort(key = lambda x:x[2])

for i in range(m):
    print("{:06d}".format(ans[i][0]),"{:06d}".format(ans[i][1]))

Submission status: Wrong Answer

Solution code:
n,m = map(int,input().split())
py = [[i+1]+list(map(int,input().split())) for i in range(m)]
pysort = sorted(py,key=lambda x:(x[1],x[2]))
j = 1
cnt = 0
for i in range(m):
    if pysort[i][1] == j:
        cnt += 1
        #pysort[i] += [f"{pysort[i][1]}:{cnt}"]
        pysort[i] += [str(pysort[i][1]).zfill(6)+str(cnt).zfill(6)]
    else:
        cnt = 1
        j += 1
        #pysort[i] += [f"{pysort[i][1]}:{cnt}"]
        pysort[i] += [str(pysort[i][1]).zfill(6)+str(cnt).zfill(6)]

pysortsort = sorted(pysort,key=lambda x:x[0])
[print(a[3]) for a in pysortsort]

Submission status: Wrong Answer

Solution code:
N, M = map(int, input().split())
pairs = []
ys = {}

for i in range(M):
  p, y = map(int, input().split())
  pairs.append((p, y))
  if p not in ys:
    ys[p] = [y]
  else:
    ys[p].append(y)

for p, y in pairs:
  sorted(ys[p])
  ID = str(p).rjust(6, "0")
  n = ys[p].index(y) + 1
  ID += str(n).rjust(6, "0")
  print(ID)

Submission status: Wrong Answer

Solution code:

n,m = map(int, input().split())
pyl = [ [] for _ in range(n+1) ]

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

ans = ['']*m
for p, yil in enumerate(pyl):
    top = str(p).zfill(6)
    yil.sort()
    for order,(y,i) in enumerate(yil):
        print(order,i)
        bottom = order+1
        bottom = str(bottom).zfill(6)
        ans[i] = top+bottom

for a in ans:
    print(a)

Submission status: Wrong Answer

Solution code:
import sys
from collections import deque


stdin = sys.stdin
def ns(): return stdin.readline().rstrip()
def ni(): return int(stdin.readline().rstrip())
def nm(): return map(int, stdin.readline().split())
def nl(): return list(map(int, stdin.readline().split()))


def main():
    n, m = nm()
    Y = [[] for _ in range(n)]
    Y_id = []
    order = []
    for i in range(m):
        p, y = nm()
        Y[p - 1].append(y)
        order.append(p)

    for y in Y:
        Y_id += [deque(sorted(range(1, len(y) + 1), key=lambda x: y[x - 1]))]

    for o in order:
        print('{:06}'.format(o) + '{:06}'.format(Y_id[o - 1].popleft()))


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

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

t = 1
tmp = sorted(lis)[0][0]

nlis =[]

for i in sorted(lis):
    if tmp == i[0]:
        left = str(i[0]).zfill(6)
        right = str(t).zfill(6)
        t += 1
    else:
        t = 1
        tmp = i[0]
        left = str(i[0]).zfill(6)
        right = str(t).zfill(6)
    
    nlis.append([i[2],left+right])

for j in sorted(nlis):
    print(j[1])

Submission status: Wrong Answer

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

lis = []
for i in range(m):
    a = list(map(int, input().split()))
    a.append(i)
    lis.append(a)
print(lis)

t = 1
tmp = sorted(lis)[0][0]

nlis =[]

for i in sorted(lis):
    if tmp == i[0]:
        a = str(i[0])
        left = a.zfill(6)
        right = str(t).zfill(6)
        t += 1
    else:
        t = 1
        tmp = i[0]
        left = str(i[0]).zfill(6)
        right = str(t).zfill(6)
    
    nlis.append([i[2],left+right])

for j in sorted(nlis):
    print(j[1])

Submission status: Wrong Answer

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

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

t = 1
tmp = sorted(lis)[0][0]

for i in sorted(lis):
    if tmp == i[0]:
        a = str(i[0])
        left = a.zfill(6)
        right = str(t).zfill(6)
        t += 1
    else:
        t = 1
        tmp = i[0]
        left = str(i[0]).zfill(6)
        right = str(t).zfill(6)
    
    print(left+right)

Submission status: Wrong Answer

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

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

print(lis)
print(sorted(lis))

t = 1
tmp = sorted(lis)[0][0]

for i in sorted(lis):
    if tmp == i[0]:
        a = str(i[0])
        left = a.zfill(6)
        right = str(t).zfill(6)
        t += 1
    else:
        t = 1
        tmp = i[0]
        left = str(i[0]).zfill(6)
        right = str(t).zfill(6)
    
    print(left+right)

Submission status: Wrong Answer

Solution code:
from collections import defaultdict
import bisect

pre = defaultdict(list)
ori = []
n, m = map(int, input().split())
for _ in range(m):
    x, y = map(int, input().split())
    pre[x].append(y)
    ori.append([x, y])

for key, val in pre.items():
    val.sort()

print(pre)
for i in range(m):
    l = pre[ori[i][0]]
    idx = bisect.bisect(l, ori[i][1])
    print(f'{ori[i][0]:06}{idx:06}')

Submission status: Wrong Answer

Solution code:
import bisect
N,M = map(int,input().split())
A = [[] for _ in range(N)] #重複がある場合にはsetにする？
original = []
for i in range(M):
  a,b = map(int,input().split())
  a-=1 #県を0indexに直す
  A[a].append(b)
  original.append((a,b))
for X in A:
  X.sort()

for i in range(M):
  ken,now = original[i]
  ID = bisect.bisect_right(A[ken],now)
  ken += 1; ID+=1
  ans = "0"*(6-len(str(ken)))+str(ken)+"0"*(6-len(str(ID+1)))+str(ID)
  print(ans)

Submission status: Wrong Answer

Solution code:
import bisect
N,M = map(int,input().split())
A = [[] for _ in range(N)] #重複がある場合にはsetにする？
original = []
for i in range(M):
  a,b = map(int,input().split())
  a-=1 #県を0indexに直す
  A[a].append(b)
  original.append((a,b))
for X in A:
  X.sort()

for i in range(M):
  ken,now = original[i]
  ID = bisect.bisect_left(A[ken],now)
  ken += 1; ID+=1
  ans = "0"*(6-len(str(ken)))+str(ken)+"0"*(6-len(str(ID+1)))+str(ID)
  print(ans)

Submission status: Wrong Answer

Solution code:
N,M = map(int, input().split())
C = sorted([list(map(int, input().split())) for m in range(M)])
A = (N+1)*[0]
D = {}

for p,y in C:
  A[p]+=1
  D[y]="%06d%06d" % (p,A[p])

for p,y in C:
  print(D[y])

Submission status: Wrong Answer

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

for m in range(M-1):
  if C[m][0]==C[m+1][0]:
    C[m]+=[n]
    n+=1
  else:
    C[m]+=[n]
    n = 1

C[-1]+=[n]

for m in range(M):
  print("{:06d}{:06d}".format(C[m][0],C[m][2]))

Submission status: Wrong Answer

Solution code:
import numpy as np

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

var = np.array(var)

var2 = np.zeros_like(var)
var2[:, 0] = var[:, 0]

prefs = sorted(set(var[:, 0]))
for pref in prefs:
    arr = var[:, 1][var[:, 0] == pref]
    arr = np.c_[np.arange(len(arr)), arr]
    year_sort = np.argsort(arr, axis=0)[:, 1]
    year_id = np.arange(len(arr))[arr[year_sort][:, 0]] + 1
    var2[:, 1][var[:, 0] == pref] = year_id

var3 = [''.join(list(map(lambda x:str(x).zfill(6), v))) for v in var2]

for v in var3:
    print(v)

Submission status: Wrong Answer

Solution code:
NN, MM = list(map(int,input().split()))

data = []
pref = [[100500]*100000 for i in range(NN)]
prefindex = [0]*100000
while True:
    try:
        i = list(map(int, input().split()))
        data.append(i)
    except EOFError:
        break

for i in range(len(data)):
    pref[data[i][0]-1][prefindex[data[i][0]-1]] = data[i][1]
    prefindex[data[i][0]-1] += 1

for j in range(NN):
    pref[j].sort()

for k in range(len(data)):
    print("{:06d}".format(int(data[k][0])),"{:06d}".format(pref[data[k][0]-1].index(data[k][1])+1),sep="")

#print(pref)

Submission status: Wrong Answer

Solution code:
N,M = map(int,input().split())
ls = []
for i in range(M):
    P,Y = map(int,input().split())
    ls.append([P,Y,i])
ls.sort()
num = 1
city = ls[0][0]
for i in range(M):
    if ls[i][0] == city:
        ls[i][1] = num
        num += 1
    else:
        num = 1
        ls[i][1] = num
        city = ls[i][0]
ls.sort(key=lambda x:x[2])
for i in range(M):
    print('{0:06d}'.format(ls[i][0])+'{0:06d}'.format(ls[i][1]))

Submission status: Wrong Answer

Solution code:
N,M = map(int,input().split())
ls = []
for i in range(M):
    P,Y = map(int,input().split())
    ls.append([i,P,Y])
ls.sort(key=lambda x:x[2])    
ls.sort(key=lambda x:x[1])
num = 1
city = ls[0][1]
for i in range(M):
    if ls[i][1] == city:
        ls[i][2] = num
        num += 1
    else:
        num = 1
        ls[i][2] = num
        city = ls[i][1]
ls.sort(key=lambda x:x[0])
for i in range(M):
    print('{0:06d}'.format(ls[i][1])+'{0:06d}'.format(ls[i][2]))

Submission status: Wrong Answer

Solution code:
N,M = map(int,input().split())
ls = []
for i in range(M):
    P,Y = map(int,input().split())
    ls.append([i,P,Y])
ls.sort(key=lambda x:x[1])
num = 1
city = ls[0][1]
for i in range(M):
    if ls[i][1] == city:
        ls[i][2] = num
        num += 1
    else:
        num = 1
        ls[i][2] = num
        city = ls[i][1]
ls.sort(key=lambda x:x[0])
for i in range(M):
    print('{0:06d}'.format(ls[i][1])+'{0:06d}'.format(ls[i][2]))

Submission status: Wrong Answer

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

number_list=[]
number_list.append([str(0)]*(6-(len(list(str(py[0][0])))))+list(str(py[0][0]))+[str(0)]*(6-(len(list(str(1)))))+list(str(1))+[str(py[0][-1])])
k=2
for j in range(1,m):
    if py[j][0]==py[j-1][0]:
        number_list.append([str(0)]*(6-(len(list(str(py[j][0])))))+list(str(py[j][0]))+[str(0)]*(6-(len(list(str(k)))))+list(str(k))+[str(py[j][-1])])    
        k+=1
    else:
        k=1
        number_list.append([str(0)]*(6-(len(list(str(py[j][0])))))+list(str(py[j][0]))+[str(0)]*(6-(len(list(str(k)))))+list(str(k))+[str(py[j][-1])])
        k+=1
        
number_list_sort=sorted(number_list,key=lambda x:x[-1])
for l in range(m):
    print(''.join(number_list_sort[l][:-1]))

Submission status: Wrong Answer

Solution code:
n,m=map(int,input().split())
py=[]
for i in range(m):
    py.append(list(map(int,input().split()))+[i+1])
py.sort()
number_list=[]
number_list.append([str(0)]*(6-(len(list(str(py[0][0])))))+list(str(py[0][0]))+[str(0)]*(6-(len(list(str(1)))))+list(str(1))+[str(py[0][-1])])
k=2
for j in range(1,m):
    if py[j][0]==py[j-1][0]:
        number_list.append([str(0)]*(6-(len(list(str(py[j][0])))))+list(str(py[j][0]))+[str(0)]*(6-(len(list(str(k)))))+list(str(k))+[str(py[j][-1])])    
        k+=1
    else:
        k=1
        number_list.append([str(0)]*(6-(len(list(str(py[j][0])))))+list(str(py[j][0]))+[str(0)]*(6-(len(list(str(k)))))+list(str(k))+[str(py[j][-1])])
        k+=1
number_list_sort=sorted(number_list,key=lambda x:x[-1])
for l in range(m):
    print(''.join(number_list_sort[l][:-1]))

Submission status: Wrong Answer

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

import sys
import math
from bisect import bisect_right as br
from bisect import bisect_left as bl
sys.setrecursionlimit(2147483647)
from heapq import heappush, heappop,heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
inf = float('inf')
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))

n, m = LI()
lst = [[] for _ in range(n)]

for i in range(m):
    p, y = LI()
    lst[p-1].append([y, i])

for i in lst:
    i.sort()

ans = []
for i in range(n):
    for idx, [j, k] in enumerate(lst[i]):
        s = "0" * 6 + str(i+1)
        s = s[-6:]
        t = "0" * 6 + str(idx+1)
        t = t[-6:]
        ans.append([i, s+t])
ans.sort()
for i, j in ans:
    print(j)

Submission status: Wrong Answer

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

import sys

def main():
    input = sys.stdin.readline
    n, m = map(int, input().split())
    y_dict = {}
    ken_dict = {}
    for i in range(m):
        p_i, y_i = map(int, input().split())
        y_dict[y_i] = []
        y_dict[y_i].append(p_i)

        if not p_i in ken_dict:
            ken_dict[p_i] = []
            ken_dict[p_i].append(y_i)
        else:
            ken_dict[p_i].append(y_i)


    for key in ken_dict.keys():
        ken_dict[key].sort()
        for i,value in enumerate(ken_dict[key]):
            i += 1
            y_dict[value].append(i)
    
    for value in y_dict.values():
        print(str(value[0]).rjust(6, '0') + str(value[1]).rjust(6, '0'))
    
    return

Submission status: Wrong Answer

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

import sys

def main():
    input = sys.stdin.readline
    n, m = map(int, input().split())
    y_dict = {}
    ken_dict = {}
    for i in range(m):
        p_i, y_i = map(int, input().split())
        y_dict[y_i] = []
        y_dict[y_i].append(p_i)

        if not p_i in ken_dict:
            ken_dict[p_i] = []
            ken_dict[p_i].append(y_i)
        else:
            ken_dict[p_i].append(y_i)


    for key in ken_dict.keys():
        ken_dict[key].sort()
        print(ken_dict[key])
        for i,value in enumerate(ken_dict[key]):
            i += 1
            y_dict[value].append(i)
    
    for value in y_dict.values():
        print(str(value[0]).rjust(6, '0') + str(value[1]).rjust(6, '0'))
    
    return


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
N, M = map(int,input().split())
py = []
for i in range(M):
  py.append(list(map(int,input().split())))
  py[i].append(i)
sorted_py = sorted(py, key=lambda x: x[1])
P = [0]*N
p_num = 0
num = 0
output = ''
output2 = []
outputs = []
for i in range(M):
  P[sorted_py[i][0]-1] += 1
  p_num = sorted_py[i][0]
  num = P[sorted_py[i][0]-1]
  output = str(p_num).zfill(6) + str(num).zfill(8)
  output2 = [output, sorted_py[i][2]]
  outputs.append(output2)
sorted_outputs = sorted(outputs, key=lambda x: x[1])
for out in sorted_outputs:
  print(out[0])