Buggy python submission (verdict: Runtime Error):
import sys
n = int(input())
x = list(map(int, input().split()))
s = sorted([[y-1, i+1] for i, y in enumerate(x)])
cur = 0
cnt = [0 for _ in range(n+1)]
fill_cur = 0
ans = []
residual = []
for i in range(n*n):
	if i == s[cur][0] and cnt[s[cur][1]] != s[cur][1]-1:
		print("No")
		sys.exit()
	elif i == s[cur][0]:
		ans.append(s[cur][1])
		cnt[s[cur][1]] += 1
		residual += [s[cur][1]] * (n - s[cur][1])
		cur += 1
		fill_cur = max(fill_cur, cur)
		if cur == n:
			break
	elif fill_cur < n:
		if cnt[s[fill_cur][1]] == s[fill_cur][1]-1:
			fill_cur += 1
		if fill_cur == n:
			ans.append(residual.pop())
			continue
		fill_cur = max(fill_cur, cur)
		ans.append(s[fill_cur][1])
		cnt[s[fill_cur][1]] += 1
	else:
		ans.append(residual.pop())
ans += residual
print("Yes")
print(*ans)

Fixed submission:
import sys
n = int(input())
x = list(map(int, input().split()))
s = sorted([[y-1, i+1] for i, y in enumerate(x)])
cur = 0
cnt = [0 for _ in range(n+1)]
fill_cur = 0
ans = []
residual = []
for i in range(n*n):
	if i == s[cur][0] and cnt[s[cur][1]] != s[cur][1]-1:
		print("No")
		sys.exit()
	elif i == s[cur][0]:
		ans.append(s[cur][1])
		cnt[s[cur][1]] += 1
		residual += [s[cur][1]] * (n - s[cur][1])
		cur += 1
		fill_cur = max(fill_cur, cur)
		if cur == n:
			break
	elif fill_cur < n:
		while cnt[s[fill_cur][1]] == s[fill_cur][1]-1:
			fill_cur += 1
			if fill_cur == n:
				if not residual:
					print("No")
					sys.exit()
				ans.append(residual.pop())
				break
		else:
			fill_cur = max(fill_cur, cur)
			ans.append(s[fill_cur][1])
			cnt[s[fill_cur][1]] += 1
	elif not residual:
		print("No")
		sys.exit()
	else:
		ans.append(residual.pop())
ans += residual
print("Yes")
print(*ans)

Buggy python submission (verdict: Runtime Error):
import sys
n = int(input())
x = list(map(int, input().split()))
s = sorted([[y-1, i+1] for i, y in enumerate(x)])
#print(s)
cur = 0
cnt = [0 for _ in range(n+1)]
cnt_cur = 0
ans = []
residual = []
for i in range(n*n):
	#print(i, cur, cnt_cur)
	if i == s[cur][0] and cnt[s[cur][1]] != s[cur][1]-1:
		print("No")
		sys.exit()
	elif i == s[cur][0]:
		ans.append(s[cur][1])
		cnt[s[cur][1]] += 1
		residual += [s[cur][1]] * (n - s[cur][1])
		cur += 1
		if cur == n:
			break
	elif cnt_cur < n:
		if cnt[s[cnt_cur][1]] == s[cnt_cur][1]-1:
			cnt_cur += 1
		if cnt_cur == n:
			ans.append(residual.pop())
			continue
		cnt_cur = max(cnt_cur, cur)
		ans.append(s[cnt_cur][1])
		cnt[s[cnt_cur][1]] += 1
	else:
		ans.append(residual.pop())
ans += residual
print("Yes")
print(*ans)

Fixed submission:
import sys
n = int(input())
x = list(map(int, input().split()))
s = sorted([[y-1, i+1] for i, y in enumerate(x)])
cur = 0
cnt = [0 for _ in range(n+1)]
fill_cur = 0
ans = []
residual = []
for i in range(n*n):
	if i == s[cur][0] and cnt[s[cur][1]] != s[cur][1]-1:
		print("No")
		sys.exit()
	elif i == s[cur][0]:
		ans.append(s[cur][1])
		cnt[s[cur][1]] += 1
		residual += [s[cur][1]] * (n - s[cur][1])
		cur += 1
		fill_cur = max(fill_cur, cur)
		if cur == n:
			break
	elif fill_cur < n:
		while cnt[s[fill_cur][1]] == s[fill_cur][1]-1:
			fill_cur += 1
			if fill_cur == n:
				if not residual:
					print("No")
					sys.exit()
				ans.append(residual.pop())
				break
		else:
			fill_cur = max(fill_cur, cur)
			ans.append(s[fill_cur][1])
			cnt[s[fill_cur][1]] += 1
	elif not residual:
		print("No")
		sys.exit()
	else:
		ans.append(residual.pop())
ans += residual
print("Yes")
print(*ans)

Buggy python submission (verdict: Runtime Error):
import sys
n = int(input())
x = list(map(int, input().split()))
s = sorted([[y-1, i+1] for i, y in enumerate(x)])
#print(s)
cur = 0
cnt = [0 for _ in range(n+1)]
cnt_cur = 0
ans = []
residual = []
for i in range(n*n):
	#print(i, cur, cnt_cur)
	if i == s[cur][0] and cnt[s[cur][1]] < s[cur][1]-1:
		print("No")
		sys.exit()
	elif i == s[cur][0]:
		ans.append(s[cur][1])
		cnt[s[cur][1]] += 1
		residual += [s[cur][1]] * (n - s[cur][1])
		cur += 1
		if cur == n:
			break
	elif cnt_cur < n:
		if cnt[s[cnt_cur][1]] == s[cnt_cur][1]-1:
			cnt_cur += 1
		if cnt_cur == n:
			ans.append(residual.pop())
			continue
		cnt_cur = max(cnt_cur, cur)
		ans.append(s[cnt_cur][1])
		cnt[s[cnt_cur][1]] += 1
	else:
		ans.append(residual.pop())
ans += residual
print("Yes")
print(*ans)

Fixed submission:
import sys
n = int(input())
x = list(map(int, input().split()))
s = sorted([[y-1, i+1] for i, y in enumerate(x)])
cur = 0
cnt = [0 for _ in range(n+1)]
fill_cur = 0
ans = []
residual = []
for i in range(n*n):
	if i == s[cur][0] and cnt[s[cur][1]] != s[cur][1]-1:
		print("No")
		sys.exit()
	elif i == s[cur][0]:
		ans.append(s[cur][1])
		cnt[s[cur][1]] += 1
		residual += [s[cur][1]] * (n - s[cur][1])
		cur += 1
		fill_cur = max(fill_cur, cur)
		if cur == n:
			break
	elif fill_cur < n:
		while cnt[s[fill_cur][1]] == s[fill_cur][1]-1:
			fill_cur += 1
			if fill_cur == n:
				if not residual:
					print("No")
					sys.exit()
				ans.append(residual.pop())
				break
		else:
			fill_cur = max(fill_cur, cur)
			ans.append(s[fill_cur][1])
			cnt[s[fill_cur][1]] += 1
	elif not residual:
		print("No")
		sys.exit()
	else:
		ans.append(residual.pop())
ans += residual
print("Yes")
print(*ans)