AtCoder Grand Contest 008 - K-th K

You are given an integer sequence x of length N. Determine if there exists an integer sequence a that satisfies all of the following conditions, and if it exists, construct an instance of a.

* a is N^2 in length, containing N copies of each of the integers 1, 2, ..., N.
* For each 1 ≤ i ≤ N, the i-th occurrence of the integer i from the left in a is the x_i-th element of a from the left.

Constraints

* 1 ≤ N ≤ 500
* 1 ≤ x_i ≤ N^2
* All x_i are distinct.

Input

The input is given from Standard Input in the following format:


N
x_1 x_2 ... x_N


Output

If there does not exist an integer sequence a that satisfies all the conditions, print `No`. If there does exist such an sequence a, print `Yes` in the first line, then print an instance of a in the second line, with spaces inbetween.

Examples

Input

3
1 5 9


Output

Yes
1 1 1 2 2 2 3 3 3


Input

2
4 1


Output

No

Difficulty: UNKNOWN_DIFFICULTY

Starter code:

Solutions:
import sys
sys.setrecursionlimit(10 ** 6)
input = sys.stdin.readline
from math import floor, sqrt, factorial, hypot, log
from heapq import heappop, heappush, heappushpop
from collections import Counter, defaultdict, deque
from itertools import accumulate, permutations, combinations, product, combinations_with_replacement
from bisect import bisect_left, bisect_right
from copy import deepcopy
from fractions import gcd
from random import randint

def ceil(a, b):
	return (a + b - 1) // b
inf = float('inf')
mod = 10 ** 9 + 7

def pprint(*A):
	for a in A:
		print(*a, sep='\n')

def INT_(n):
	return int(n) - 1

def MI():
	return map(int, input().split())

def MF():
	return map(float, input().split())

def MI_():
	return map(INT_, input().split())

def LI():
	return list(MI())

def LI_():
	return [int(x) - 1 for x in input().split()]

def LF():
	return list(MF())

def LIN(n: int):
	return [I() for _ in range(n)]

def LLIN(n: int):
	return [LI() for _ in range(n)]

def LLIN_(n: int):
	return [LI_() for _ in range(n)]

def LLI():
	return [list(map(int, l.split())) for l in input()]

def I():
	return int(input())

def F():
	return float(input())

def ST():
	return input().replace('\n', '')

def main():
	N = I()
	XI = [(x - 1, i) for (i, x) in enumerate(MI())]
	XI.sort()
	remain = [N - i - 1 for i in range(N)]
	idx = 0
	ans = [None] * (N * N)
	ok = True
	for (x, i) in XI:
		for _ in range(i):
			while idx < N * N and ans[idx] is not None:
				idx += 1
			if idx >= x:
				ok = False
				break
			ans[idx] = i
			idx += 1
		ans[x] = i
	for (x, i) in XI:
		for _ in range(remain[i]):
			while idx < N * N and ans[idx] is not None:
				idx += 1
			if idx < x:
				ok = False
			ans[idx] = i
			idx += 1
	if not ok:
		print('No')
		return
	print('Yes')
	print(*[a + 1 for a in ans])
main()


n = int(input())
x = [int(x) for (i, x) in enumerate(input().split())]
x = sorted(zip(x, range(1, n + 1)))
stack = []
for (v, i) in x[::-1]:
	for _ in range(i - 1):
		stack.append(i)
cur = 1
ans = []
res = []
cnt = [0] * (n + 1)
for i in range(n):
	for _ in range(x[i][0] - cur):
		if stack:
			nxt = stack.pop()
		elif res:
			nxt = res.pop()
		else:
			print('No')
			exit()
		ans.append(nxt)
		cnt[nxt] += 1
	if cnt[x[i][1]] != x[i][1] - 1:
		print('No')
		exit()
	ans.append(x[i][1])
	for _ in range(n - x[i][1]):
		res.append(x[i][1])
	cur = x[i][0] + 1
ans += res
print('Yes')
print(*ans)


n = int(input())
X = tuple(map(int, input().split()))
XI = sorted(((x, i + 1) for (i, x) in enumerate(X)))
L = [-1] * (n * n)
A = []
B = []
for (x, i) in XI:
	A = [i] * (i - 1) + A
	B += [i] * (n - i)
	L[x - 1] = i
now = 0
while A:
	if L[now] == -1:
		L[now] = A.pop()
	now += 1
now = n - 1
while B:
	if L[now] == -1:
		L[now] = B.pop()
	now -= 1
C = [0] * (n + 1)
for (x, l) in enumerate(L, 1):
	C[l] += 1
	if C[l] == l:
		if X[l - 1] != x:
			print('No')
			exit()
print('Yes')
print(*L)


def main():
	n = int(input())
	X = list(map(int, input().split()))
	ans = [-1] * n ** 2
	left = []
	right = []
	for (idx, x) in enumerate(X):
		idx += 1
		ans[x - 1] = idx
		left.append((x, idx - 1, idx))
		right.append((x, n - idx, idx))
	left.sort(key=lambda x: -x[0])
	right.sort(key=lambda x: x[0])
	(amt, cnt) = (0, 0)
	for i in range(n ** 2):
		if ans[i] != -1:
			continue
		while amt == 0 and cnt < n:
			cnt += 1
			(x, amt, idx) = left.pop()
		if amt == 0:
			break
		if x <= i:
			print('No')
			return
		amt -= 1
		ans[i] = idx
	(amt, cnt) = (0, 0)
	for i in range(n ** 2 - 1, -1, -1):
		if ans[i] != -1:
			continue
		while amt == 0 and cnt < n:
			cnt += 1
			(x, amt, idx) = right.pop()
		if amt == 0:
			break
		if x > i:
			print('No')
			return
		amt -= 1
		ans[i] = idx
	print('Yes')
	print(*ans)
