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:
#!/usr/bin/env python3
import sys

"""
ABC113_C ID 学び：
 python の0埋め　s.rjust(digit,0) でいける
 sortを県ごとにしないといけない、とわかれば、input, sort , outputの３段かいに別れる
どんな配列を持てばいいかは事前に考える。
実際にそこまで立てて、inputをローカルでやると良い
"""

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
n, m = map(int, input().split())
lis_p = [[] for _ in range(n)]
city = [[0, 0] for _ in range(m)]  # p と　idx
idx_p = []
# input
for i in range(m):
    p, y = map(int, input().split())
    city[i][0] = p - 1
    city[i][1] = len(lis_p[p - 1])
    lis_p[p - 1].append(y)
for pref in range(n):
    k = len(lis_p[pref])
    # print(lis_p[pref])
    idx = []
    if k > 0:
        lis_p[pref], idx = zip(*sorted(zip(lis_p[pref], range(k))))
    idx_p.append(idx)
for i in range(m):
    # string になおす必要がある rjust
    print(str(city[i][0] + 1).rjust(6, "0"), end="")
    print(str(1 + idx_p[city[i][0]][city[i][1]]).rjust(6, "0"))

Submission status: Wrong Answer

Solution code:
from operator import itemgetter
n,m=map(int,input().split())
a=[]
for i in range(m):
    pi,yi=map(int,input().split())
    a.append([i,pi,yi])
b=[]
c=[]
for i in range(n):
    b.append([])
    c.append([])
for i in range(m):
    x=a[i][0]
    y=a[i][2]
    b[a[i][1]-1].append([x,y])

for i in range(n):
    b[i].sort(key=itemgetter(1))
    l=len(b[i])
    for j in range(l):
        a[b[i][j][0]].append(j+1)
print(a)
for i in range(m):
    xi=a[i][1]
    yi=a[i][3]
    print('{0:06d}{1:06d}'.format(xi,yi))

Submission status: Wrong Answer

Solution code:
from operator import itemgetter
n,m=map(int,input().split())
a=[]
for i in range(m):
    pi,yi=map(int,input().split())
    a.append([i,pi,yi])
b=[]
c=[]
for i in range(n):
    b.append([])
    c.append([])
for i in range(m):
    x=a[i][0]
    y=a[i][2]
    b[a[i][1]-1].append([x,y])

for i in range(n):
    b[i].sort(key=itemgetter(1))
    l=len(b[i])
    for j in range(l):
        a[b[i][j][0]].append(j+1)
for i in range(m):
    x=a[i][1]
    y=a[i][3]
    print('{0:06d}{0:06d}'.format(x,y))

Submission status: Wrong Answer

Solution code:
n,m=map(int,input().split())
a=[]
for i in range(n):
    a.append(0)
for i in range(m):
    pi,yi=map(int,input().split())
    a[pi-1]+=1
for i in range(len(a)):
    for j in range(a[i]):
        print('{0:06d}{1:06d}'.format(i+1,j+1))

Submission status: Wrong Answer

Solution code:
N, M = map(int, input().split())
py = []
for i in range(M):
    p, y = map(int, input().split())
    py += [[i, p, y]]
py = sorted(py, key=lambda x:(x[1], x[2]))
cnt = 0
pre = py[0][1]
ans = []
for n, p, y in py:
    if pre != p:
        cnt = 1
        pre = n
    else:
        cnt += 1
        
    ans += [[n, str(p).zfill(6)+str(cnt).zfill(6)]]

ans = sorted(ans, key=lambda x:x[0])
for _, n in ans:
    print(n)

Submission status: Wrong Answer

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

citys = []
c_append = citys.append
prefs = []
p_append = prefs.append
pref_in_citys = {}
for i in range(M):
    P, Y = map(int, input().split())
    if P not in prefs:
        p_append(P)
        pref_in_citys[P] = []
    city_dict = {
        "birth": Y,
        "pref": P,
        "number": ""
    }
    c_append(city_dict)
    pref_in_citys[P].append(citys[-1])

