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())
s=[list(map(int, input().split())) for i in range(m)] 
for i in range(m):
    s[i].append(i+1)
a=0
s.sort()
for i in range(m):
    if i>1:
        if s[i][0]!=s[i-1][0]:
            a=0
        
    s[i].append(str(0)*(6-len(str(s[i][0])))+str(s[i][0]))
    s[i].append(str(0)*(6-len(str(a)))+str(a+1))
    a+=1
s.sort(key=lambda x:x[2])
for i in range(m):
    print(s[i][3]+s[i][4])

Submission status: Wrong Answer

Solution code:
n,m=map(int,input().split())
s=[list(map(int, input().split())) for i in range(m)] 
for i in range(m):
    s[i].append(i+1)
print(s)
a=0
s.sort()
for i in range(m):
    if i>1:
        if s[i][0]!=s[i-1][0]:
            a=0
        
    s[i].append(str(0)*(6-len(str(s[i][0])))+str(s[i][0]))
    s[i].append(str(0)*(6-len(str(a)))+str(a+1))
    a+=1
s.sort(key=lambda x:x[2])
for i in range(m):
    print(s[i][3]+s[i][4])

Submission status: Wrong Answer

Solution code:
n,m=map(int,input().split())
s=[list(map(int, input().split())) for i in range(m)] 
for i in range(m):
    s[i].append(i+1)
a=0
s.sort()
s.sort(key=lambda x:x[1])
for i in range(m):
    if i>1:
        if s[i][0]!=s[i-1][0]:
            a=0
        
    s[i].append(str(0)*(6-len(str(s[i][0])))+str(s[i][0]))
    s[i].append(str(0)*(6-len(str(a)))+str(a+1))
    a+=1
s.sort(key=lambda x:x[2])
for i in range(m):
    print(s[i][3]+s[i][4])

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
import numpy as np

n,m = map(int,input().split())
d = {}
ans = ["" for i in range(m)]

for i in range(m):
    p,y = map(int,input().split())
    if p not in d:
        d[p] = [[y,i]]
    else:
        d[p].append([y,i])
for key in d.keys():
    temp = d[key]
    temp.sort(key=lambda x:x[0])
    city = key
    if len(str(city)) < 7:
        city = "0" * (6 - len(str(city))) + str(city)
    for i in range(len(temp)):
        if len(str(i)) < 7:
            y = "0"*(6-len(str(i)))+str(i+1)
        ans[temp[i][1]] = city+y

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

Submission status: Wrong Answer

Solution code:
N,M = map(int,input().split())
l = [list(map(int,input().split()))+[i] for i in range(M)]
l.sort(key=lambda x:(x[0],x[1]))
#print(N,M,l)

ans = []
for i in range(M):
    cnt = 1
    if i == 0:
        p = l[0][0]
        ans.append(["{:0=6}".format(p) + "{:0=6}".format(1),l[i][2]])
    else:
        p = l[i][0]
        if p != l[i-1][0]:
            cnt = 1
        else:
            cnt += 1
        ans.append(["{:0=6}".format(p) + "{:0=6}".format(cnt),l[i][2]])
ans.sort(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())
py = []
for i in range(m):
    p, y = list(map(int, input().split()))
    py.append([p, y, i])

py.sort()

print(py)

ken = [0] * n
ans = [0] * m

for p, y, i in py:
    ken[p - 1] = ken[p - 1] + 1
    ans[i] = p + ken[p - 1]

for i in ans:
    print(i)

Submission status: Wrong Answer

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

n, m = map(int, input().split())
l = []
num = 1
ans = [""] * m

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

l.sort()

pn = l[0][0]

for p, y, i in l:
    if p == pn:
        ans[i] = str(p).zfill(6) + str(num).zfill(6)
        num += 1
    else:
        num = 1
        ans[i] = str(p).zfill(6) + str(num).zfill(6)
        num += 1

for a in ans:
    print(a)

Submission status: Wrong Answer

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

n, m = map(int, input().split())
l = []
num = 1
ans = [""] * m

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

