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 in C++14 (GCC 5.4.1) (judge verdict: Wrong Answer)

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
 

signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(20);
    
    
    int n;
    cin>>n;
    int ans[n*n]={};
    array<int,2> a[n];
    for(int i=0;i<n;i++){
        int x;
        cin>>x;
        a[i] = {x,i};
        ans[x-1] = i+1;
    }
    sort(a,a+n);
    int now = 0;
    int cnt = 0;
    bool used[n+5]={};
    bool pos = true;
    for(int i=0;i<n*n;i++){
        if(cnt == a[now][1]){
            cnt = 0;
            now++;
        }
        if(now == n) break;
        if(ans[i]){
            if(a[now][1]+1 == ans[i])pos=false;
            used[ans[i]] = 1;
            continue;
        }
        if(used[a[now][1]+1]) pos = false;
        ans[i] = a[now][1]+1;
        cnt++;
    }
    now = n-1;
    cnt = 0;

    for(int i=n*n-1;i>=0;i--){
        if(ans[i])continue;
        if(cnt == n - a[now][1] - 1){
            cnt = 0;
            now--;
        }
        if(now == -1) break;
        ans[i] = a[now][1]+1;
        cnt++;
    }
    for(int i=0;i<n*n;i++){
        if(!ans[i])pos=false;
    }
    int c[n+1]={};
    now = 0;
    for(int i=0;i<n;i++){
        c[ans[i]]++;
        if(a[now][0] == i+1){
            if(c[a[now][1]+1] != a[now][1]+1)pos=false;
            now++;
        }
    }
    if(pos){
        cout << "Yes\n";
        for(int i=0;i<n*n;i++){
            cout << ans[i] << " ";
        }
        cout << "\n";
    }
    else cout << "No\n";
}