# check
for p in pref_in_citys.keys():
    target_citys = pref_in_citys[p]
    if len(target_citys) == 1:
        target_citys[0]["number"] += "000001"
    else:
        target_citys.sort(key=lambda x: x["birth"])
        lot_num = 1
        for c in target_citys:
            c["number"] += "0" * (6 - len(str(p))) + str(p) + "0" * (6 - len(str(lot_num))) + str(lot_num)
            lot_num += 1

for c in citys:
    print(c["number"])

Submission status: Wrong Answer

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

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

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

for i in range(n):
    p[i].sort()
    city_cnt = 1
    for j in p[i]:
        p_num = str(i + 1)
        ans = '0' * (6 - len(p_num))
        ans += p_num
        city_num = str(city_cnt)
        ans += '0' * (6 - len(city_num))
        ans += city_num
        city_cnt += 1
        print(ans)

Submission status: Wrong Answer

Solution code:
n,m=map(int,input().split())
num=[]
ans=[""]*m
numcount=[1]*n
count=1
for i in range(m):
    p,y=map(int,input().split())
    num.append([p,y,i])
stry= lambda val: val[1]
num.sort(key=stry)
print(num)
for i in range(m):
    p=str(num[i][0])
    y=str(numcount[int(num[i][0])-1])
    numcount[int(num[i][0])-1]+=1
    ans[num[i][2]]="0"*(6-len(p))+p+"0"*(6-len(y))+y
for i in range(m):
    print(ans[i])

Submission status: Wrong Answer

Solution code:
n,m=map(int,input().split())
num=[]
ans=[""]*m
count=1
for i in range(m):
    p,y=input().split()
    num.append([p,y,i])
stry= lambda val: val[1]
num.sort(key=stry)
strp= lambda val: val[0]
num.sort(key=strp)
for i in range(m):
    p=str(num[i][0])
    if i!=0 and num[i][0]==num[i-1][0]:
        count+=1
        y=str(count)
    else:
        count=1
        y=str(count)
    ans[num[i][2]]="0"*(6-len(p))+p+"0"*(6-len(y))+y
for i in range(m):
    print(ans[i])

Submission status: Wrong Answer

Solution code:
n,m=map(int,input().split())
num=[]
ans=[""]*m
count=1
for i in range(m):
    p,y=input().split()
    num.append([p,y,i])
print(num)
stry= lambda val: val[1]
num.sort(key=stry)
strp= lambda val: val[0]
num.sort(key=strp)
for i in range(m):
    p=str(num[i][0])
    if i!=0 and num[i][0]==num[i-1][0]:
        count+=1
        y=str(count)
    else:
        count=1
        y=str(count)
    ans[num[i][2]]="0"*(6-len(p))+p+"0"*(6-len(y))+y
for i in range(m):
    print(ans[i])

Submission status: Wrong Answer

Solution code:
n,m = map(int,input().split())
l = []
s = ""
tmp = 1
for i in range(m):
  p,y = map(str,input().split())
  l.append([p.zfill(6),y,i+1])
  
l = sorted(l, key=lambda x:(x[0],x[1]))

for i in range(m):
  s = ""
  if i == 0 or l[i-1][0] != l[i][0]:
    tmp = 1
  else:
    tmp += 1
  s = l[i][0] + str(tmp).zfill(6)
  l[i].append(s)
    
l = sorted(l, key=lambda x:(x[2]))

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

Submission status: Wrong Answer

Solution code:
n,m = map(int,input().split())
l = []
s = ""
tmp = 1
for i in range(m):
  p,y = map(str,input().split())
  l.append([p.zfill(6),y,i+1])
  
l = sorted(l, key=lambda x:(x[0],x[1]))

for i in range(m):
  if i == 0 or l[i-1][0] != l[i][0]:
    tmp = 1
  else:
    tmp += 1
  s = l[i][0] + str(tmp).zfill(6)
  l[i].append(s)
    
l = sorted(l, key=lambda x:(x[2]))

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

Submission status: Wrong Answer

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

for i in range(M):
  p, y = map(int, input().split())
  D[p-1].append((y, i)) #市ごとにリストに入れる．この時，元の順番をタプルの1番目の要素として入れておく
print(D)
ans = [None]*M

for i, d in enumerate(D): #enumerateは要素の中身とインデックス番号を持ってこれる．print(i, d)で確認
  d.sort()
  print(d)
  for k, (y, j) in enumerate(d): #こちらも同様．(y, j)となっているため，yには年数が，jには元の順番の情報が入る
    ans[j] = str(i+1).zfill(6) + str(k+1).zfill(6) #ans[j]に12桁の認識番号を挿入

