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 Rust (1.15.1) (judge verdict: Runtime Error)

/// Thank you tanakh!!!
/// https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let mut s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };

    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };

    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };

    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

use std::cmp;

fn main() {
    input!(n: usize, a: usize, b: usize);
    if a + b > n + 1 {
        println!("-1");
    } else if cmp::min(a + n / a, b + n / b) > a + b {
        println!("-1");
    } else {
        let (a, b, reversed) = if a > b { (a, b, false) } else { (b, a, true) };

        let mut ans = vec![];
        let one_box = b;
        let num_box = (n + b - 1) / b;

        let mut cur = n;
        for _ in 0..num_box {
            let mut b = vec![];
            for _ in 0..one_box {
                b.push(cur);
                cur -= 1;
                if cur == 0 {
                    break;
                }
            }
            ans.push(b);
        }
        ans.reverse();

        if a < num_box {
            unimplemented!();
        }
        let mut rest = a - num_box;
        assert!(n - one_box + 1 >= a);

        for i in 0..num_box {
            if ans[i].len() <= rest {
                ans[i].reverse();
                rest -= ans[i].len();
            } else {
                let mut next: Vec<usize> = vec![];
                for _ in 0..rest {
                    let t: usize = ans[i].pop().unwrap();
                    next.push(t);
                }
                for &t in ans[i].iter() {
                    next.push(t);
                }
                ans[i] = next;
                rest = 0;
            }

            if rest == 0 {
                break;
            }
        }

        let mut answer: Vec<usize> = vec![];
        for ans in ans.iter() {
            for &ans in ans.iter() {
                answer.push(ans);
            }
        }
        if reversed {
            answer.reverse();
        }

        for i in 0..n {
            if i > 0 {
                print!(" ");
            }
            print!("{}", answer[i]);
        }
        println!();
    }
}