Problem: 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.

Submission attempts (in order):
N,M = map(int,input().split())
P = []

Indexs = []
Syuturyoku = []


for j in range(N):
	P.append([0])


for i in range(M):
	p,y = map(int,input().split())

	P[p-1].append(y)
	Indexs.append(y)
	Syuturyoku.append(("0","0"))

for i in range(len(P)):
	P[i].sort()
	P[i] = list(map(str,P[i]))


for i in range(len(P)):
	if(len(P[i])>1):
		for j in range(len(P[i])-1):
			atai = P[i][j+1]
			si = i+1
			si = str(si)
			x = j+1
			x = str(x)
			bangou = list(map(str,si))
			bangou_len = int(len(bangou))
			bangou_ushiro = list(map(str,x))
			bangou_ushiro_len = int(len(bangou_ushiro))
			if(len(bangou)<6):
				for zero in range(6-bangou_len):
					bangou.insert(0,'0')
			if(len(bangou_ushiro)<6):
				for zero in range(6-bangou_ushiro_len):
					bangou_ushiro.insert(0,'0')

			mojiretsu = ''
			for k in bangou:
				mojiretsu += k
			mojiretsu2 = ''
			for k2 in bangou_ushiro:
				mojiretsu2 += k2

			a = Indexs.index(int(atai))
			Syuturyoku[a] = (mojiretsu,mojiretsu2)
for i in range(M):
	print(Syuturyoku[i][0],Syuturyoku[i][1])


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

Indexs = []
Syuturyoku = []


for j in range(N):
	P.append([0])


for i in range(M):
	p,y = map(int,input().split())

	P[p-1].append(y)
	Indexs.append(y)
	Syuturyoku.append(("0","0"))

for i in range(len(P)):
	P[i].sort()
	P[i] = list(map(str,P[i]))


for i in range(len(P)):
	if(len(P[i])>1):
		zeros = ''
		zeros_2 = ''
		for j in range(len(P[i])-1):
			atai = P[i][j+1]
			si = i+1
			si = str(si)
			x = j+1
			x = str(x)
			bangou = list(map(str,si))
			bangou_len = int(len(bangou))
			bangou_ushiro = list(map(str,x))
			bangou_ushiro_len = int(len(bangou_ushiro))
			if(len(bangou)<6):
				for zero in range(6-bangou_len):
					zeros += '0'
			if(len(bangou_ushiro)<6):
				for zero in range(6-bangou_ushiro_len):
					zeros_2 += '0'

			mojiretsu = zeros+si
			mojiretsu2 = zeros_2+x

			a = Indexs.index(int(atai))
			Syuturyoku[a] = (mojiretsu,mojiretsu2)
for i in range(M):
	print(Syuturyoku[i][0]+Syuturyoku[i][1])


import bisect

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

Indexs = {}
Syuturyoku = []
vp = []
vy = []

for j in range(N):
	P.append([0])


for i in range(M):
	p,y = map(int,input().split())
	vp.append(p)
	vy.append(y)

	P[p-1].append(y)
	Indexs[y] = i
	Syuturyoku.append(0)

for i in range(len(P)):
	P[i].sort()

for si in range(M):
	x = bisect.bisect_left(P[vp[si] - 1], vy[si])
	print('{:06}{:06}'.format(vp[si], x)) 


Verdicts: Wrong Answer

Wrong Answer

Accepted