print(*ans, sep = '\n')

Submission status: Wrong Answer

Solution code:
n,m=map(int,input().split())
py=[list(map(int,input().split())) for i in range(m)]
l=[[] for j in range(n)]
for p,y in py:
  l[p-1].append(y)
for j in range(n):
  l[j].sort()
for j in range(n):
  for t in range(len(l[j])):
    pre='0'*(6-len(str(j+1)))+str(j+1)
    y='0'*(6-len(str(t+1)))+str(t+1)
    print(pre+y)

Submission status: Wrong Answer

Solution code:
n,m=map(int,input().split())
py=[list(map(int,input().split())) for i in range(m)]
l=[[] for j in range(n)]
for p,y in py:
  l[p-1].append(y)
for j in range(n):
  l[j].sort()
for j in range(n):
  for t in range(len(l[j])):
    pre='0'*(6-len(str(l[j][t])))+str(l[j][t])
    y='0'*(6-len(str(t+1)))+str(t+1)
    print(pre+y)

Submission status: Wrong Answer

Solution code:
n,m=map(int,input().split())
temp=[0]*m
for i in range(0,m):
  p,y=map(int,input().split())
  temp[i]=[i,p,y]
temp.sort(key=lambda x: x[2])  
temp.sort(key=lambda x: x[1])  
j=1
n=1
for i in range(0,m):
  if temp[i][1]==n:
    tempn=str(n)
    tempj=str(j)
    temp[i][1]=tempn.zfill(6)
    temp[i][2]=tempj.zfill(6)
    j=j+1
  else:
    n=n+1
    j=1
    tempn=str(n)
    tempj=str(j)
    temp[i][1]=tempn.zfill(6)
    temp[i][2]=tempj.zfill(6)
    j=j+1
temp.sort(key=lambda x: x[0])
for i in range(0,m):
  print(temp[i][1]+temp[i][2])

Submission status: Wrong Answer

Solution code:
n,m=map(int,input().split())
temp=[0]*m
for i in range(0,m):
  p,y=map(int,input().split())
  temp[i]=[i,p,y]
temp.sort(key=lambda x: x[2])  
temp.sort(key=lambda x: x[1])  
print(temp)
j=1
n=1
for i in range(0,m):
  if temp[i][1]==n:
    tempn=str(n)
    tempj=str(j)
    temp[i][1]=tempn.zfill(6)
    temp[i][2]=tempj.zfill(6)
    j=j+1
  else:
    n=n+1
    j=1
    tempn=str(n)
    tempj=str(j)
    temp[i][1]=tempn.zfill(6)
    temp[i][2]=tempj.zfill(6)
    j=j+1
temp.sort(key=lambda x: x[0])
for i in range(0,m):
  print(temp[i][1]+temp[i][2])

Submission status: Wrong Answer

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

for p in range(1,n+1):
    tmp=sorted(x[p])
    print(p,tmp)
    for j in range(len(tmp)):
        ans[tmp[j][1]]=str(p).zfill(6)+str(j+1).zfill(6)

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

Submission status: Wrong Answer

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

py.sort()

old=py[0][0]
order=1
for i in range(m):
    now=py[i][0]
    if now==old:
        py[i].append(order)
        order+=1
    else:
        order=1
        py[i].append(order)
        
py.sort(key = lambda x:x[2])

for pypy in py:
    ans = str(pypy[0]).zfill(6) + str(pypy[3]).zfill(6)
    print(ans)

Submission status: Wrong Answer

Solution code:
import sys
import heapq
import re
from itertools import permutations
from bisect import bisect_left, bisect_right
from collections import Counter, deque
from fractions import gcd
from math import factorial, sqrt, ceil
from functools import lru_cache, reduce
INF = 1 << 60
MOD = 1000000007
sys.setrecursionlimit(10 ** 7)

# UnionFind
class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.find(x)]

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        return len(self.roots())

    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}

    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())

def is_prime(n):
    if n == 1:
        return False
    for i in range(2,int(n**0.5)+1):
        if n % i == 0:
            return False
    return True


