Problem:
Score : 1500 points

Problem Statement

Given are an integer K and integers a_1,\dots, a_K. Determine whether a sequence P satisfying below exists. If it exists, find the lexicographically smallest such sequence.

Every term in P is an integer between 1 and K (inclusive).

For each i=1,\dots, K, P contains a_i occurrences of i.

For each term in P, there is a contiguous subsequence of length K that contains that term and is a permutation of 1,\dots, K.

Constraints

1 \leq K \leq 100

1 \leq a_i \leq 1000 \quad (1\leq i\leq K)

a_1 + \dots + a_K\leq 1000

All values in input are integers.

Input

Input is given from Standard Input in the following format:

K
a_1 a_2 \dots a_K

Output

If there is no sequence satisfying the conditions, print -1.
Otherwise, print the lexicographically smallest sequence satisfying the conditions.

Sample Input 1

3
2 4 3

Sample Output 1

2 1 3 2 2 3 1 2 3

For example, the fifth term, which is 2, is in the subsequence (2, 3, 1) composed of the fifth, sixth, and seventh terms.

Sample Input 2

4
3 2 3 2

Sample Output 2

1 2 3 4 1 3 1 2 4 3

Sample Input 3

5
3 1 4 1 5

Sample Output 3

-1

Solution in C# (.NET Core 3.1.201) (judge verdict: Wrong Answer)

using System;
using System.Text;
using System.Diagnostics;
using System.Numerics;
using System.Collections.Generic;

class Myon

{
    public Myon() { }
    public static int Main()
    {
        cin = new Scanner();
        new Myon().calc();
        return 0;
    }
    static Scanner cin;
    int mod = 998244353;

    void calc()
    {
        int K = cin.nextInt();
        int[] A = cin.ArrayInt(K);
        int min = 999999;
        int max = 0;
        for (int i = 0; i < A.Length; i++)
        {
            min = Math.Min(min, A[i]);
            max = Math.Max(max, A[i]);
        }
        if(min * 2 < max)
        {
            Console.WriteLine(-1);
            return;
        }
        List<int> ans = new List<int>();

        for (int t = 0; t < min; t++)
        {
            int nokori = min - t;
            List<int> over = new List<int>();
            List<int> under = new List<int>();

            int overMax = -1;
            for (int i = 0; i < K; i++)
            {
                if(A[i] == nokori * 2)
                {
                    overMax = i;
                }
            }

            bool first = true;
            for (int i = 0; i < K; i++)
            {
                if((A[i] > nokori && (first || i <= overMax)))
                {
                    A[i] -= 2;
                    over.Add(i + 1);
                    if (A[i] > nokori - 1) first = false;
                }
                else
                {
                    A[i]--;
                    under.Add(i + 1);
                    first = false;
                }
            }
            foreach (var item in over)
            {
                ans.Add(item);
            }

            foreach (var item in under)
            {
                ans.Add(item);
            }

            foreach (var item in over)
            {
                ans.Add(item);
            }
        }

        Console.WriteLine(string.Join(" ", ans));

    }

}


class Scanner
{
    string[] s;
    int i;

    char[] cs = new char[] { ' ' };

    public Scanner()
    {
        s = new string[0];
        i = 0;
    }

    public string next()
    {
        if (i < s.Length) return s[i++];
        string st = Console.ReadLine();
        while (st == "") st = Console.ReadLine();
        s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
        if (s.Length == 0) return next();
        i = 0;
        return s[i++];
    }

    public int nextInt()
    {
        return int.Parse(next());
    }
    public int[] ArrayInt(int N, int add = 0)
    {
        int[] Array = new int[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = nextInt() + add;
        }
        return Array;
    }

    public long nextLong()
    {
        return long.Parse(next());
    }

    public long[] ArrayLong(int N, long add = 0)
    {
        long[] Array = new long[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = nextLong() + add;
        }
        return Array;
    }

    public double nextDouble()
    {
        return double.Parse(next());
    }


    public double[] ArrayDouble(int N, double add = 0)
    {
        double[] Array = new double[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = nextDouble() + add;
        }
        return Array;
    }
}