l.sort()
print(l)

pn = l[0][0]

for p, y, i in l:
    if p == pn:
        ans[i] = str(p).zfill(6) + str(num).zfill(6)
        num += 1
    else:
        num = 1
        ans[i] = str(p).zfill(6) + str(num).zfill(6)
        num += 1

for a in ans:
    print(a)

Submission status: Wrong Answer

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

n, m = map(int, input().split())
l = []
pn = 1
num = 1
ans = [""] * m

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

l.sort()


for p, y, i in l:
    if p == pn:
        ans[i] = str(p).zfill(6) + str(num).zfill(6)
        num += 1
    else:
        num = 1
        ans[i] = str(p).zfill(6) + str(num).zfill(6)
        num += 1

for a in ans:
    print(a)

Submission status: Wrong Answer

Solution code:
from operator import itemgetter

N, M = map(int, input().split()) # 横に2個
City = [[i] + list(map(int, input().split())) for i in range(1, M+1)]


City = sorted(City, key=itemgetter(2))
City = sorted(City, key=itemgetter(1))

ans = []
pre = 1
seq = 0
for c in City:
    y = c[1]
    if y > pre:
        seq = 1
        pre += 1
    else:
        seq += 1
    ans.append([c[0], y, seq])

ans.sort(key=itemgetter(0))
for a in ans:
    pre = str(a[1])
    seq = str(a[2])
    print('0'*(6-len(pre)) + pre + '0'*(6-len(seq)) + seq)

Submission status: Wrong Answer

Solution code:
from operator import itemgetter

N, M = map(int, input().split()) # 横に2個
City = [[i] + list(map(int, input().split())) for i in range(1, M+1)]


City = sorted(City, key=itemgetter(2))
City = sorted(City, key=itemgetter(1))

ans = []
pre = 1
seq = 0
for c in City:
    y = c[1]
    if y > pre:
        seq = 1
        pre += 1
    else:
        seq += 1
    ans.append([c[0], pre, seq])

ans.sort(key=itemgetter(0))
for a in ans:
    pre = str(a[1])
    seq = str(a[2])
    print('0'*(6-len(pre)) + pre + '0'*(6-len(seq)) + seq)

Submission status: Wrong Answer

Solution code:
n,m=map(int,input().split())
py=[]
for i in range(m):
    q=[int(j) for j in input().split()]
    py.append(q+[i])
from operator import itemgetter
py.sort(key=itemgetter(1))
py.sort(key=itemgetter(0))
ans=[]
q=0
c=2
for i,j,k in py:
    p=str(i).rjust(6,'0')
    if q==i:
        y=str(c).rjust(6,'0')
        c+=1
    else:
        y="000001"
        q=i   
    ans.append([p+y,k])
from operator import itemgetter
ans.sort(key=itemgetter(1))
for i,j in ans:
    print(i)

Submission status: Wrong Answer

Solution code:
N,M=map(int,input().split())
P=[]
Y=[]
seiritsu=[[]]*N
for i in range(M):
  p,y=map(int,input().split())
  P.append(p)
  Y.append(y)
  seiritsu[P[i]-1].append(Y[i])
for k in range(N):
  seiritsu[k].sort()
for l in range(M):
  print(str(P[l]).zfill(6)+str(seiritsu[P[l]-1].index(Y[l])+1).zfill(6))

Submission status: Wrong Answer

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

for i, y in lst:
    i -= 1
    lst_city[i].append(y)
else:
    lst_city[i].sort()


for i, y in lst:
    id_u = str(i).zfill(6)
    id_l = str(lst_city[i-1].index(y) + 1).zfill(6)
    ans = id_u + id_l
    print(ans)

Submission status: Wrong Answer

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

for i, y in lst:
    i -= 1
    lst_city[i].append(y)
else:
    lst_city[i].sort()
print(lst_city)


for i, y in lst:
    id_u = str(i).zfill(6)
    id_l = str(lst_city[i-1].index(y) + 1).zfill(6)
    ans = id_u + id_l
    print(ans)