# ワーシャルフロイド (任意の2頂点の対に対して最短経路を求める)
# 計算量n^3 (nは頂点の数)
def warshall_floyd(d, n):
    #d[i][j]: iからjへの最短距離
    for k in range(n):
        for i in range(n):
            for j in range(n):
                d[i][j] = min(d[i][j],d[i][k] + d[k][j])
    return d


# ダイクストラ
def dijkstra_heap(s, edge, n):
    #始点sから各頂点への最短距離
    d = [10**20] * n
    used = [True] * n #True:未確定
    d[s] = 0
    used[s] = False
    edgelist = []
    for a,b in edge[s]:
        heapq.heappush(edgelist,a*(10**6)+b)
    while len(edgelist):
        minedge = heapq.heappop(edgelist)
        #まだ使われてない頂点の中から最小の距離のものを探す
        if not used[minedge%(10**6)]:
            continue
        v = minedge%(10**6)
        d[v] = minedge//(10**6)
        used[v] = False
        for e in edge[v]:
            if used[e[1]]:
                heapq.heappush(edgelist,(e[0]+d[v])*(10**6)+e[1])
    return d

# 素因数分解
def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append([i, cnt])

    if temp!=1:
        arr.append([temp, 1])

    if arr==[]:
        arr.append([n, 1])

    return arr

# 2数の最小公倍数
def lcm(x, y):
    return (x * y) // gcd(x, y)

# リストの要素の最小公倍数
def lcm_list(numbers):
    return reduce(lcm, numbers, 1)

# リストの要素の最大公約数
def gcd_list(numbers):
    return reduce(gcd, numbers)

# 素数判定



# limit以下の素数を列挙
def eratosthenes(limit):
    A = [i for i in range(2, limit+1)]
    P = []

    while True:
        prime = min(A)
        
        if prime > sqrt(limit):
            break
            
        P.append(prime)
            
        i = 0
        while i < len(A):
            if A[i] % prime == 0:
                A.pop(i)
                continue
            i += 1
            
    for a in A:
        P.append(a)
            
    return P

# 同じものを含む順列
def permutation_with_duplicates(L):

    if L == []:
        return [[]]

    else:
        ret = []

        # set（集合）型で重複を削除、ソート
        S = sorted(set(L))

        for i in S:

            data = L[:]
            data.remove(i)

            for j in permutation_with_duplicates(data):
                ret.append([i] + j)

        return ret


# ここから書き始める
n, m = map(int, input().split())
p = [0 for i in range(m)]
y = [0 for i in range(m)]
for i in range(m):
    p[i], y[i] = map(int, input().split())
x = [[] for i in range(n)]
for i in range(m):
    x[p[i] - 1].append(y[i])
for i in range(n):
    x[i].sort()
print("x =", x)
for i in range(m):
    index = bisect_left(x[p[i] - 1], y[i])
    ans = str(p[i]).zfill(6) + str(index + 1).zfill(6)
    print(ans)

Submission status: Wrong Answer

Solution code:
n,m = map(int,input().split())
C = [[i, list(map(int,input().split()))] for i in range(m)]
C.sort(key=lambda x:(x[1][0],x[1][1]))
D = {}
rank=1
for i in range(m):
    name=C[i][0]
    if i>1 and C[i][1][0] != C[i-1][1][0]:
        rank = 1
    D[name] = str(C[i][1][0]).zfill(6)+str(rank).zfill(6)
    rank+=1
for i in range(m):
    print(D[i])

Submission status: Wrong Answer

Solution code:
n,m = map(int,input().split())
C = [[i, list(map(int,input().split()))] for i in range(m)]
C.sort(key=lambda x:(x[1][0],x[1][1]))
D = {}
print(C)
rank=1
for i in range(m):
    name=C[i][0]
    if i>1 and C[i][1][0] != C[i-1][1][0]:
        rank = 1
    D[name] = str(C[i][1][0]).zfill(6)+str(rank).zfill(6)
    rank+=1
for i in range(m):
    print(D[i])

Submission status: Wrong Answer

