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

 $f(i, j) = \left\{\begin{array}{ll}{P [ i ]} & {\text{if} j = 1} \\{f(P [ i ], j - 1)} & {\text{otherwise}} \end{array} \right.$ 

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.


-----Examples-----
Input
9 2 5

Output
6 5 8 3 4 1 9 2 7
Input
3 2 1

Output
1 2 3 


-----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

Difficulty: MEDIUM_HARD

Solutions:
from sys import stdin, stdout
(n, a, b) = map(int, input().split())
found = False
for x in range(n + 1):
	if (n - a * x) % b == 0:
		y = (n - a * x) // b
		if y >= 0:
			found = True
			break
if not found:
	print(-1)
	exit()
ans = []
(l, r) = (0, 1)
for _ in range(x):
	l = r
	r = l + a
	for i in range(l, r):
		if i + 1 == r:
			ans.append(l)
		else:
			ans.append(i + 1)
for _ in range(y):
	l = r
	r = l + b
	for i in range(l, r):
		if i + 1 == r:
			ans.append(l)
		else:
			ans.append(i + 1)
print(*ans)


import sys
(n, a, b) = list(map(int, sys.stdin.readline().strip().split()))

def euc(a, b):
	if b > a:
		(d, p, q) = euc(b, a)
		return (d, q, p)
	if b == 0:
		return (a, 1, 0)
	s = a // b
	(d, sp, sq) = euc(a - s * b, b)
	return (d, sp, sq - s * sp)

def normalize(n, a, b, d, p, q):
	if p < 0:
		(sp, sq) = normalize(n, b, a, d, q, p)
		return (sq, sp)
	elif q >= 0:
		return (p, q)
	r = -(q // (a // d))
	sp = p - r * (b // d)
	sq = q + r * (a // d)
	if sp < 0:
		raise ValueError
	else:
		return (sp, sq)
(d, p, q) = euc(a, b)
if n % d != 0:
	print('-1')
	return
m = n // d
(p, q) = (m * p, m * q)
try:
	(p, q) = normalize(n, a, b, d, p, q)
except ValueError:
	print('-1')
	return
res = []
last = 1
for _ in range(p):
	res.extend(list(range(last + 1, last + a)))
	res.append(last)
	last += a
for _ in range(q):
	res.extend(list(range(last + 1, last + b)))
	res.append(last)
	last += b
print(' '.join(map(str, res)))


(n, a, b) = map(int, input().split())
cop = n
if a > b:
	(a, b) = (b, a)
j = -1
ke = -1
while n >= 0:
	if n % a == 0:
		j = n // a
		ke = (cop - a * j) // b
		break
	else:
		n -= b
if j == -1:
	print(-1)
else:
	ans = []
	t = 1
	for yu in range(j):
		for ty in range(a):
			k = t + (ty + 1) % a
			if k == 0:
				k += a
			ans.append(k)
		t += a
	for yu in range(ke):
		for ty in range(b):
			k = t + (ty + 1) % b
			if k == 0:
				k += b
			ans.append(k)
		t += b
	print(*ans, sep=' ')


(n, a, b) = [int(x) for x in input().split()]

def egcd(a, b):
	if a == 0:
		return (b, 0, 1)
	else:
		(g, y, x) = egcd(b % a, a)
		return (g, x - b // a * y, y)
(g, a_1, b_1) = egcd(a, b)
if n % g:
	print(-1)
	return
fac = n // g
a_1 *= fac
b_1 *= fac
if a_1 < 0:
	while a_1 < 0:
		a_1 += b // g
		b_1 -= a // g
	if b_1 < 0:
		print(-1)
		return
elif b_1 < 0:
	while b_1 < 0:
		b_1 += a // g
		a_1 -= b // g
	if a_1 < 0:
		print(-1)
		return
res = []
i = 1
for _ in range(a_1):
	for j in range(a - 1):
		i += 1
		res.append(i)
	res.append(i - a + 1)
	i += 1
for _ in range(b_1):
	for j in range(b - 1):
		i += 1
		res.append(i)
	res.append(i - b + 1)
	i += 1
print(' '.join(map(str, res)))


(n, a, b) = (int(x) for x in input().split())
l = -1
for k in range(n // a + 1):
	if (n - k * a) % b == 0:
		l = (n - k * a) // b
		break
if l == -1:
	print(-1)
	quit()
perm = []
curr_last_op = 1
for i in range(k):
	curr_cycle = [curr_last_op + j for j in range(a)]
	curr_last_op = curr_last_op + a
	perm += curr_cycle[1:] + curr_cycle[:1]
for i in range(l):
	curr_cycle = [curr_last_op + j for j in range(b)]
	curr_last_op = curr_last_op + b
	perm += curr_cycle[1:] + curr_cycle[:1]
print(*perm)


(n, a, b) = map(int, input().split())
for i in range(n // a + 1):
	if (n - i * a) % b == 0:
		res = []
		for j in range(i):
			t = [j * a + k for k in range(1, a + 1)]
			res += t[1:] + [t[0]]
		for j in range((n - i * a) // b):
			t = [i * a + j * b + k for k in range(1, b + 1)]
			res += t[1:] + [t[0]]
		print(*res)
		break
else:
	print(-1)


(n, a, b) = map(int, input().split())
(x, y) = (-1, -1)
for i in range(n + 1):
	if n - a * i >= 0 and (n - a * i) % b == 0:
		x = i
		y = (n - a * i) // b
		break
if x == -1:
	print(-1)
	exit()
ans = [-1] * n
for i in range(0, a * x, a):
	for j in range(i, i + a - 1):
		ans[j] = j + 1
	ans[i + a - 1] = i
for i in range(a * x, n, b):
	for j in range(i, i + b - 1):
		ans[j] = j + 1
	ans[i + b - 1] = i
for i in range(n):
	ans[i] += 1
print(*ans)


(N, A, B) = map(int, input().split())
for i in range(N // A + 1):
	if (N - i * A) % B == 0:
		ans = []
		for j in range(i):
			l = []
			for k in range(1, A + 1):
				l.append(j * A + k)
			ans += l[1:] + [l[0]]
		for j in range((N - i * A) // B):
			l = []
			for k in range(1, B + 1):
				l.append(i * A + j * B + k)
			ans += l[1:] + [l[0]]
		print(*ans)
		break
else:
	print(-1)


def main():
	(n, a, b) = map(int, input().split())
	found = False
	for x in range(n + 1):
		rem = n - a * x
		if rem >= 0 and rem % b == 0:
			y = rem // b
			found = True
			break
	if not found:
		print(-1)
		return
	ans = []
	if a == 1 or b == 1:
		for i in range(n):
			ans.append(i + 1)
	else:
		start = 1
		for i in range(x):
			arr = [start + 1]
			for j in range(a - 2):
				arr.append(arr[-1] + 1)
			arr.append(start)
			start = arr[-2] + 1
			ans.extend(arr)
		for i in range(y):
			arr = [start + 1]
			for j in range(b - 2):
				arr.append(arr[-1] + 1)
			arr.append(start)
			start = arr[-2] + 1
			ans.extend(arr)
	for i in ans:
		print(i, end=' ')
main()