Problem:
 Score : 800 points    Problem Statement 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.        Sample Input 1 3
1 5 9      Sample Output 1 Yes
1 1 1 2 2 2 3 3 3  For example, the second occurrence of the integer 2 from the left in a in the output is the fifth element of a from the left.
Similarly, the condition is satisfied for the integers 1 and 3 .       Sample Input 2 2
4 1      Sample Output 2 No

Solution (Python):
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

if __name__ == '__main__':

    
    
    
    
    

    
    
    
    
    
    
    

    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)

Solution (Python):
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:])

Solution (Python):
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))
    else:
        if(others):
            ans.append(others.pop())
        else:
            print('No')
            exit()



print('Yes')
print(' '.join(map(str,ans)))

Solution (Python):
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)

Solution (Python):
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)

Solution (Python):
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)

Solution (Python):
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
            else:
                if i!=n*n-1:
                    ansnum=1
                    break
    if ansnum==1:
        print("No")
    else:
        print("Yes")
        print(*ans)
solve()

Solution (Python):
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)))
if __name__ == '__main__':
    main()

Solution (Python):
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:])))

Solution (Python):
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)

Solution (Python):











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])
if __name__ == '__main__':
    main()

Solution (Python):
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()

Solution (Python):
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)

Solution (Python):
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=" ")

Solution (Python):
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)

Solution (Python):

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

Solution (Python):
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')

Solution (Python):
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)

Solution (Python):
N, *X = map(int, open(0).read().split())

X = sorted(((x, i) for i, x in enumerate(X, 1)), key=lambda x: x[0])
x_to_i = dict(X)

T = []
for x, i in X:
    T += [i] * (i - 1)
for x, i in X:
    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] != i - 1:
            print("No")
            quit()
    else:
        i = next(T)
    C[i] += 1
    A.append(i)

print("Yes")
print(*A)

Solution (Python):

N, *X = map(int, open(0).read().split())

X = sorted(enumerate(X, 1), key=lambda x: x[1])
x_to_i = {x: i for i, x in X}

T = []
for i, x in X:
    T += [i] * (i - 1)
for i, x in X:
    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] != i - 1:
            print("No")
            quit()
    else:
        i = next(T)
    C[i] += 1
    A.append(i)

print("Yes")
print(*A)

Solution (Python):
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')

Solution (Python):
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
    else:
        if 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)

Solution (Python):
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')

Solution (Python):




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:]

if __name__ == "__main__":
    ok, ans = solve()
    if ok:
        print("Yes")
        print(*ans)
    else:
        print("No")

Solution (Python):
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)

Solution (Python):
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:])

Solution (Python):
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:])

Solution (Python):
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
    else:
        if 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
"""
3
6 7 8
"""
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

if __name__ == '__main__':
    examD()

Solution (Python):
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')

Solution (Python):
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)

Solution (Python):
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)))

Solution (Python):
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])

    else:

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