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 Java8 (OpenJDK 1.8.0) (judge verdict: Wrong Answer)

import java.io.*;
import java.util.Arrays;
import java.util.StringJoiner;
import java.util.StringTokenizer;
import java.util.function.IntBinaryOperator;

public class Main {

    static int N, A, B;

    public static void main(String[] args) {
        FastScanner sc = new FastScanner(System.in);
        N = sc.nextInt();
        A = sc.nextInt();
        B = sc.nextInt();

        int[] arr = solve();
        if( arr == null ) {
            System.out.println(-1);
        } else {
            StringJoiner j = new StringJoiner(" ");
            for (int i : arr) {
                j.add(String.valueOf(i));
            }
            System.out.println(j.toString());
        }
    }

    static int[] solve(int n, int a, int b) {
        N = n;
        A = a;
        B = b;
        return solve();
    }

    static int[] solve() {
        if( A + B > N + 1 ) return null;
        if( N > A * B ) return null;


        // LISでカードを並べた気持ちになる
        // 縦にならんだ数がLDSになる模様
        //
        // 例 N = 14, A = 5, B = 3の場合
        // 10 11 12 13 14
        //  2  6  7  8  9
        //  1  3  4  5
        // -> [11 12 13 14 15 2 7 8 9 10 1 3 4 5 6]

        int[] arr = new int[N];

        // まず LISの長さを確保する
        for (int i = 0; i < A; i++) {
            arr[i] = N - A + i + 1;
        }

        if( B == 1 ) return arr;

        // カードの高さがLDS
        // すでに一枚はならんでいるのでそれを考慮する
        int H = B - 1;
        int W = ((N - A) + (H - 1)) / H;

        // [from, to)
        int idx = A;
        int from = H + 1;
        int to = N - A + 1;
        for (int h = 0; h < H; h++) {
            arr[idx++] = H - h ;
            if( from == to ) continue;
            int f = Math.max(to - (W-1), from);
            int t = to;
            to = f;

            int cur = f;
            for (int w = 1; w < W; w++) {
                if( cur < t ) {
                    arr[idx++] = cur++;
                }
            }
        }

        return arr;
    }

    @SuppressWarnings("unused")
    static class FastScanner {
        private BufferedReader reader;
        private StringTokenizer tokenizer;

        FastScanner(InputStream in) {
            reader = new BufferedReader(new InputStreamReader(in));
            tokenizer = null;
        }

        String next() {
            if (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

        String nextLine() {
            if (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    return reader.readLine();
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken("\n");
        }

        long nextLong() {
            return Long.parseLong(next());
        }

        int nextInt() {
            return Integer.parseInt(next());
        }

        int[] nextIntArray(int n) {
            int[] a = new int[n];
            for (int i = 0; i < n; i++)
                a[i] = nextInt();
            return a;
        }

        long[] nextLongArray(int n) {
            long[] a = new long[n];
            for (int i = 0; i < n; i++)
                a[i] = nextLong();
            return a;
        }
    }
}