main()


from collections import deque
from collections import defaultdict
n = int(input())
x = list(map(int, input().split()))
for i in range(n):
	if x[i] - 1 < i or x[i] - 1 > n * n - n + i:
		print('No')
		exit()
ans = [-1] * n * n
for i in range(n):
	ans[x[i] - 1] = i + 1
x2 = []
for i in range(n):
	x2.append((x[i], i + 1))
x2.sort()
yusen = deque([])
ato = deque([])
for i in range(n):
	yusen.extend([x2[i][1]] * (x2[i][1] - 1))
	ato.extend([x2[i][1]] * (n - x2[i][1]))
for i in range(n * n):
	if ans[i] == -1:
		if yusen:
			ko = yusen.popleft()
			ans[i] = ko
		else:
			ko = ato.popleft()
			ans[i] = ko
d = defaultdict(int)
for i in range(n * n):
	d[ans[i]] += 1
	if d[ans[i]] == ans[i]:
		if i + 1 != x[ans[i] - 1]:
			print('No')
			exit()
print('Yes')
print(*ans)


from collections import deque
from operator import itemgetter
n = int(input())
a = list(map(int, input().split()))
ans = [-1] * n ** 2
for i in range(n):
	ans[a[i] - 1] = i + 1
a_ind = [(j, a[j]) for j in range(n)]
a_ind = sorted(a_ind, key=itemgetter(1))
pos = 0
for (j, _) in a_ind:
	k = j
	while True:
		if j == 0:
			break
		if ans[pos] != -1:
			pos += 1
		else:
			ans[pos] = k + 1
			pos += 1
			j -= 1
used = [False] * n
q = deque([])
cnt = [0] * n
for i in range(n ** 2):
	if ans[i] != -1:
		cnt[ans[i] - 1] += 1
		if cnt[ans[i] - 1] == ans[i]:
			for _ in range(n - ans[i]):
				q.append(ans[i])
			used[ans[i] - 1] = True
	elif not q:
		print('No')
		exit()
	else:
		tmp = q.pop()
		ans[i] = tmp
cnt = [0] * n
for i in range(n ** 2):
	cnt[ans[i] - 1] += 1
	if cnt[ans[i] - 1] == ans[i]:
		if a[ans[i] - 1] != i + 1:
			print('No')
			exit()
print('Yes')
print(*ans)


(N, *X) = map(int, open(0).read().split())
x_to_i = {x: i for (i, x) in enumerate(X, 1)}
I = sorted(range(1, N + 1), key=lambda i: X[i - 1])
T = []
for i in I:
	T += [i] * (i - 1)
for i in I:
	T += [i] * (N - i)
T = iter(T)
C = [0] * (N + 1)
A = []
for x in range(1, N * N + 1):
	if x in x_to_i:
		i = x_to_i[x]
		if C[i] + 1 != i:
			print('No')
			quit()
	else:
		i = next(T)
	C[i] += 1
	A.append(i)
print('Yes')
print(*A)


import collections
n = int(input())
x = list(map(int, input().split()))
x = list(enumerate(x, 1))
x.sort(key=lambda x: x[1])
li = []
dic = {j: i for (i, j) in x}
for (i, j) in x:
	li += [i] * (i - 1)
for (i, j) in x:
	li += [i] * (n - i)
li = collections.deque(li)
ans = []
cnt = [0 for i in range(n + 1)]
for i in range(1, n ** 2 + 1):
	if i in dic:
		m = dic[i]
		if cnt[m] != m - 1:
			print('No')
			exit()
	else:
		m = li.popleft()
	cnt[m] += 1
	ans.append(m)
print('Yes')
print(*ans)


def solve():
	N = int(input())
	Xs = [(X, i + 1) for (i, X) in enumerate(map(int, input().split()))]
	N2 = N ** 2
	Xs.sort()
	As = [0] * (2 * N2 + 1)
	for (X, no) in Xs:
		As[X] = no
	iA = 1
	for (X, no) in Xs:
		num = no - 1
		while num:
			if As[iA] == 0:
				As[iA] = no
				num -= 1
			iA += 1
		if iA > X:
			return []
	for (X, no) in Xs:
		while As[iA] != 0:
			iA += 1
		if iA <= X:
			return []
		num = N - no
		while num:
			if As[iA] == 0:
				As[iA] = no
				num -= 1
			iA += 1
	if iA != N2 + 1:
		return []
	return As[1:iA]
anss = solve()
if anss:
	print('Yes')
	print(' '.join(map(str, anss)))
else:
	print('No')


from heapq import heappush, heappop
import sys
input = sys.stdin.readline
N = int(input())
x = [0] + list(map(int, input().split()))
v = []
heap = []
a = [-1] * (N * N + 1)
for i in range(1, N + 1):
	a[x[i]] = i
	for j in range(1, i):
		v.append((x[i] - j, i))