Submission status: Wrong Answer

Solution code:
from operator import itemgetter
N, M = map(int, input().split())
PY = [list(map(int, input().split()))+[i] for i in range(M)]
PY.sort()
now = 1
cnt = 1
for j in range(M):
    if now != PY[j][0]:
        cnt = 1
        now += 1
        PY[j].append(cnt)
    else:
        PY[j].append(cnt)
    cnt += 1
PY.sort(key=itemgetter(2))
for i in range(M):
    if len(str(PY[i][0])) > 6:
        print(str(PY[i][0])[:7], end="")
    else:
        print(str(PY[i][0]).zfill(6),end="")
    if len(str(PY[i][3])) > 6:
        print(str(PY[i][3])[:7])
    else:
        print(str(PY[i][3]).zfill(6))

Submission status: Wrong Answer

Solution code:
from operator import itemgetter
N, M = map(int, input().split())
PY = [list(map(int, input().split()))+[i] for i in range(M)]
PY_n = sorted(PY)
now = 1
cnt = 1
for j in range(M):
    if now != PY_n[j][0]:
        cnt = 1
        now += 1
        PY_n[j].append(cnt)
    else:
        PY_n[j].append(cnt)
    cnt += 1
PY_n.sort(key=itemgetter(2))
for i in range(M):
    print(str(PY_n[i][0]).zfill(6)+str(PY_n[i][3]).zfill(6))

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)
py.sort(key=lambda x:x[1])
py.sort(key=lambda x:x[0])
x = py[0][0]
j=0
for i in range(m):
    if x != py[i][0]:
        j = 1
    else:
        j+=1
    s = str(py[i][0]).zfill(6) + str(j).zfill(6)
    py[i].append(s)
py.sort(key=lambda x:x[2])
for i in range(m):
    print(py[i][3])

Submission status: Wrong Answer

Solution code:
N, M = map(int, input().split())
city = [0]*M
for i in range(M):
    city[i] = [i] * 4
    prefecture, year = map(int, input().split())
    city[i][0], city[i][1] = year, prefecture

city = sorted(city)
print(city)

print(city)
ite = [1] * (N+1)
for k in range(M):
    city[k][3] = ite[city[k][1]]
    ite[city[k][1]] += 1
city = sorted(city, key=lambda x: x[2])
for j in range(M):
    print("{:0=12}".format(city[j][1]*1000000+city[j][3]))  # zero padding

Submission status: Wrong Answer

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

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

a = 0
tmp = li[0][0]

for i in range(M):
    if tmp != li[i][0]:
        tmp = li[i][0]
        a = 1
    else:
        a += 1
    li2[i] = [str(li[i][0]).zfill(6)+str(a).zfill(6),li[i][2]]

li2.sort(key=lambda x: x[1])
for i in range(M):
    print(li2[i][0])

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.append([i, p, y])
    
PY = sorted(PY, key=lambda x: x[1])

cnt = [0]*N
ken = 1
for i in range(M):
    if PY[i][1]==ken:
        cnt[ken-1] += 1
    else:
        ken += 1
        cnt[ken-1] += 1

ken = 1
ans = []
num = 0

for i in range(N):
    num += i
    temp_shi = []

    for j in range(cnt[i]):
        num = len(ans)+len(temp_shi)
        temp_shi.append(PY[num])
    
    temp_shi = sorted(temp_shi, key=lambda x: x[2])
    
    for j in range(cnt[i]):
        num = len(ans)+len(temp_shi)
        ans.append([temp_shi[j][0],str(i+1).zfill(6) + str(j+1).zfill(6)])

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