Solution code:
n,m = map(int,input().split())
C = [[i, list(map(int,input().split()))] for i in range(m)]
C.sort(key=lambda x:(x[1][0],x[1][1]))
D = {}
rank=1
for i in range(m):
    name=C[i][0]
    if i>1 and C[i][1][0] != C[i-1][1][0]:
        rank = 1
    D[name] = str(C[i][1][0]).zfill(6)+str(rank).zfill(6)
    rank+=1
    print(D[name])

Submission status: Wrong Answer

Solution code:
n,m=map(int,input().split())
lst=[]
for i in range(m):
  a,b=map(int,input().split())
  lst.append([a, b])
lst.sort()
for j in range(m):
  ans=""
  ans+="0"*(6-len(str(lst[j][0])))+str(lst[j][0])+"0"*(6-len(str(j+1)))+str(j+1)
  print(ans)

Submission status: Wrong Answer

Solution code:
from bisect import bisect_left
n, m = map(int, input().split())
p, y = [0]*m, [0]*m
dict_p = {}
for i in range(m):
    p[i], y[i] = map(int, input().split())
    if p[i] not in dict_p.keys():
        dict_p[p[i]] = list()

    dict_p[p[i]].append(y[i])
#print(dict_p)
ans = [0]*m
#for i in range(m):
    #dict_p[p[i]].sort()

for i in range(m):
    x = bisect_left(dict_p[p[i]], y[i])
    ans = "{:006}".format(p[i]) + "{:006}".format(x+1)
    print(ans)

Submission status: Wrong Answer

Solution code:
n,m = map(int,input().split())
p = {str(i):[] for i in range(1,n+1)}
l = []
for i in range(m):
    t = input().split()
    l.append(t)
    p[t[0]].append(t[1])
for i in range(1,n+1):
    p[str(i)].sort()
for t in l:
    print(t[0].zfill(6)+str(p[t[0]].index(t[1])+1).zfill(6))

Submission status: Wrong Answer

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

pref = {}
for p,y in info:
    if not p in pref: pref[p] = [y]
    else: pref[p].append(y)

id = {}
for p,years in pref.items():
    id[p] = {}
    for i,y in enumerate(years):
        id[p][y] = str(p).zfill(6) + str(i+1).zfill(6)

for p,y in info:
    print(id[p][y])

Submission status: Wrong Answer

Solution code:
import numpy as np
n,m = list(map(int, input().split()))
info = [list(map(int, input().split())) for i in range(m)]

info = np.array(info)
pref = {}
for i in range(1,n+1):
    pref[i] = info[info[:,0] == i, 1]

id = {}
for p,years in pref.items():
    id[p] = {}
    for i,y in enumerate(years):
        id[p][y] = str(p).zfill(6) + str(i+1).zfill(6)

for p,y in info:
    print(id[p][y])

Submission status: Wrong Answer

Solution code:
import numpy as np
n,m = list(map(int, input().split()))
info = list(list(map(int, input().split())) for i in range(m))

info = np.array(info)
p,y = info[:,0],info[:,1]
y[np.argsort(y)] = np.arange(1,m+1)
for i in range(m):
    print(str(p[i]).zfill(6) + str(y[i] - min(y[p == p[i]]) + 1).zfill(6))

Submission status: Wrong Answer

Solution code:
import numpy as np
n,m = list(map(int, input().split()))
info = list(list(map(int, input().split())) for i in range(m))

info = np.array(info)
p,y = info[:,0],info[:,1]
y[np.argsort(y)] = np.arange(1,m+1)

for num in range(1,n+1):
    filt = (p==num)
    if sum(filt):
        y[filt] -= min(y[filt])-1
for i in range(m):
    print(str(p[i]).zfill(6) + str(y[i]).zfill(6))

Submission status: Wrong Answer

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

prefecture = []
city = []
index_ = []

for i in range(m):
    a, b = map(int, input().split())
    prefecture.append(a)
    city.append(b)
    index_.append(i)

A = zip(city, prefecture, index_)
A = sorted(A)
city, prefecture, index_ = zip(*A)
# print(city, prefecture, index_)

true_index = []

prefecture_2 = list(prefecture) + [max(prefecture) + 1]
result = 0
for i in range(m):
    if prefecture_2[i] == prefecture_2[i+1]:
        true_index.append(result)
        result += 1
    else:
        true_index.append(result)
        result = 0
A = zip(index_, prefecture, true_index)
A = sorted(A)
index_, prefecture, true_index = zip(*A)


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