v.sort(reverse=True)
for i in range(1, N * N + 1):
	if a[i] != -1:
		n = a[i]
		for j in range(N - n):
			heappush(heap, (N * N - j, n))
		continue
	if v:
		(j, k) = v.pop()
		if x[k] < i:
			print('No')
			exit()
		a[i] = k
	else:
		if not heap:
			print('No')
			exit()
		(j, k) = heappop(heap)
		a[i] = k
print('Yes')
print(*a[1:])


from collections import deque
n = int(input())
x = list(map(int, input().split()))
y = [(x[i], i + 1) for i in range(n)]
y.sort()
rng = [(y[0][1], (n - 1) * n // 2 + 1)]
bef = deque([y[0][1]] * (y[0][1] - 1))
for i in range(1, n):
	(a, b) = rng[-1]
	rng.append((a + y[i][1], b + n - y[i - 1][1] + 1))
	bef.extend([y[i][1]] * (y[i][1] - 1))
ans = []
cnt = 0
for i in range(n):
	goal = y[i][0]
	if cnt > goal or not rng[i][0] <= y[i][0] <= rng[i][1]:
		print('No')
		exit()
	while cnt + 1 < goal:
		if not bef:
			print('No')
			exit()
		ans.append(bef.popleft())
		cnt += 1
	ans.append(y[i][1])
	cnt += 1
	bef.extend([y[i][1]] * (n - y[i][1]))
while bef:
	ans.append(bef.popleft())
print('Yes')
print(*ans, sep=' ')


N = int(input())
X = list(map(int, input().split()))
Y = sorted([(x - 1, i + 1) for (i, x) in enumerate(X)])
ans = [None] * (N * N)
must = []
for (i, n) in Y:
	ans[i] = n
	must += [n] * (n - 1)
must.reverse()
used = [0] * (N + 1)
free = [1]
for i in range(N * N):
	if ans[i]:
		a = ans[i]
		if used[a] != a - 1:
			print('No')
			exit()
		free += [a] * (N - a)
	elif must:
		a = must.pop()
		ans[i] = a
	elif free:
		a = free.pop()
		ans[i] = a
	else:
		print('No')
		exit()
	used[ans[i]] += 1
for i in range(1, N + 1):
	if used[i] != N:
		print('No')
		exit()
print('Yes')
print(*ans)


from collections import defaultdict, deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random

def LI():
	return [int(x) for x in sys.stdin.readline().split()]

def I():
	return int(sys.stdin.readline())

def LS():
	return [list(x) for x in sys.stdin.readline().split()]

def S():
	res = list(sys.stdin.readline())
	if res[-1] == '\n':
		return res[:-1]
	return res

def IR(n):
	return [I() for i in range(n)]

def LIR(n):
	return [LI() for i in range(n)]

def SR(n):
	return [S() for i in range(n)]

def LSR(n):
	return [LS() for i in range(n)]
sys.setrecursionlimit(1000000)
mod = 1000000007

def A():
	(x, y) = LI()
	if x < 0:
		if y < 0:
			if x < y:
				print(y - x)
			else:
				print(x - y + 2)
		elif abs(x) < y:
			print(y - abs(x) + 1)
		else:
			print(-y - x + (y > 0))
	elif y < 0:
		if x < abs(y):
			print(abs(y) - x + 1)
		else:
			print(x + y + 1)
	elif x < y:
		print(y - x)
	else:
		print(x - y + (x > 0) + (y > 0))
	return

def B():
	return

def C():
	a = LI()
	if a[0] > 0 and a[3] > 0 and (a[4] > 0):
		print(max(2 * (a[0] // 2) + a[1] + 2 * (a[3] // 2) + 2 * (a[4] // 2), 2 * ((a[0] - 1) // 2) + a[1] + 2 * ((a[3] - 1) // 2) + 2 * ((a[4] - 1) // 2) + 3))
	else:
		print(2 * (a[0] // 2) + a[1] + 2 * (a[3] // 2) + 2 * (a[4] // 2))
	return

def D():
	n = I()
	x = LI()
	f = [(x[i], i) for i in range(n)]
	f.sort()
	b = []
	for (xi, i) in f:
		b += [i + 1] * i
	for (xi, i) in f:
		b += [i + 1] * (n - i - 1)
	ans = []
	l = 0
	for (xi, i) in f:
		while len(ans) + 1 < xi:
			if l == len(b):
				break
			ans.append(b[l])
			l += 1
		ans.append(i + 1)
	for i in range(l, len(b)):
		ans.append(b[i])
	f = [0] * n
	for i in range(len(ans)):
		ai = ans[i] - 1
		if f[ai] == ai:
			if i + 1 != x[ai]:
				print('No')
				return
		f[ai] += 1
	print('Yes')
	print(*ans)
	return

def E():
	return

def F():
	return
D()


N = int(input())
ans = [-1] * N ** 2
X = [int(x) - 1 for x in input().split()]
for (i, x) in enumerate(X):
	ans[x] = i + 1
(left, right) = ([], [])
for i in range(N):
	(l_cnt, r_cnt) = (i, N - (i + 1))
	left.extend([(X[i], i + 1)] * l_cnt)
	right.extend([(X[i], i + 1)] * r_cnt)
(l, r) = (0, N ** 2 - 1)
left.sort()
right.sort()
for (_, x) in left:
	while ans[l] != -1:
		l += 1
	ans[l] = x
for (_, x) in reversed(right):
	while ans[r] != -1:
		r -= 1
	ans[r] = x
counter = [[] for _ in range(N)]
for (i, a) in enumerate(ans):
	counter[a - 1].append(i)
if all((counter[i].index(x) == i for (i, x) in zip(range(N), X))):
	print('Yes')
	print(*ans)
else:
	print('No')
assert all((a != -1 for a in ans))
assert all((len(row) == N for row in counter))


from collections import deque
import sys
N = int(input())
x = list(map(int, input().split()))
mustuse = deque([])
ableuse = deque([])
xlis = []
ans = [None] * N ** 2
for i in range(N):
	ans[x[i] - 1] = i + 1
	xlis.append([x[i], i + 1])
xlis.sort()
for i in range(N):
	for j in range(xlis[i][1] - 1):
		mustuse.append(xlis[i][1])
for i in range(N ** 2):
	if ans[i] != None:
		if len(mustuse) > 0 and mustuse[0] == ans[i]:
			print('No')
			sys.exit()
		for j in range(N - ans[i]):
			ableuse.append(ans[i])
	elif len(mustuse) > 0:
		ans[i] = mustuse.popleft()
	elif len(ableuse) > 0:
		ans[i] = ableuse.popleft()
	else:
		print('No')
		sys.exit()
print('Yes')
print(' '.join(map(str, ans)))


INF = (1 << 31) - 1

class SegmentTree:

	def __init__(self, N):
		self.N = 2 ** (N - 1).bit_length()
		self.data = [[INF, -1] for _ in range(2 * self.N - 1)]

	def update(self, k, a):
		self.data[k + self.N - 1] = [a, k]
		k += self.N - 1
		while k > 0:
			k = (k - 1) // 2
			if self.data[2 * k + 1][0] < self.data[2 * k + 2][0]:
				self.data[k] = self.data[2 * k + 1][:]
			else:
				self.data[k] = self.data[2 * k + 2][:]

	def query_min(self, l, r):
		L = l + self.N
		R = r + self.N
		s = [INF, -1]
		while L < R:
			if R & 1:
				R -= 1
				if s[0] > self.data[R - 1][0]:
					s = self.data[R - 1]
			if L & 1:
				if s[0] > self.data[L - 1][0]:
					s = self.data[L - 1]
				L += 1
			L >>= 1
			R >>= 1
		return s
import sys
input = sys.stdin.readline
from bisect import bisect_left
N = int(input())
X = list(map(int, input().split()))
sortedX = sorted(X)
decided = [-1] * (N ** 2 + 1)
for (i, x) in enumerate(X):
	decided[x] = i + 1
marge = SegmentTree(N + 1)
remains = [0] * (N + 1)
alreadyUsed = [None] * (N + 1)
for (i, x) in enumerate(X):
	i += 1
	alreadyused = bisect_left(sortedX, x)
	if i != 1:
		marge.update(i, x - alreadyused - i)
	alreadyUsed[i] = alreadyused
	remains[i] = i - 1

def solve():
	offset = 0
	for n in range(1, N ** 2 + 1):
		if decided[n] != -1:
			decided_num = decided[n]
			if remains[decided_num] > 0:
				return (False, None)
			remain = N - decided_num
			if remain < 0:
				return (False, None)
			if remain == 0:
				marge.update(decided_num, INF)
				remains[decided_num] = 0
			else:
				marge_now = N ** 2 - n - (N - alreadyUsed[decided_num] - 1) - remain + offset
				marge.update(decided_num, marge_now)
				remains[decided_num] = remain
		else:
			(marge_now, num) = marge.query_min(0, N + 1)
			if marge_now - offset < 0 or marge_now == INF:
				return (False, None)
			remains[num] -= 1
			if remains[num] == 0:
				marge.update(num, INF)
			else:
				marge.update(num, marge_now + 1)
			decided[n] = num
			offset += 1
	return (True, decided[1:])
(ok, ans) = solve()
if ok:
	print('Yes')
	print(*ans)
else:
	print('No')


import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)
N = int(input())
X = sorted(((x, i) for (i, x) in enumerate((int(x) for x in input().split()), 1)))
arr = []
for (x, i) in X:
	arr += [i] * (i - 1)
for (x, i) in X:
	arr += [i] * (N - i)
x_to_i = dict(X)
arr = arr[::-1]
answer = []
counter = [0] * (N + 1)
bl = True
for x in range(1, N * N + 1):
	if x in x_to_i:
		i = x_to_i[x]
		counter[i] += 1
		bl &= counter[i] == i
	else:
		i = arr.pop()
		counter[i] += 1
	answer.append(i)
if bl:
	print('Yes')
	print(*answer)
else:
	print('No')


from heapq import heappop, heappush
n = int(input())
a = list(map(int, input().split()))
dic = dict()
for (i, ai) in enumerate(a, 1):
	if ai - 1 in dic:
		print('No')
		eixt()
	dic[ai - 1] = i
hq = []
for (i, ai) in enumerate(a[1:], 2):
	heappush(hq, (ai - i, i - 1, i))
others = []
ans = []
for ind in range(n ** 2):
	if ind in dic:
		i = dic[ind]
		ans.append(i)
		others += [i] * (n - i)
		continue
	if hq:
		(num, rem, i) = heappop(hq)
		if num < ind:
			print('No')
			exit()
		elif rem == 1:
			ans.append(i)
		else:
			ans.append(i)
			heappush(hq, (num + 1, rem - 1, i))
	elif others:
		ans.append(others.pop())
	else:
		print('No')
		exit()
print('Yes')
print(' '.join(map(str, ans)))


N = int(input())
X = []
for (i, x) in enumerate(input().split()):
	X.append((int(x) - 1, i + 1))
X.sort()
(a, b, c, k, l) = (0, 0, 0, 0, 0)
ans = []
for i in range(N * N):
	if b <= N - 1:
		(x, p) = X[b]
		if x == i:
			if a <= b and p != 1:
				print('No')
				exit()
			ans.append(p)
			b += 1
			continue
	if a <= N - 1:
		(y, q) = X[a]
		if q == 1:
			a += 1
			if a == N:
				(z, r) = X[c]
				if c >= b:
					print('No')
					exit()
				if r == N:
					c += 1
					l = 0
					(z, r) = X[c]
				ans.append(r)
				l += 1
				if l == N - r:
					c += 1
					l = 0
				continue
			else:
				(y, q) = X[a]
				k = 0
		ans.append(q)
		k += 1
		if k == q - 1:
			a += 1
			k = 0
	else:
		(z, r) = X[c]
		if c >= b:
			print('No')
			exit()
		if r == N:
			c += 1
			l = 0
			(z, r) = X[c]
		ans.append(r)
		l += 1
		if l == N - r:
			c += 1
			l = 0
print('Yes')
print(' '.join(map(str, ans)))


import math, string, itertools, fractions, heapq, collections, re, array, bisect, sys, random, time
sys.setrecursionlimit(10 ** 7)
inf = 10 ** 20
mod = 10 ** 9 + 7

def main():
	n = int(input())
	a = list(map(int, input().split()))
	nn = n * n
	r = [-1] * nn
	ms = []
	us = []
	for i in range(n):
		c = i + 1
		ri = a[i] - 1
		r[ri] = c
		ms.append([ri, i, c])
		us.append([ri, n - i - 1, c])
	ms.sort()
	si = 0
	for (ri, k, c) in ms:
		for _ in range(k):
			while r[si] > 0 and si < nn - 1:
				si += 1
			if si > ri or r[si] > 0:
				print('No')
				return
			r[si] = c
	si = nn - 1
	us.sort()
	us.reverse()
	for (ri, k, c) in us:
		for _ in range(k):
			while r[si] > 0 and si > 0:
				si -= 1
			if si < ri or r[si] > 0:
				print('No')
				return
			r[si] = c
	print('Yes')
	print(' '.join(map(str, r)))
main()


import sys
N = int(input())
a = [-1] * N ** 2
x = list(map(lambda x: int(x) - 1, input().split()))
x = list(zip(x, list(range(1, N + 1))))
x.sort()
now = 0
for (v, i) in x:
	if a[v] >= 0:
		print('No')
		sys.exit()
	a[v] = i
	cnt = 0
	while cnt < i - 1:
		if now == v:
			print('No')
			sys.exit()
		if a[now] < 0:
			a[now] = i
			cnt += 1
		now += 1
now = N * N - 1
for (v, i) in reversed(x):
	cnt = 0
	while cnt < N - i:
		if now <= v:
			print('No')
			sys.exit()
		if a[now] < 0:
			a[now] = i
			cnt += 1
		now -= 1
if all((v >= 0 for v in a)):
	print('Yes')
	print(*a)
else:
	print('No')


N = int(input())
X = list(map(int, input().split()))
A = [-1] * N * N
sorted_X = sorted(X)
first_empty = 0
last_empty = N * N - 1
fail_flag = 0
for i in range(N):
	x = sorted_X[i]
	K = X.index(x) + 1
	if A[x - 1] == -1:
		A[x - 1] = K
	else:
		print('No')
		fail_flag = 1
		break
	K_rest = K - 1
	while K_rest > 0:
		while True:
			if A[first_empty] == -1:
				break
			first_empty = first_empty + 1
		if first_empty < x - 1:
			A[first_empty] = K
			K_rest = K_rest - 1
			first_empty = first_empty + 1
		else:
			print('No')
			fail_flag = 1
			break
	if fail_flag == 1:
		break
if fail_flag == 0:
	for i in range(N - 1, -1, -1):
		x = sorted_X[i]
		K = X.index(x) + 1
		K_rest = N - K
		while K_rest > 0:
			while True:
				if A[last_empty] == -1:
					break
				last_empty = last_empty - 1
			if last_empty > x - 1:
				A[last_empty] = K
				K_rest = K_rest - 1
				last_empty = last_empty - 1
			else:
				print('No')
				fail_flag = 1
				break
		if fail_flag == 1:
			break
if fail_flag == 0:
	print('Yes')
	for a in A:
		print(str(a), end=' ')


N = int(input())
x = list(map(int, input().split()))
ans = [0] * N ** 2
x = [(x[i] - 1, i + 1) for i in range(N)]
x.sort()
for i in range(N):
	(p, v) = x[i]
	ans[p] = v
pos = 0
for i in range(N):
	(val, count) = x[i]
	count -= 1
	while count:
		while ans[pos]:
			pos += 1
		if pos >= val:
			print('No')
			exit()
		else:
			ans[pos] = x[i][1]
			count -= 1
pos = N ** 2 - 1
for i in range(N - 1, -1, -1):
	(val, count) = x[i]
	count -= 1
	count = N - 1 - count
	while count:
		while ans[pos]:
			pos -= 1
		if val >= pos:
			print('No')
			exit()
		else:
			ans[pos] = x[i][1]
			count -= 1
print('Yes')
print(*ans)


import sys
readline = sys.stdin.readline

def check(A, X):
	N = len(A)
	Ans = [None] * N ** 2
	cnt = 0
	po = 0
	for i in range(N):
		(a, x) = (A[i], X[i])
		a += 1
		x -= 1
		if Ans[x] is not None:
			return False
		cnt += a - 1
		if cnt > x:
			return False
		cnt += 1
		Ans[x] = a
		res = a - 1
		while res:
			if Ans[po] is None:
				res -= 1
				Ans[po] = a
			po += 1
	cnt = 0
	po = N ** 2 - 1
	for i in range(N - 1, -1, -1):
		(a, x) = (A[i], X[i])
		a += 1
		x -= 1
		cnt += N - a
		if N ** 2 - x < 1 + cnt:
			return False
		cnt += 1
		res = N - a
		while res:
			if Ans[po] is None:
				res -= 1
				Ans[po] = a
			po -= 1
	return Ans
N = int(readline())
X = list(map(int, readline().split()))
A = sorted(list(range(N)), key=lambda x: X[x])
X.sort()
Ans = check(A, X)
if Ans:
	print('Yes')
	print(*Ans)
else:
	print('No')


N = int(input())
X = list(map(lambda x: int(x) - 1, input().split()))
Ans = [0] * (N * N)
for (i, x) in enumerate(X, 1):
	Ans[x] = i
Y = list(range(1, N + 1))
Y.sort(key=lambda y: X[y - 1])
q1 = []
q1_cnt = [0] * (N + 1)
for y in Y:
	q1 += [y] * (y - 1)
	q1_cnt[y] += y - 1
q1.reverse()
q2 = []
for (i, a) in enumerate(Ans[:]):
	if a == 0:
		if q1:
			v = q1.pop()
			Ans[i] = v
			q1_cnt[v] -= 1
		elif q2:
			Ans[i] = q2.pop()
		else:
			print('No')
			exit()
	else:
		if q1_cnt[a] > 0:
			print('No')
			exit()
		q2 += [a] * (N - a)
print('Yes')
print(' '.join(map(str, Ans)))


n = int(input())
a = list(map(int, input().split()))
ans = [-1] * n ** 2
for i in range(n):
	ans[a[i] - 1] = i + 1
b = sorted([(a[i], i + 1) for i in range(n)], reverse=True)
stack = []
for (_, val) in b:
	for _ in range(val - 1):
		stack.append(val)
for i in range(n ** 2):
	if ans[i] == -1:
		if not stack:
			continue
		ans[i] = stack.pop()
b = sorted([(a[i], i + 1) for i in range(n)])
stack = []
for (_, val) in b:
	for _ in range(n - val):
		stack.append(val)
for i in range(n ** 2)[::-1]:
	if ans[i] == -1:
		if not stack:
			continue
		ans[i] = stack.pop()
cnt = [0] * (n + 1)
for i in range(n ** 2):
	cnt[ans[i]] += 1
	if cnt[ans[i]] == ans[i]:
		if a[ans[i] - 1] == i + 1:
			continue
		else:
			print('No')
			exit()
print('Yes')
print(*ans)


def solve(n, xxx):
	n2 = n ** 2
	yyy = sorted(((x - 1, k) for (k, x) in enumerate(xxx, start=1)))
	i = 0
	ans = [-1] * n2
	for (x, k) in yyy:
		j = k - 1
		while j:
			while ans[i] != -1:
				i += 1
			ans[i] = k
			i += 1
			j -= 1
		if i > x:
			return False
		ans[x] = k
	for (x, k) in yyy:
		while i < n2 and ans[i] != -1:
			i += 1
		if i < x:
			return False
		j = n - k
		while j:
			while i < n2 and ans[i] != -1:
				i += 1
			if i == n2:
				return False
			ans[i] = k
			i += 1
			j -= 1
	return ans
n = int(input())
xxx = list(map(int, input().split()))
result = solve(n, xxx)
if result:
	print('Yes')
	print(*result)
else:
	print('No')


def N():
	return int(input())

def NM():
	return map(int, input().split())

def L():
	return list(NM())

def LN(n):
	return [N() for i in range(n)]

def LL(n):
	return [L() for i in range(n)]
n = N()
l = [(j, i) for (i, j) in enumerate(L(), 1)]
l.sort()
ans = [0] * (n * n + 1)
k = 1

def No():
	print('No')
	quit()
for (j, i) in l:
	if ans[j] != 0:
		No()
	ans[j] = i
	x = 0
	while x < i - 1:
		if ans[k] == 0:
			ans[k] = i
			x += 1
		k += 1
	if k > j:
		No()
l.sort(reverse=True)
k = n * n
for (j, i) in l:
	if i == n:
		continue
	x = 0
	while x < n - i:
		if ans[k] == 0:
			ans[k] = i
			x += 1
		k -= 1
	if k < j:
		No()
print('Yes')
print(' '.join(map(str, ans[1:])))


def examA():
	(x, y) = LI()
	ans = 0
	if x < 0 and y < 0:
		if x <= y:
			ans = y - x
		else:
			ans = x - y + 2
	elif x < 0 and 0 <= y:
		if -x <= y:
			ans = y + x + 1
		else:
			ans = min(-(x + y) + 1, y - x)
	elif y <= 0:
		ans = abs(y + x) + 1
	elif x <= y:
		ans = y - x
	else:
		ans = x - y + 2
	print(ans)
	return

def examB():
	(B, K) = LI()
	A = LI()
	cumA = [0] * (B + 1)
	negA = [0] * (B + 1)
	for (i, a) in enumerate(A):
		cumA[i + 1] = cumA[i]
		negA[i + 1] = negA[i]
		if a > 0:
			cumA[i + 1] += a
		else:
			negA[i + 1] += a
	ans = 0
	for i in range(B - K + 1):
		curC = cumA[K + i] - cumA[i]
		curN = negA[K + i] - negA[i]
		now1 = cumA[B] + curN
		now2 = cumA[B] - curC
		ans = max(ans, now1, now2)
	print(ans)
	return

def examC():
	(Ai, Ao, At, Aj, Al, As, Az) = LI()
	ans = 0
	ans += Ao
	ans += (Ai // 2 + Aj // 2 + Al // 2) * 2
	if Ai >= 1 and Aj >= 1 and (Al >= 1):
		if Ai % 2 + Aj % 2 + Al % 2 == 3:
			ans += 3
		elif Ai % 2 + Aj % 2 + Al % 2 == 2:
			ans += 1
	print(ans)
	return

def examD():
	N = I()
	X = LI()
	A = [0] * N ** 2
	que = deque()
	ans = 'Yes'
	need = [0] * N ** 2
	for i in range(N):
		need[X[i] - 1] = i
	for i in range(N):
		A[X[i] - 1] = i + 1
	X.sort()
	k = 0
	for i in range(N):
		cur = need[X[i] - 1]
		for j in range(cur):
			while A[k] != 0:
				k += 1
			A[k] = A[X[i] - 1]
		if k >= X[i]:
			ans = 'No'
			break
		res = N - 1 - cur
		que.append((res, i))
	loop = 0
	if ans == 'No':
		print(ans)
		return
	while que and k < N ** 2 and (loop < 10 ** 6):
		loop += 1
		(cur, i) = que.popleft()
		while k < N ** 2 and A[k] != 0:
			k += 1
		if k < X[i] and cur > 0:
			que.append((cur, i))
			continue
		for j in range(cur):
			while k < N ** 2 and A[k] != 0:
				k += 1
			A[k] = A[X[i] - 1]
	if que or loop >= 10 ** 6:
		ans = 'No'
	if ans == 'No':
		print(ans)
		return
	else:
		print(ans)
		print(' '.join(map(str, A)))
	return
import sys, copy, bisect, itertools, heapq, math
from heapq import heappop, heappush, heapify
from collections import Counter, defaultdict, deque

def I():
	return int(sys.stdin.readline())

def LI():
	return list(map(int, sys.stdin.readline().split()))

def LSI():
	return list(map(str, sys.stdin.readline().split()))

def LS():
	return sys.stdin.readline().split()

def SI():
	return sys.stdin.readline().strip()
global mod, mod2, inf
mod = 10 ** 9 + 7
mod2 = 998244353
inf = 10 ** 18
examD()


n = int(input())
x = list(map(int, input().split()))
ans = [0] * (n ** 2 + 1)
for (k, v) in enumerate(x):
	ans[v] = k + 1
x = sorted([[v, k] for (k, v) in enumerate(x)])
now = 1
for (k, v) in x:
	num = v + 1
	while v:
		if ans[now]:
			if ans[now] == num:
				print('No')
				exit()
		else:
			ans[now] = num
			v -= 1
		now += 1
now2 = n ** 2
for (k, v) in reversed(x):
	num = v + 1
	quant = n - num
	while quant:
		if ans[now2]:
			if ans[now2] == num:
				print('No')
				exit()
		else:
			ans[now2] = num
			quant -= 1
		now2 -= 1
print('Yes')
print(*ans[1:])


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)


def solve(X):
	N = len(X)
	X = sorted(((x, i) for (i, x) in enumerate(X, start=1)))
	L = N ** 2
	res = [-1] * L
	i = 0
	for (x, n) in X:
		r = n - 1
		while r > 0 and i < x:
			if res[i] < 0:
				res[i] = n
				r -= 1
			i += 1
		if res[x] > 0 or r > 0:
			return None
		else:
			res[x] = n
	i = L
	for (x, n) in reversed(X):
		r = N - n
		while r > 0 and i > x:
			if res[i - 1] < 0:
				res[i - 1] = n
				r -= 1
			i -= 1
		if r > 0:
			return None
	return res
from itertools import permutations

def naive(X):
	N = len(X)
	for a in permutations(list(range(N)) * N):
		for (i, x) in enumerate(X):
			if not (a[x] == i and sum((v == i for v in a[:x])) == i):
				break
		else:
			return [v + 1 for v in a]
	return None
from random import shuffle
N = int(input())
X = [int(x) - 1 for x in input().split()]
r = solve(X)
if r is None:
	print('No')
else:
	print('Yes')
	print(*r)


N = int(input())
x = list(map(int, input().split()))
x_ = [(x[i], i + 1) for i in range(N)]
x_.sort(key=lambda s: s[0])
seq = [x_[i][1] for i in range(N)]
left = []
for s in seq:
	left.extend([s] * (s - 1))
right = []
for s in reversed(seq):
	right.extend([s] * (N - s))
right.reverse()
ans_raw = left + right
ans_raw.reverse()
ans = [0] * N ** 2
for (i, xi) in enumerate(x):
	ans[xi - 1] = -(i + 1)
for i in range(N ** 2):
	if ans[i] == 0:
		ans[i] = ans_raw.pop()
cnt_list = [0] * (N + 1)
for i in range(N ** 2):
	if ans[i] < 0:
		if cnt_list[-ans[i]] != -ans[i] - 1:
			print('No')
			exit()
	else:
		cnt_list[ans[i]] += 1
print('Yes')
ans = list(map(abs, ans))
print(*ans)


import sys
input = sys.stdin.readline
N = int(input())
a = list(map(int, input().split()))
b = [(a[i], i) for i in range(N)]
b.sort()
res = [0] * pow(N, 2)
for i in range(N):
	res[a[i] - 1] = i + 1
for k in range(N):
	i = b[k][1]
	x = i
	if i == 0:
		continue
	for j in range(a[i] - 1):
		if res[j]:
			continue
		res[j] = i + 1
		x -= 1
		if x == 0:
			break
	if x:
		print('No')
		exit(0)
for i in range(N):
	x = N - i - 1
	for j in range(a[i], N ** 2):
		if res[j]:
			continue
		res[j] = i + 1
		x -= 1
		if x == 0:
			break
	if x:
		print('No')
		exit(0)
print('Yes')
print(*res)


n = int(input())
a = [int(i) for i in input().split()]
a_num = [(v, num + 1) for (num, v) in enumerate(a)]
ans = [0] * n ** 2
for (i, v) in enumerate(a):
	ans[v - 1] = i + 1
a_num.sort()
judge = True
ind = 0
for (v, num) in a_num:
	cnt = 0
	while not cnt == num - 1:
		if ans[ind] == 0:
			ans[ind] = num
			cnt += 1
		elif ans[ind] == num:
			judge = False
			break
		ind += 1
a_num.reverse()
ind = n * n - 1
for (v, num) in a_num:
	cnt = 0
	while not cnt == n - num:
		if ans[ind] == 0:
			ans[ind] = num
			cnt += 1
		elif ans[ind] == num:
			judge = False
			break
		ind -= 1
if judge == True:
	print('Yes')
	print(*ans)
else:
	print('No')


import sys
sys.setrecursionlimit(10000000)
MOD = 10 ** 9 + 7
INF = 10 ** 15

def main():
	N = int(input())
	X = list(enumerate(map(int, input().split())))
	X.sort(key=lambda x: x[1])
	M = N * N
	ans = [None] * M
	now = 0
	for (i, x) in X:
		ans[x - 1] = i + 1
		count = i
		while count > 0:
			while ans[now]:
				now += 1
			if now >= x:
				print('No')
				return
			ans[now] = i + 1
			count -= 1
	now = M - 1
	for (i, x) in X[::-1]:
		count = N - i - 1
		while count > 0:
			while ans[now]:
				now -= 1
			if now < x:
				print('No')
				return
			ans[now] = i + 1
			count -= 1
	print('Yes')
	print(' '.join(map(str, ans)))
main()


import os
import sys
from collections import deque, defaultdict
if os.getenv('LOCAL'):
	sys.stdin = open('_in.txt', 'r')
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
IINF = 10 ** 18
MOD = 10 ** 9 + 7
N = int(sys.stdin.buffer.readline())
X = list(map(int, sys.stdin.buffer.readline().split()))
ans = [None] * (N ** 2 + 1)
P = list(sorted([(pos, i) for (i, pos) in enumerate(X, 1)]))
que = deque()
for (p, i) in P:
	ans[p] = i
	for _ in range(i - 1):
		que.append(i)
for p in range(1, N ** 2 + 1):
	if ans[p] is not None:
		i = ans[p]
		for _ in range(N - i):
			que.append(i)
	else:
		if not que:
			break
		ans[p] = que.popleft()

def is_ok(ans, que):
	if que:
		return False
	for a in ans[1:]:
		if a is None:
			return False
	counts = defaultdict(int)
	C = [0]
	for a in ans[1:]:
		counts[a] += 1
		C.append(counts[a])
	for (i, x) in enumerate(X, 1):
		if C[x] != i:
			return False
	return True
if is_ok(ans, que):
	print('Yes')
	print(*ans[1:])
else:
	print('No')


def solve():
	n = int(input())
	x = list(map(int, input().split()))
	list1 = []

	def ap1(num):
		list1.append(num)
	for i in range(n):
		ap1([x[i], i + 1])
	str1 = lambda val: val[0]
	list1.sort(key=str1)
	numa = []
	numb = []
	for i in range(n):
		num3 = list1[i][1]
		numa += [num3] * (num3 - 1)
		numb += [num3] * (n - num3)
	count1 = 0
	count2 = 0
	count3 = 0
	ans = []
	ansnum = 0

	def countnum(num):
		return ans.count(num)

	def apans(num):
		ans.append(num)
	for i in range(n * n):
		yn = 0
		if count1 != n:
			if i == list1[count1][0] - 1:
				if countnum(list1[count1][1]) != list1[count1][1] - 1:
					ansnum = 1
					break
				apans(list1[count1][1])
				count1 += 1
				yn = 1
		if yn == 0:
			if count2 != len(numa):
				apans(numa[count2])
				count2 += 1
			elif count3 != len(numb):
				apans(numb[count3])
				count3 += 1
			elif i != n * n - 1:
				ansnum = 1
				break
	if ansnum == 1:
		print('No')
	else:
		print('Yes')
		print(*ans)
solve()