for i in range(M):
    print(ans[i][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.append([i, p, y])
PY = sorted(PY, key=lambda x: x[2])
ken = 1
num = 0
for i in range(M):
    if PY[i][1]==ken:
        num += 1
    else:
        ken += 1
        num = 1
    ans = str(ken).zfill(6) + str(num).zfill(6)
    PY[i].append(ans)    
PY = sorted(PY, key=lambda x: x[0])
for i in range(M):
    print(PY[i][3])

Submission status: Wrong Answer

Solution code:
N, M = map(int,input().split())
li = []
for i in range(M):
    arr = list(map(int, input().split()))
    li.append(arr)
cnt = {}
for i in range(N):
    cnt[i+1] = 0
# old = li
# li.sort()

for i in range(len(li)):
    j = li[i][0]
    print('{0:06d}{1:06d}'.format(li[i][0],cnt[j]+1))
    cnt[li[i][0]] += 1

Submission status: Wrong Answer

Solution code:
n, m = [int(i) for i in input().split()]
city = []
pref = [0 for i in range(n)]
for i in range(m):
    p, y = [int(_) for _ in input().split()]
    pref[p-1] += 1
    city.append([p,y,i])

city.sort(key = lambda x: (x[0], x[1]))
cnt = 1
for i in range(m):
    city[i].append(cnt)
    if cnt == pref[city[i][0]-1]:
        cnt = 1
    else:
        cnt += 1
city.sort(key = lambda x: x[2])
for i in range(m):
    print(str(city[i][0]).zfill(6), str(city[i][3]).zfill(6))

Submission status: Wrong Answer

Solution code:
## ABC113C - ID
import sys
input = sys.stdin.readline

def main():
    n, m = list(map(int, input().rstrip().split()))
    ans = [""] * m
    arr = []
    cnt = 1
    for i in range(m):
        p, y = list(map(int, input().split()))
        arr += [(p, y, i)]
    arr = sorted(arr)

    ans[arr[0][2]] = "{:06}{:06}".format(arr[0][0], cnt)
    for i in range(1, m):
        if arr[i - 1][0] == arr[i][0]:
            cnt += 1
        else:
            cnt = 1
        ans[arr[i][2]] = "{:06}{:06}".format(arr[i][0], cnt)

    for i in ans:
        print(i)
    print(ans)


if __name__ == "__main__":
    main()

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.append((p,y))

PY = sorted(PY, key=lambda x:x[0])
PY = sorted(PY, key=lambda x:x[1])
#print(PY)
num = 1
flag = PY[0][0]
for i in range(M):
    if PY[i][0] != flag:
        num = 1
        flag = PY[i][0]
    y = str(num)
    p = str(PY[i][0])
    p = p.rjust(6,'0')
    y = y.rjust(6,'0')
    print(p+y)
    num += 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.append((p,y))

PY = sorted(PY, key=lambda x:x[0])
PY = sorted(PY, key=lambda x:x[1])
#print(PY)
num = 1
flag = PY[0][1]
for i in range(M):
    if PY[i][1] != flag:
        num = 1
    y = str(num)
    p = str(PY[i][0])
    p = p.rjust(6,'0')
    y = y.rjust(6,'0')
    print(p+y)
    num += 1

Submission status: Wrong Answer

Solution code:
from heapq import heappush
N,M = map(int, input().split())
A = {}
prefs = []
years = []
for i in range(M):
    p,y = input().split()
    prefs.append(p)
    years.append(y)
    if p not in A:
        A[p] = [int(y)]
    else:
        heappush(A[p], int(y))
res = {}
for k,v in A.items():
    for i in range(len(v)):
        res[k+str(v[i])] = str(i+1)
for p,y in zip(prefs, years):
    print(p.zfill(6) + res[p+y].zfill(6))

Submission status: Wrong Answer

Solution code:
from heapq import heappush
N,M = map(int, input().split())
A = {}
prefs = []
years = []
for i in range(M):
    p,y = input().split()
    prefs.append(p)
    years.append(y)
    if p not in A:
        A[p] = [y]
    else:
        heappush(A[p], y)
res = {}
for k,v in A.items():
    for i in range(len(v)):
        res[k+v[i]] = str(i+1)
for p,y in zip(prefs, years):
    print(p.zfill(6) + res[p+y].zfill(6))

Submission status: Wrong Answer

Solution code:
from heapq import heappush
N,M = map(int, input().split())
A = {}
S = []
for i in range(M):
    p,y = input().split()
    S.append([p,y])
    if p not in A:
        A[p] = [y]
    else:
        heappush(A[p], y)
for i in range(M):
    print(S[i][0].zfill(6) + str(A[S[i][0]].index(S[i][1])+1).zfill(6))

Submission status: Wrong Answer

Solution code:
n, m = [int(x) for x in input().split()]

ms = [0]*m
for i in range(m):
    p, y = [int(x) for x in input().split()]
    ms[i] = (p, y)

sorted_ms = sorted(ms, key=lambda x: x[1])
ps = [[]] * n
for i in range(n):
    result = list(filter(lambda x: x[0] == i+1, ms))
    ps[i] = result

for i in range(m):
    for j, x in enumerate(ps[ms[i][0] - 1]):
        if x[1] == ms[i][1]:
            print('%s%s' % (str(ms[i][0]).zfill(6), str(j+1).zfill(6)))

Submission status: Wrong Answer

Solution code:
n, m = [int(x) for x in input().split()]

ms = []
for i in range(m):
    p, y = [int(x) for x in input().split()]
    ms.append({
        'p': p,
        'y': y
    })

sorted_ms = sorted(ms, key=lambda x: x.get('y'))
ps = []
for i in range(n):
    result = list(filter(lambda x: x.get('p') == i+1, ms))
    ps.append(result)

for i in range(m):
    for j, x in enumerate(ps[ms[i].get('p') - 1]):
        if x.get('y') == ms[i].get('y'):
            print('%s%s' % (str(ms[i].get('p')).zfill(6), str(j+1).zfill(6)))

Submission status: Wrong Answer

Solution code:
nm = list(map(int,input().split()))
N = nm[0]
M = nm[1]

py ={}
iy ={}
yp ={}

for i in range(M):
    PY = list(map(int,input().split()))
    P = PY[0]
    Y = PY[1]
    iy[i] = Y
    yp[Y] = P
    if(P-1 in py):
        temp = py[P-1]
        temp.append(Y)
        sorted(temp)
        py[P-1] = temp
    else:
        temp = []
        temp.append(Y)
        py[P-1] = temp

for i in range(M):
    y = iy[i]
    p = yp[y]
    x = py[p-1].index(y)
    pref = "000000" + str(p)
    pref = pref[-6:]
    X = "000000" + str(x+1)
    X = X[-6:]
    print(pref + X)

Submission status: Wrong Answer

Solution code:
n,m=list(map(int,input().split()))
city=[]
for i in range(m):
    city.append(list(map(int,input().split()))+[i])
city.sort()
ans=[]
count=0
precity=city[0][0]
for i in city:
    if i[0]==precity:
        count+=1
    else:
        count=1
    ans.append([i[2],str(i[0]).zfill(6)+str(count).zfill(6)])
ans.sort()
for i in ans:
    print(i[1])

Submission status: Wrong Answer

Solution code:
n,m=list(map(int,input().split()))
city=[]
for i in range(m):
    city.append(list(map(int,input().split())))
city.sort()
ans=[]
count=0
precity=city[0][0]
for i in city:
    if i[0]==precity:
        count+=1
    else:
        count=1
    ans.append(str(i[0]).zfill(6)+str(count).zfill(6))
ans.sort()
for i in ans:
    print(i)

Submission status: Wrong Answer

Solution code:
n,m=map(int,input().split())
cities=[[] for i in range(n)]
for i in range(1,m+1):
  p,y=map(int,input().split())
  cities[p-1].append(y)
  print(format(str(p),"0>6")+format(str(len(cities[p-1])),"0>6"))

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]])
ans = []
P = [0] * (N + 1)
for p, y, i in PY:
    P[p] += 1
    tmp = str(p).zfill(8) + str(P[p]).zfill(8)
    ans.append([i, tmp])
