Problem:
Score : 700 points

Problem Statement

Determine if there exists a sequence obtained by permuting 1,2,...,N that satisfies the following conditions:

The length of its longest increasing subsequence is A.

The length of its longest decreasing subsequence is B.

If it exists, construct one such sequence.

Notes

A subsequence of a sequence P is a sequence that can be obtained by extracting some of the elements in P without changing the order.

A longest increasing subsequence of a sequence P is a sequence with the maximum length among the subsequences of P that are monotonically increasing.

Similarly, a longest decreasing subsequence of a sequence P is a sequence with the maximum length among the subsequences of P that are monotonically decreasing.

Constraints

1 \leq N,A,B \leq 3\times 10^5

All input values are integers.

Input

Input is given from Standard Input in the following format:

N A B

Output

If there are no sequences that satisfy the conditions, print -1.

Otherwise, print N integers. The i-th integer should be the i-th element of the sequence that you constructed.

Sample Input 1

5 3 2

Sample Output 1

2 4 1 5 3

One longest increasing subsequence of this sequence is {2,4,5}, and one longest decreasing subsequence of it is {4,3}.

Sample Input 2

7 7 1

Sample Output 2

1 2 3 4 5 6 7

Sample Input 3

300000 300000 300000

Sample Output 3

-1

Solution in C# (Mono 4.6.2.0) (judge verdict: Runtime Error)

using System;
using System.Collections;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Diagnostics;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

public static class TemplateExtension
{
    public static X[] MakeArray<X>(this int count, Func<int, X> func)
    {
        var xs = new X[count];
        for (var i = 0; i < count; i++)
        {
            xs[i] = func(i);
        }
        return xs;
    }

    public static int[] Range(this int count, int start = 0)
    {
        return count.MakeArray(i => i + start);
    }

    public static string Intercalate<X>(this IEnumerable<X> @this, string separator)
    {
        return string.Join(separator, @this);
    }

    public sealed class ValueIndexPair<T>
        : Tuple<T, int>
    {
        public T Value { get { return Item1; } }
        public int Index { get { return Item2; } }

        public ValueIndexPair(T value, int index)
            : base(value, index)
        {
        }
    }

    public static IEnumerable<ValueIndexPair<X>> Indexed<X>(this IEnumerable<X> @this)
    {
        var i = 0;
        foreach (var x in @this)
        {
            yield return new ValueIndexPair<X>(x, i);
            i++;
        }
    }
}

public sealed class Scanner
{
    private readonly TextReader _reader;
    private readonly StringBuilder _sb = new StringBuilder();

    /// <summary>
    /// Reads next word separated by spaces.
    /// </summary>
    public string Word()
    {
        _sb.Clear();

        while (true)
        {
            var r = _reader.Read();

            if (r == ' ' || r == '\r' || r == '\n')
            {
                if (r == '\r' && _reader.Peek() == '\n')
                {
                    _reader.Read();
                }

                // Ignore leading spaces.
                if (_sb.Length == 0) continue;

                break;
            }
            else if (r == -1)
            {
                break;
            }
            else
            {
                _sb.Append((char)r);
            }
        }

        return _sb.ToString();
    }

    /// <summary>
    /// Reads next word as <see cref="int"/>.
    /// </summary>
    public int N()
    {
        return int.Parse(Word().Trim());
    }

    /// <summary>
    /// Reads next word as <see cref="long"/>.
    /// </summary>
    public long L()
    {
        return long.Parse(Word());
    }

    /// <summary>
    /// Reads next word as <see cref="double"/>.
    /// </summary>
    public double F()
    {
        return double.Parse(Word());
    }

    /// <summary>
    /// Reads next line and splits it by spaces.
    /// </summary>
    public X[] Words<X>(Func<string, X> func)
    {
        return _reader.ReadLine().Split(' ').Select(func).ToArray();
    }

    public Scanner(TextReader reader)
    {
        _reader = reader;
    }
}

public partial class Program
{
    private readonly TextReader _input;
    private readonly TextWriter _output;
    private readonly Scanner _scanner;

    private void WriteLine(int value)
    {
        _output.WriteLine(value);
    }

    private void WriteLine(long value)
    {
        _output.WriteLine(value);
    }

    private void WriteLine(double value)
    {
        _output.WriteLine(value.ToString(CultureInfo.InvariantCulture));
    }

    private void WriteLine(char value)
    {
        _output.WriteLine(value);
    }

    private void WriteLine(string value)
    {
        _output.WriteLine(value);
    }

    public Program(TextReader input, TextWriter output)
    {
        _input = input;
        _output = output;
        _scanner = new Scanner(input);
    }

    public static void Main(string[] args)
    {
        new Program(Console.In, Console.Out).EntryPoint();
    }
}

public sealed partial class Program
{
    int N, A, B;

    static int[] Failure = new[] { -1 };

    private int[] Solve()
    {
        if (A == N && B == 1)
        {
            return Enumerable.Range(1, N).ToArray();
        }
        if (A == 1 && B == N)
        {
            return Enumerable.Range(1, N).Reverse().ToArray();
        }

        if (A <= 1 || B <= 1) return Failure;
        if (N <= A || N <= B) return Failure;

        var chunkLengths = new int[B];
        {
            chunkLengths[0] = A;

            var m = N - A; // >= 1
            var k = B - 1; // >= 1

            // m 個のものを k パーツに分ける
            var r = m / k;
            if (k >= 2 && m % k != 0)
            {
                for (var i = 1; i < B - 1; i++)
                {
                    chunkLengths[i] = m / k;
                }
                chunkLengths[B - 1] = m % k;
            }
            else
            {
                for (var i = 1; i < B; i++)
                {
                    chunkLengths[i] = m / k;
                }
            }
        }

        if (chunkLengths.Sum() != N) throw new Exception("Bug.");

        if (!(chunkLengths.Length == B
        && chunkLengths.All(l => l >= 1)))
        {
            return Failure;
        }

        var chunks = B.MakeArray(i => new int[chunkLengths[i]]);
        var queue = new Queue<Tuple<int, int>>();
        for (var j = 0; j < B; j++)
        {
            queue.Enqueue(Tuple.Create(j, 0));
        }
        for (var i = 0; i < N; i++)
        {
            var pair = queue.Dequeue();
            var j = pair.Item1;
            var k = pair.Item2;

            chunks[j][k] = 1 + i;

            if (k + 1 < chunkLengths[j])
            {
                queue.Enqueue(Tuple.Create(j, k + 1));
            }
        }

        var result = new int[N];
        {
            var i = 0;
            foreach (var chunk in chunks.Reverse())
            {
                foreach (var x in chunk)
                {
                    result[i] = x;
                    i++;
                }
            }
        }
        return result;
    }

    public void EntryPoint()
    {
        var I = _scanner;
        N = I.N();
        A = I.N();
        B = I.N();

        WriteLine(Solve().Select(x => x.ToString()).Intercalate(" "));
    }
}