ICM Technex 2018 and Codeforces Round 463 (Div. 1 + Div. 2, combined)
C
Permutation Cycle
Codeforces
1600
原题
← BD →
翻译中…

For a permutation $*P*[1... *N*]$ of integers from $1$ to $*N*$, function $*f*$ is defined as follows:

翻译中…

image

翻译中…

Let $*g*(*i*)$ be the minimum positive integer $*j*$ such that $*f*(*i*, *j*) = *i*$. We can show such $*j*$ always exists.

翻译中…

For given $*N*, *A*, *B*$, find a permutation $*P*$ of integers from $1$ to $*N*$ such that for $1 ≤ *i* ≤ *N*$, $*g*(*i*)$ equals either $*A*$ or $*B*$.

翻译中…

Input

翻译中…

The only line contains three integers $*N*, *A*, *B*$ ($1 ≤ *N* ≤ 10^{6}, 1 ≤ *A*, *B* ≤ *N*$).

翻译中…

Output

翻译中…

If no such permutation exists, output -1. Otherwise, output a permutation of integers from $1$ to $*N*$.

翻译中…

Note

翻译中…

In the first example, $*g*(1) = *g*(6) = *g*(7) = *g*(9) = 2$ and $*g*(2) = *g*(3) = *g*(4) = *g*(5) = *g*(8) = 5$

翻译中…

In the second example, $*g*(1) = *g*(2) = *g*(3) = 1$

翻译中…

样例

Input #1
9 2 5
Output #1
6 5 8 3 4 1 9 2 7
InputCopy OutputCopy
Input #2
3 2 1
Output #2
1 2 3
InputCopy OutputCopy
题目信息
题号
932C
时间限制
2 s
内存限制
256 MB
标签
暴力
构造

题面与样例版权归 Codeforces 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。