ans.sort()
for i, a in ans:
    print(a)

Submission status: Wrong Answer

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

P = [0] * M
Y = [0] * M
dic = {}
ano_dic = {}
for m in range(M):
    line = list(map(int, input().split()))
    P[m] = line[0]
    Y[m] = line[1]
    
    dic[m] =[P[m], Y[m]]


ID = {}
count = 0
sorted_list = sorted(dic.items(), key=lambda x: (x[1][0], x[0]))


for i, item in enumerate(sorted_list):
    if item[1][0] == sorted_list[i - 1][1][0]:
        count += 1
        ID[item[0]] = str(item[1][0]).zfill(6) + str(count).zfill(6)
    else:
        count = 1
        ID[item[0]] = str(item[1][0]).zfill(6) + str(count).zfill(6)

for item in sorted(ID.items(), key=lambda x: x[0]):
    print(item[1])

Submission status: Wrong Answer

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

P = [0] * M
Y = [0] * M
dic = {}
ano_dic = {}
for m in range(M):
    line = list(map(int, input().split()))
    P[m] = line[0]
    Y[m] = line[1]
    
    dic[m] =[P[m], Y[m]]


ID = {}
count = 0
sorted_list = sorted(dic.items(), key=lambda x: (x[1][1], x[0]))
for i, item in enumerate(sorted_list):
    if item[1][0] == sorted_list[i - 1][1][0]:
        count += 1
        ID[item[0]] = str(item[1][0]).zfill(6) + str(count).zfill(6)
    else:
        count = 1
        ID[item[0]] = str(item[1][0]).zfill(6) + str(count).zfill(6)