Submission status: Wrong Answer

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

prefecture = []
city = []
index_ = []

for i in range(m):
    a, b = map(int, input().split())
    prefecture.append(a)
    city.append(b)
    index_.append(i)

A = zip(city, prefecture, index_)
A = sorted(A)
city, prefecture, index_ = zip(*A)
number = []
order = 0
for i in range(1, m):
    if prefecture[i-1] == prefecture[i]:
        number.append(order)
        order += 1
    else:
        number.append(order)
        number.append(0)
        order = 1
number.append(order)

A = zip(index_, prefecture, city, number)
A = sorted(A)
index_, prefecture, city, number = zip(*A)

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

Submission status: Wrong Answer

Solution code:

import itertools
import math
import fractions
import functools
n, m = map(int, input().split())
py = []
for i in range(m):
    l = list(map(int, input().split()))
    l.append(i)
    py.append(l)
 
# py = [p,y,index]
 
# yでsort
py.sort(key=lambda x: x[1])

ans = [0] * (m)
ans1 = [0] * (m)
memo = {}
for item in py:
    ken = item[0]
    year = item[1]
    idx = item[2]
    print(ken)
    ith = memo.get(ken, 1)
    ans[idx] = ith
    ans1[idx] = ken
    memo[ken] = ith + 1

for i in range(m):
    print(str(ans1[i]).zfill(6) + str(ans[i]).zfill(6))

Submission status: Wrong Answer

Solution code:
import itertools
import math
import fractions
import functools
n, m = map(int, input().split())
py = []
for i in range(m):
    l = list(map(int, input().split()))
    l.append(i)
    py.append(l)

py.sort(key=lambda x: x[1])
prev = 0
for i in range(m):
    if prev != py[i][0]:
        prev = py[i][0]
        x = 1

    py[i].append(x)
    x += 1
py.sort(key=lambda x: x[2])
p_i = ""
x_i = ""
for i in range(m):
    if(len(str(py[i][0])) == 6):
        p_i = str(py[i][0])
    if(len(str(py[i][0])) == 5):
        p_i = '0' + str(py[i][0])
    if(len(str(py[i][0])) == 4):
        p_i = '00'+str(py[i][0])
    if(len(str(py[i][0])) == 3):
        p_i = '000' + str(py[i][0])
    if(len(str(py[i][0])) == 2):
        p_i = '0000'+str(py[i][0])
    if(len(str(py[i][0])) == 1):
        p_i = '00000' + str(py[i][0])
    if(len(str(py[i][3])) == 6):
        x_i = str(py[i][3])
    if(len(str(py[i][3])) == 5):
        x_i = '0' + str(py[i][3])
    if(len(str(py[i][3])) == 4):
        x_i = '00'+str(py[i][3])
    if(len(str(py[i][3])) == 3):
        x_i = '000' + str(py[i][3])
    if(len(str(py[i][3])) == 2):
        x_i = '0000'+str(py[i][3])
    if(len(str(py[i][3])) == 1):
        x_i = '00000' + str(py[i][3])

    print(p_i + x_i)

Submission status: Wrong Answer

Solution code:
n,m=map(int,input().split())
lis=[]
for i in range(m):
  p,q=map(int,input().split())
  lis.append([q,p])
lis.sort()
ken=[1]*n
for i in range(0,m):
  attack=lis[i]
  kenken=attack[1]
  ken_count=ken[kenken-1]
  moji=""
  moji+="0"*(6-len(str(kenken)))+str(kenken)+"0"*(6-len(str(ken_count)))+str(ken_count)
  ken[kenken-1]+=1
  print(moji)

Submission status: Wrong Answer

Solution code:
import numpy as np

def padding_id(id):
    padded_id = id
    id_length = len(id)
    for i in range(6-id_length):
        padded_id = "0" + padded_id
    return padded_id