for item in sorted(ID.items(), key=lambda x: x[0]):
    print(item[1])

Submission status: Wrong Answer

Solution code:
def resolve():
    (N, M) = list(map(int,input().split(" ")))
    cities = [list(map(int, input().split(" "))) + [i] for i in range(M)]
    sorted_cities = sorted(cities, key=lambda x: (x[0], x[1]))

    pref = 0
    cnt = 0
    for city in sorted_cities:
        if pref != city[0]:
            pref = city[0]
            cnt = 0
        cnt = cnt + 1
        city.append("{:06d}{:06d}".format(pref, cnt))
    
    #sorted_cities = sorted(cities, key=lambda x: x[2])
    for city in sorted_cities:
        print(city[3])

if '__main__' == __name__:
    resolve()

Submission status: Wrong Answer

Solution code:
def resolve():
    (N, M) = list(map(int,input().split(" ")))
    cities = [list(map(int, input().split(" "))) for i in range(M)]
    sorted_cities = sorted(sorted(cities, key=lambda x: x[0]), key=lambda y: y[1])

    pref = sorted_cities[0][0]
    cnt = 0
    for city in sorted_cities:
        if pref != city[0]:
            pref = city[0]
            cnt = 0
        cnt = cnt + 1
        city.append("{:06d}{:06d}".format(pref, cnt))
    
    for city in cities:
        print(city[2])
        

if '__main__' == __name__:
    resolve()

Submission status: Wrong Answer

Solution code:
def resolve():
    (N, M) = list(map(int,input().split(" ")))
    cities = [list(map(int, input().split(" "))) for i in range(M)]
    sorted_cities = sorted(sorted(cities, key=lambda x: x[0]), key=lambda y: y[1])

    pref = 0
    cnt = 0
    for city in sorted_cities:
        if pref != city[0]:
            pref = city[0]
            cnt = 0
        cnt = cnt + 1
        city.append("{:06}{:06}".format(pref, cnt))
    
    for city in cities:
        print(city[2])
        

if '__main__' == __name__:
    resolve()

Submission status: Wrong Answer

Solution code:
def resolve():
    (N, M) = list(map(int,input().split(" ")))
    cities = [list(map(int, input().split(" "))) for i in range(M)]
    sorted_cities = sorted(sorted(cities, key=lambda x: x[0]), key=lambda y: y[1])

    pref = 0
    for city in sorted_cities:
        if pref != city[0]:
            pref = city[0]
            cnt = 0
        cnt = cnt + 1
        city.append("{:06}{:06}".format(pref, cnt))
    
    for city in cities:
        print(city[2])
        