def main():
    string = input().split(' ')
    N = int(string[0])
    M = int(string[1])
    P = np.zeros(M, dtype='int16')
    Y = np.zeros(M, dtype='int16')
    Y_per_P = {}
    for i in range(M):
        string = input().split(' ')
        P[i] = int(string[0])
        Y[i] = int(string[1])
        if P[i] in Y_per_P:
            Y_per_P[P[i]]['year'] = np.append(Y_per_P[P[i]]['year'], Y[i])
        else:
            Y_per_P[P[i]] = {'year': np.asarray([Y[i]])}
    for key in Y_per_P.keys():
        Y_per_P[key]['sorted_id'] = np.argsort(Y_per_P[key]['year'])

    for p, y in zip(P, Y):
        y_filter = Y_per_P[p]['year'] == y
        id = Y_per_P[p]['sorted_id'][y_filter][0]
        print(padding_id(str(p)) + padding_id(str(id+1)))


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import numpy as np

def padding_id(id):
    padded_id = id
    id_length = len(id)
    for i in range(6-id_length):
        padded_id = "0" + padded_id
    return padded_id


def main():
    string = input().split(' ')
    N = int(string[0])
    M = int(string[1])
    P = np.zeros(M, dtype='int16')
    Y = np.zeros(M, dtype='int16')
    Y_per_P = {}
    for i in range(M):
        string = input().split(' ')
        P[i] = int(string[0])
        Y[i] = int(string[1])
        if P[i] in Y_per_P:
            Y_per_P[P[i]]['year'] = np.append(Y_per_P[P[i]]['year'], Y[i])
        else:
            Y_per_P[P[i]] = {'year': np.asarray([Y[i]])}
    for key in Y_per_P.keys():
        Y_per_P[key]['sorted_id'] = np.argsort(Y_per_P[key]['year'])

    for p, y in zip(P, Y):
        y_filter = Y_per_P[p]['year'] == y
        id = Y_per_P[p]['sorted_id'][y_filter]
        print(padding_id(str(p)) + padding_id(str(id[0]+1)))


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import numpy as np

def padding_id(id):
    padded_id = id
    id_length = len(id)
    for i in range(6-id_length):
        padded_id = "0" + padded_id
    return padded_id

def main():
    string = input().split(' ')
    N = int(string[0])
    M = int(string[1])
    P = np.zeros(M, dtype='int32')
    Y = np.zeros(M, dtype='int32')
    Y_per_P = {}
    for i in range(M):
        string = input().split(' ')
        P[i] = int(string[0])
        Y[i] = int(string[1])
        if P[i] in Y_per_P:
            Y_per_P[P[i]]['year'] = np.append(Y_per_P[P[i]]['year'], Y[i])
        else:
            Y_per_P[P[i]] = {'year': np.asarray([Y[i]])}
    for key in Y_per_P.keys():
        Y_per_P[key]['sorted_id'] = np.argsort(Y_per_P[key]['year'])

    for p, y in zip(P, Y):
        y_filter = Y_per_P[p]['year'] == y
        id = Y_per_P[p]['sorted_id'][y_filter]
        print(padding_id(str(p)) + padding_id(str(id[0]+1)))


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
N,K=map(int,input().split())
ans=0

if K%2!=0:
  p=N//K
  ans+= p**3
else:
  z=K//2
  a=(N-z)//K+1
  ans += a**3
  p=N//K
  ans+= p**3

print(ans)

Submission status: Wrong Answer

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

for i in range(M):
    pi, yi = map(int, input().split())
    records.append([i, pi, yi, "X"])

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

city = records[0][1]
city_num = 0

for i in range(M):
    if records[i][1] == city:
        city_num += 1
        records[i][3] = city_num
    else:
        city += records[i][1]
        records[i][3] = 1
        city_num = 1

records.sort()
for record in records:
    ans = "%06d" % record[1] + "%06d" % record[3]
    print(ans)

Submission status: Wrong Answer

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

for i in range(M):
    pi, yi = map(int, input().split())
    records.append([i, pi, yi, "X"])

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

city = 1
city_num = 0

for i in range(M):
    if records[i][1] == city:
        city_num += 1
        records[i][3] = city_num
    else:
        city += records[i][1]
        records[i][3] = 1
        city_num = 1

records.sort()

for record in records:
    ans = "%06d" % record[1] + "%06d" % record[3]
    print(ans)

Submission status: Wrong Answer