if '__main__' == __name__:
    resolve()

Submission status: Wrong Answer

Solution code:
import bisect
import operator
import os
from collections import Counter, deque
from fractions import gcd
from functools import lru_cache
from functools import reduce
import functools
import heapq
import itertools
import math
import numpy as np
import re
import sys

if os.getenv("LOCAL"):
    sys.stdin = open("_in.txt", "r")

sys.setrecursionlimit(2147483647)
INF = float("inf")

N, M = list(map(int, sys.stdin.readline().split()))
P, Y = list(zip(*[map(int, sys.stdin.readline().split()) for _ in range(M)]))

P = np.array(P)
Y = np.array(Y)
order = Y.argsort()
P = P[order]
Y = Y[order]

ans = []
cnt = 1
prev = None
for p, y in zip(P, Y):
    if p == prev:
        cnt += 1
    else:
        cnt = 1
    ans.append('{:06d}{:06d}'.format(p, cnt))
    prev = p
print('\n'.join(map(str, np.array(ans)[order.argsort()])))

Submission status: Wrong Answer

Solution code:
N,M=map(int,input().split())
PY=[[0,0]]
ans=[]
for _ in range(M):
    PY.append(list(map(int,input().split())))
PY.sort(key=lambda x:(x[0],x[1]))

for i in range(M):
    number=""
    if PY[i+1][0]!=PY[i][0]:
        x=1
    else:
        x+=1
    number+=str(PY[i+1][0]).zfill(6)
    number+=str(x).zfill(6)
    ans.append(number)

for i in ans:
    print(i)

Submission status: Wrong Answer

Solution code:
N,M = [int(i) for i in input().split()]
PY = []
for m in range(M):
    PY.append([int(i) for i in input().split()])
    PY[-1].append(m)
PY.sort(key=lambda x:x[0])
PY.sort(key=lambda x:x[1])
ans = []
pre = 0
cnt = 0
for py in PY:
    if pre == py[0]:
        cnt+=1
    else:
        cnt = 1
    ans.append([str(py[0]).zfill(6) + str(cnt).zfill(6),py[2]])
    pre = py[0]
ans.sort(key=lambda x:x[1])
for a in ans:
    print(a[0])

Submission status: Wrong Answer

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

mp = {}
for i in range(M):
    P,Y=map(int,input().split())
    if not P in mp:
        mp[P] = []
    mp[P].append(Y)

for k,li in sorted(mp.items()):
    for i, _ in enumerate(li):
        print('{:06d}{:06d}'.format(k, i+1))

Submission status: Wrong Answer

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

N,M = map(int,input().split())
py= []

for i in range(M):
    pp,yy = map(int,input().split())
    py.append((pp,yy,i))

py.sort()

cnt = 1
pp_prev = 0
code = ['' for _ in range(M)]

for pp,yy,i in py:
    if pp == pp_prev:
       cnt += 1 
    else:
        cnt = 1
    code[i] = "%06d%06d"%(pp,cnt)
    
print(*code,sep='\n')

Submission status: Wrong Answer

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

for i in range(M):
    pp,yy = input().split()
    py.append((pp,yy,i))

py.sort()

cnt = 1
pp_prev = ''
code = ['' for _ in range(M)]

for pp,yy,i in py:
    if pp == pp_prev:
       cnt += 1 
    else:
        cnt = 1
    code[i] = '0'*(6-len(pp)) + pp + '0'*(6-len(str(cnt))) + str(cnt)
    pp_prev = pp

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

Submission status: Wrong Answer

Solution code:
N, M = map(int, input().split())
from collections import defaultdict
d = defaultdict(list)
for i in range(M):
    P,Y = map(str, input().split())
    d[P].append([Y,i])
l = [0 for i in range(M)] 
cnt = 0   
for key in d:
    d[key] = sorted(d[key])
    tmp = 0
    for i in range(len(d[key])):
        l[cnt] = [key.zfill(6) + str(tmp+1).zfill(6), d[key][i][1]]
        cnt += 1
        tmp += 1
l.sort(key = lambda x: x[1])
for i in range(M):
    print(l[i][0])

Submission status: Wrong Answer

Solution code:
N, M = map(int, input().split())
from collections import defaultdict
d = defaultdict(list)
l = [[] for i in range(M)]
for i in range(M):
    P,Y = map(str, input().split())
    P = "0" * len(P) + P
    d[P].append(int(Y))
    l[i] = [P,int(Y)]
for i in range(M):
    tmp = str((sorted(d[l[i][0]]).index(l[i][1]))+1)
    print(l[i][0] + "0" * (6-len(tmp)) + tmp)

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))

ans = [None]*M

for i, d in enumerate(D):
    print(d)
    d.sort()
    for k, (y, j) in enumerate(d):
        ans[j] = "%06d%06d" % (i+1, k+1)
    
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)]

convertedPY = [
    {'index': i,
     'city': py[0],
     'year': py[1]
     } for i, py in enumerate(PY)
]
'''
3 4
1 32
3 64
3 63
1 33

'''
convertedPY = sorted(convertedPY, key=lambda a: (a['city'], a['year']))
answer = []
cnt = 1
tmp = convertedPY[0]['city']
#print(convertedPY)
result = []
for py in convertedPY:
    temp_dict = {}
    if tmp == py['city']:
        temp_dict['answer'] = '{:0=6}'.format(py['city']) + '{:0=6}'.format(cnt)
        temp_dict['index'] = py['index']
        result.append(temp_dict)
        cnt += 1
    else:
        cnt = 1
        temp_dict['answer'] = '{:0=6}'.format(py['city']) + '{:0=6}'.format(cnt)
        temp_dict['index'] = py['index']
        result.append(temp_dict)
        tmp = py['city']


result = sorted(result, key=lambda a: a['index'])
#print(result)
for r in result:
    print(r['answer'])

Submission status: Wrong Answer

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

convertedPY = [
    {'index': i,
     'city': py[0],
     'year': py[1]
     } for i, py in enumerate(PY)
]
'''
3 4
1 32
3 64
3 63
1 33

'''
convertedPY = sorted(convertedPY, key=lambda a: (a['city'], a['year']))
answer = []
cnt = 1
tmp = convertedPY[0]['city']
#print(convertedPY)
result = []
for py in convertedPY:
    temp_dict = {}
    if tmp == py['city']:
        temp_dict['answer'] = '{:0=6}'.format(py['city']) + '{:0=6}'.format(cnt)
        temp_dict['index'] = py['index']
        result.append(temp_dict)
        cnt += 1
    else:
        cnt = 1
        temp_dict['answer'] = '{:0=6}'.format(py['city']) + '{:0=6}'.format(cnt)
        temp_dict['index'] = py['index']
        result.append(temp_dict)
        tmp == py['city']
        

result = sorted(result, key=lambda a: a['index'])
#print(result)
for r in result:
    print(r['answer'])

'''
3
21 -11
81234 52141 94124
'''

#print(PY)

Submission status: Wrong Answer

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

convertedPY = [
    {'index': i,
     'city': py[0],
     'year': py[1]
     } for i, py in enumerate(PY)
]

convertedPY = sorted(convertedPY, key=lambda a: (a['city'], a['year']))
answer = []
cnt = 1
tmp = convertedPY[0]['city']
#print(convertedPY)
result = []
for py in convertedPY:
    temp_dict ={}
    if tmp == py['city']:
        temp_dict['answer'] = '{:0=6}'.format(py['city']) + '{:0=6}'.format(cnt)
        temp_dict['index'] = py['index']
        result.append(temp_dict)
        cnt += 1
    else:
        cnt = 1
        temp_dict['answer'] = '{:0=6}'.format(py['city']) + '{:0=6}'.format(cnt)
        temp_dict['index'] = py['index']
        result.append(temp_dict)

#print(result)
result = sorted(result, key=lambda a: a['index'])

for r in result:
    print(r['answer'])