Solution code:
N,M = map(int,input().split()) #N個の県、M個の市
city_info = [] #要素０は０市の情報[P県、０市が誕生したY年]
Pref_info = [[] for _ in range(N)] #県P情報[要素０は０県。[市が誕生した年Y]
for i in range(M):
    P,Y = map(int,input().split())
    city_info.append([P-1, Y])
    Pref_info[P - 1].append(Y)
for i in Pref_info:
    i.sort()
    
print("city_info = " + str(city_info))
print("Pref_info = " + str(Pref_info))
for p,y in city_info:
    x = Pref_info[p].index(y) + 1 #市が誕生した順番を取得
    print("{0:0>6}".format(p+1) + "{0:0>6}".format(x))

Submission status: Wrong Answer

Solution code:
N,M = map(int,input().split()) #N個の県、M個の市
city_info = [] #要素０は０市の情報[P県、０市が誕生したY年]
Pref_info = [[] for _ in range(N)] #県P情報[要素０は０県。[市が誕生した年Y]
for i in range(M):
    P,Y = map(int,input().split())
    city_info.append([P-1, Y])
    Pref_info[P - 1].append(Y)
    
#print("city_info = " + str(city_info))
#print("Pref_info = " + str(Pref_info))
for p,y in city_info:
    x = Pref_info[p].index(y) + 1 #市が誕生した順番を取得
    print("{0:0>6}".format(p+1) + "{0:0>6}".format(x))

Submission status: Wrong Answer

Solution code:
from operator import itemgetter
N,M=map(int,input().split())
py=[list(map(int,input().split())) for _ in range(M)]
py.sort(key=itemgetter(1))
pre={}
#print(dp)
for i in range(M):
    if py[i][0] not in pre.keys():    
        pre[py[i][0]]=1
    else:
        pre[py[i][0]]+=1
    print(str(py[i][0]).rjust(6,"0")+str(pre[py[i][0]]).rjust(6,"0"))

#print(p)
#print(y)
#print(dp)

Submission status: Wrong Answer

Solution code:
import sys
sys.setrecursionlimit(10**6) #再帰関数の上限
import math
from copy import copy, deepcopy
from operator import itemgetter
from bisect import bisect_left, bisect, bisect_right#2分探索
#bisect_left(l,x), bisect(l,x)#aはソート済みである必要あり。aの中からx未満の要素数を返す。rightだと以下
from collections import deque 
#deque(l), pop(), append(x), popleft(), appendleft(x)
##listでqueの代用をするとO(N)の計算量がかかってしまうので注意
from collections import Counter#文字列を個数カウント辞書に、
#S=Counter(l),S.most_common(x),S.keys(),S.values(),S.items()
from itertools import accumulate#累積和
#list(accumulate(l))
from heapq import heapify,heappop,heappush
#heapify(q),heappush(q,a),heappop(q) #q=heapify(q)としないこと、返り値はNone
#import fractions#古いatcoderコンテストの場合GCDなどはここからimportする

def input(): return sys.stdin.readline()[:-1]
def printl(li): print(*li, sep="\n")
def argsort(s, return_sorted=False): 
    inds=sorted(range(len(s)), key=lambda k: s[k])
    if return_sorted: return inds, [s[i] for i in inds]
    return inds

def main():
    mod = 10**9+7
    #w.sort(key=itemgetter(1),reversed=True)  #二個目の要素で降順並び替え

    #N = int(input())
    N, M = map(int, input().split())
    #A = tuple(map(int, input().split())) #1行ベクトル
    #L = tuple(int(input()) for i in range(N)) #改行ベクトル
    #S = tuple(tuple(map(int, input().split())) for i in range(N)) #改行行列
    tot=[[] for _ in range(N+1)]
    ys=[0]*M
    for i in range(N):
        heapify(tot[i])
    for i in range(M):
        P, Y = map(int, input().split())
        heappush(tot[P],Y)
        ys[i]=Y
    tset=[]
    tseti=[]
    for i in range(N+1):
        t1=tot[i]
        if len(t1)<1:continue
        p=str(i)
        if len(p)<6:
            p='0'*(6-len(p))+p
        for j,t in enumerate(t1):
            tx=str(j+1)
            if len(tx)<6:
                tx='0'*(6-len(tx))+tx
            tset.append(p+tx)
            tseti.append(t)
    for y in ys:
        i=tseti.index(y)
        print(tset[i])





if __name__ == "__main__":
    main()