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 (Python):
r,p=range,print
n,a,b=map(int,input().split())
if a+b>n+1or a*b<n:exit(p(-1))
l=[[]for i in r(b-1)]+[list(r(1,a+1))]
for i in r(a,n):l[-2-(i-a)%(b-1)]+=[i+1]
for i in l:p(*i,end=" ")

Solution (Python):
def main(n,a,b):
    if not a*b>=n>=a+b-1:
        return [-1]
    ans=[]
    flg=False
    
    for x in range(b): 
        
        if not flg:
            for y in range(a):
                
                ans.append(b-x+b*y)
                if len(ans)+(b-x)==n:
                    if y!=a-1:
                        ans.append(b-x+b*(a-1))
                    else:
                        ans.append(b-(x+1))
                    flg=True
                    break
        elif flg:
            ans.append(b-x+b*(a-1))
    c=ans.copy()
    c.sort()
    from bisect import bisect_right
    ans=[bisect_right(c,x) for x in ans]
    return ans

n,a,b=map(int,input().split())
ary=main(n,a,b)
print(*ary,sep=' ')

Solution (Python):
n,a,b = map(int,input().split())

if(n > a*b)|(a+b > n+1):
    print(-1)
    exit()
if(a==1)|(b==1):
    if(b==n):
        ans = list(range(n,0,-1))
        print(' '.join(map(str,ans)))
    elif(a==n):
        ans = list(range(1,n+1))
        print(' '.join(map(str,ans)))
    else:
        print(-1)
    exit()

ans = []
top = n
while(top > 0):
    if(top-a >= b):
        for i in range(top-a+1,top+1):
            ans.append(i)
        top -= a
        b -= 1
        continue
    a = top-b+1
    for i in range(top-a+1,top+1):
        ans.append(i)
    for i in range(b-1,0,-1):
        ans.append(i)
    break

print(' '.join(map(str,ans)))

Solution (Python):

max2 = lambda x,y: x if x > y else y

def solve(N,A,B):
    if A+B > N+1:
        return None
    if A*B < N:
        return None


    res = [-1]*N
    rem = A

    i = 0
    while i+B+rem-1 < N:
        rem -= 1
        o = i+B
        for k in range(B):
            res[i+k] = o-k-1
        i += B

    p = N-i-rem+1
    for k in range(p):
        res[i+k] = i+p-k-1
    i += p
    rem -= 1
    for k in range(i,N):
        res[k] = k
    return res






from itertools import permutations
def naive(N,A,B):

    for p in permutations(range(N)):
        dp = [1]*N
        for i in range(N):
            for j in range(i):
                if p[j] < p[i]:
                    dp[i] = max2(dp[i],dp[j]+1)

        a = max(dp)

        dp = [1]*N
        for i in range(N):
            for j in range(i):
                if p[j] > p[i]:
                    dp[i] = max2(dp[i],dp[j]+1)

        b = max(dp)

        if a == A and b == B:
            return p
    return None

if __name__ == '__main__':
    N,A,B = map(int,input().split())
    res = solve(N,A,B)
    if res is None:
        print(-1)
    else:
        print(*(v+1 for v in res))

Solution (Python):
import sys

input_methods=['clipboard','file','key']
using_method=1
input_method=input_methods[using_method]

tin=lambda : map(int, input().split())
lin=lambda : list(tin())
mod=1000000007



def main():
	
	n, a, b = tin()
	
	if n < a+b-1:
		return -1
	if n > a*b:
		return -1
	if a == 1:
		print(*list(range(n,0,-1)))
		return 
	if b==1:
		print(*list(range(1, n+1)))
		return 
	
	al = list( range(1, n+1))
	cc = (n - a) // (b-1)
	amari = (n - a) % (b-1)
	ret = al[-a:]
	st=n-a
	for bi in range(b-1):
		na = cc + (1 if bi < amari else 0)
		st -= na
		for ai in range(na):
			ret.append(al[st+ai])
	print(*ret)
		
		
	
	

isTest=False

def pa(v):
	if isTest:
		print(v)
		
def input_clipboard():
	import clipboard
	input_text=clipboard.get()
	input_l=input_text.splitlines()
	for l in input_l:
		yield l

if __name__ == "__main__":
	if sys.platform =='ios':
		if input_method==input_methods[0]:
			ic=input_clipboard()
			input = lambda : ic.__next__()
		elif input_method==input_methods[1]:
			sys.stdin=open('inputFile.txt')
		else:
			pass
		isTest=True
	else:
		pass
		
			
	ret = main()
	if ret is not None:
		print(ret)

Solution (Python):
N,A,B = map(int,input().split())
if A+B-1>N or N>A*B:
    print(-1)
else:
    G = {i:[] for i in range(1,A+1)}
    i = A
    cnt = 0
    cur = N
    while cur>A:
        G[i].append(cur)
        cnt += 1
        cur -= 1
        if cnt==B-1:
            cnt = 0
            i -= 1
    C = []
    for i in range(1,A+1):
        C += G[i]
        C.append(i)
    print(*C)

Solution (Python):

import sys
def main(N, A, B):
    if A + B - 1 > N or A * B < N:
        print(-1)
        return
    P = []
    r = A * B - N
    for b in range(B):
        for a in range(A):
            if b >= 1 and a >= 1 and r > 0:
                if r >= A - 1:
                    r -= A - 1
                    break
                r -= 1
                continue
            P.append((B - b) * A + a + 1)
    s = sorted([(p, i) for i, p in enumerate(P)], key=lambda x: x[0])
    s = sorted([(i, j) for j, (p, i) in enumerate(s)], key=lambda x: x[0])
    s = [j + 1 for i, j in s]
    print(*s)

if __name__ == '__main__':
    input = sys.stdin.readline
    N, A, B = map(int, input().split())
    main(N, A, B)

Solution (Python):
def examC():
    N = LI(); N.sort()
    if N[0]==1:
        if N[1]==1:
            ans = 1
        else:
            ans = max(0,N[1]-2)
    else:
        ans = (N[1]-2)*(N[0]-2)
    print(ans)
    return

def examD():
    N, K = LI()
    ans = 0
    b = K+1
    while(b<=N):
        cur = N//b * (b-K) + max(0,N%b - K+1)
        if cur==N+1:
            cur = N
        ans += cur
        b += 1

    print(ans)
    return

def examE():
    N, A, B = LI()
    if N<A+B-1 or N>A*B:
        print(-1)
        return
    ans = []
    cur = N
    num = N
    rest = B - 1
    
    for i in range(B):
        cur -= A
        if cur<=rest:
            cur += A
            break
        for j in range(A):
            if num==rest:
                break
            ans.append(cur+1)
            cur += 1
            num -= 1
        cur -= A
        rest -= 1
    for i in range(rest,cur):
        ans.append(i+1)
    cur = rest
    for j in range(rest):
        ans.append(cur)
        cur -= 1
    print(" ".join(map(str,ans)))
    return

def examF():
    ans = 0
    print(ans)
    return

import sys,copy,bisect,itertools,heapq,math
from heapq import heappop,heappush,heapify
from collections import Counter,defaultdict,deque
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))
def LSI(): return list(map(str,sys.stdin.readline().split()))
def LS(): return sys.stdin.readline().split()
def SI(): return sys.stdin.readline().strip()
global mod,mod2,inf,alphabet
mod = 10**9 + 7
mod2 = 998244353
inf = 10**18
alphabet = [chr(ord('a') + i) for i in range(26)]

if __name__ == '__main__':
    examE()

"""

"""

Solution (Python):
N, A, B = map(int, input().split())

if A * B < N:
  print(-1)
elif A + B - 1 > N:
  print(-1)
else:
  P = [0] * N
  b = (N - A) // (B - 1) if B > 1 else 0
  r = (N - A) % (B - 1) + 1 if B > 1 else 1
  i = 1
  pos = 0
  while i <= N:
    if b:
      for j in range(B):
        P[pos + B - j - 1] = i
        i += 1
      pos += B
      b -= 1
    elif r:
      for j in range(r):
        P[pos + r - j - 1] = i
        i += 1
      pos += r
      r = 0
    else:
      P[pos] = i
      i += 1
      pos += 1
    
  for p in P:
    print(p, end=' ')

Solution (Python):
r,p=range,print
n,a,b=map(int,input().split())
if a+b>n+1or a*b<n:exit(p(-1))
l=[[]for i in r(b-1)]+[list(r(1,a+1))]
for i in r(a+1,n+1):l[-2-(i-a-1)%(b-1)]+=[i]
for i in l:p(*i,end=" ")

Solution (Python):
r,p=range,print
n,a,b=map(int,input().split())
if a+b>n+1or a*b<n:exit(p(-1))
l=[[]for i in r(b-1)]+[list(r(1,a+1))]
for i in r(a+1,n+1):l[-2-(i-a-1)%(b-1)].append(i)
for i in l:p(*i,end=" ")

Solution (Python):
N,A,B=map(int,input().split())
a=list(range(N-A+1,N+1))
for i in range(B-1,0,-1):
    a.append(i)
m,M=B,N-A
for j in range(A-1):
    for i in range(min(M,m+B-2),m-1,-1):
        a.append(i)
    m=min(M,m+B-2)+1
    if len(a)==N:
        break
print(*a if len(a)==N else [-1])

Solution (Python):
N, A, B = map(int, input().split())

if (A + B > N + 1) or (A * B < N):
    print(-1)
    exit()


distributes = [1] * A
remain = N - A
for i in range(A):
    d = min(remain, B - 1)
    distributes[i] += d
    remain -= d

marker = 1
ans = []
for d in distributes:
    ans.extend(list(range(marker, marker + d))[::-1])
    marker += d
print(*ans, sep=' ')

Solution (Python):
import sys
def input(): return sys.stdin.readline().strip()
def mapint(): return map(int, input().split())
sys.setrecursionlimit(10**9)

N, A, B = mapint()
from collections import deque
if A+B-1>N or N>A*B:
    print(-1)
else:
    blocks = []
    blocks.append(' '.join(map(str, range(B, 0, -1))))
    now = B+1
    rest = N-A+2

    while now:
        if now==rest:
            break
        if now+B>rest:
            blocks.append(' '.join(map(str, range(rest, now-1, -1))))
            rest += 1
            break
        blocks.append(' '.join(map(str, range(now+B-1, now-1, -1))))
        now = now+B
        rest += 1
    blocks.append(' '.join(map(str, range(rest, N+1))))
    print(' '.join(blocks))

Solution (Python):
import sys
def input(): return sys.stdin.readline().strip()
def mapint(): return map(int, input().split())
sys.setrecursionlimit(10**9)

N, A, B = mapint()
from collections import deque
if A+B-1>N or N>A*B:
    print(-1)
else:
    blocks = []
    blocks.append(' '.join(map(str, range(B, 0, -1))))
    now = B+1
    rest = N-A+2

    while now:
        if now>=rest:
            break
        if now+B>rest:
            blocks.append(' '.join(map(str, range(rest, now-1, -1))))
            rest += 1
            break
        blocks.append(' '.join(map(str, range(now+B-1, now-1, -1))))
        now = now+B
        rest += 1
    blocks.append(' '.join(map(str, range(rest, N+1))))
    print(' '.join(blocks))

Solution (Python):
n, a, b = map(int, input().split())
if a+b-1 > n or a*b < n:
  print(-1)
  exit()
L = [[] for _ in range(b)]
L[-1] = list(range(1, a+1))
for now in range(a+1, n+1):
  temp = -2 - (now-(a+1))%(b-1)
  L[temp].append(now)
for l in L:
  print(*l, end=" ")

Solution (Python):
N,A,B=map(int,input().split())

if A*B<N or A+B-1>N:
    print(-1)
    exit()

rev=(B>A)
A,B=max(A,B),min(A,B)
B-=1
M=N
ans1=[]
ans2=[]
while M>0:
    if len(ans1)==len(ans2):
        temp=[i for i in range(M+1-A,M+1)]
        ans1.append(temp)
        M=M-A
        A-=1
    else:
        temp=[i for i in range(M+1-B,M+1)]
        temp=temp[::-1]
        ans2.append(temp)
        M=M-B
        B-=1

ans2=ans2[::-1]
res=[]
for L in ans1:
    res+=L
for L in ans2:
    res+=L

res=[val for val in res if val>0]
if rev:
    res=res[::-1]
print(*res)

Solution (Python):
N, A, B = map(int, input().split())
ans = []
 
if A+B-1<=N<=A*B:
    S = N-A
    cur = N
    ans = []
    for i in range(A+1):
        num = min(B-1, S)+1
        S -= num-1
        for j in range(num):
            ans.append(cur-num+1+j)
        cur -= num
    ans = ans[::-1][1:]
    print(*ans)
else:
    print(-1)

Solution (Python):
N, A, B = map(int, input().split())
ans = []
 
if A+B-1<=N<=A*B:
    S = N-A
    cur = N
    ans = []
    for i in range(A+1):
        num = min(B-1, S)+1
        S -= num-1
        for j in range(num):
            ans.append(cur-num+1+j)
        cur -= num
    ans = ans[::-1][1:]
    print(*ans)
else:
    print(-1)

from bisect import bisect


def LIS(L):
    INF, N = 10**12, len(L)
    seq = [INF] * N
    for i in L:
        seq[bisect(seq, i)] = i
    return N - seq.count(INF)

Solution (Python):
import numpy as np
N,A,B = map(int,input().split())

if A+B > N+1:
  print("-1")
  exit()
if A == 1:
  if B== N:
    ans = [i+1 for i in reversed(range(N))]
    print(*ans)
    exit()
  else:
    print("-1")
    exit()
if B == 1:
  if A== N:
    ans = [i+1 for i in range(N)]
    print(*ans)
    exit()
  else:
    print("-1")
    exit()
if A >= B:
  Flag = True
else:
  Flag = False
  A,B = B,A

if A*B<N:
  print("-1")
  exit()
else:
  L = [1 for _ in range(B)]
  nokori = N-B
  for i in range(B):
    if A-L[i] >0:
      temp = min(A-L[i],nokori)
      L[i] += temp
      nokori -= temp
    if nokori == 0:
      break
  now = 0
  P = [[] for _ in range(B)]
  for i,num in enumerate(L):
    for j in range(num):
      now += 1
      P[-i-1].append(now)
  
  ans = P
  output = []
  for i in range(len(ans)):
    for j in ans[i]:
      output.append(j)
  if Flag:
    print(*output)
  else:
    output = output[::-1]
    print(*output)

Solution (Python):
n,a,b=map(int,input().split())
if a+b-1>n:exit(print(-1))
if a*b<n:exit(print(-1))
ans=[]
c=0
nn=n
for i in range(a):
  ans.append([])
  t=0--nn//(a-i)
  if i==0:
    t=b
  nn-=min(t,b)
  for j in range(min(b,t)):
    ans[-1].append((i+1)*b-j)
    c+=1
    if c==n:break
  if c==n:break
anss=[]
for i in ans:anss+=i
def position_zip(a,flag):
  j=1
  d={}
  for i in sorted(a):
    if i in d:continue
    d[i]=j
    j+=1
  if flag==1:return d
  return [d[i] for i in a]
print(*position_zip(anss,0))

Solution (Python):
N,A,B=map(int,input().split())
if N>A*B or N<A+B-1:
  print(-1)
  exit()
P=[[] for i in range(B)]
for i in range(N):
  P[i//A].append(i+1)
P=P[::-1]
for i in range(B):
  if len(P[i])==0:
    P[i].append(P[-((N-i-1)//A+1)][-1])
    del P[-((N-i-1)//A+1)][-1]
  else:
    break
Q=[]
for i in range(B):
  for j in range(len(P[i])):
    Q.append(P[i][j])
print(*Q)

Solution (Python):
n, a, b = map(int, input().split())

min_b = -((-n) // a)
if not(min_b <= b and a + b <= n + 1):
    print(-1)
    exit()

ans = []
i = 0
while True:
    tmp = []
    break_flag = False
    for j in range(a):
        if i * a + j >= n:
            break_flag = True
            break
        tmp.append(i * a + j + 1)
    if not tmp:
        break
    ans.append(tmp)
    i += 1
    if break_flag:
        break

ans.sort(reverse=True)
nokori_b = b - len(ans)

for i in range(len(ans) - 1):
    cnt_elems = len(ans[i])
    if nokori_b >= len(ans[i]) - 1:
        ans[i].sort(reverse=True)
        nokori_b -= (len(ans[i]) - 1)
    else:
        ans[i] = sorted(ans[i][:nokori_b + 1], reverse=True) + ans[i][nokori_b + 1:]
        break

res = []
for li in ans:
    for num in li:
        res.append(num)
print(*res)

Solution (Python):
N,A,B=map(int,input().split())
if A+B-1>N or A*B<N:
  print(-1)
  exit()
Q=[[] for i in range(B)]
for i in range(N):
  Q[i//A].append(i+1)
Q=Q[::-1]
X=N-1
for i in range(B):
  if len(Q[i])==0:
    Q[i].append(Q[-(X//A+1)][-1])
    del Q[-(X//A+1)][-1]
    X-=1
  else:
    break
P=[]
for i in range(B):
  for j in range(len(Q[i])):
    P.append(Q[i][j])
print(*P)

Solution (Python):
import sys
import collections
import itertools

sys.setrecursionlimit(10 ** 8)
inm = lambda: map(int, sys.stdin.readline().split())


N, A, B = inm()


def solve():
    if A + B > N + 1:
        return None
    a, b = N, 1
    b += B - 1
    a -= B - 1
    

    s = []
    s.append(range(B, 0, -1))
    la = 1
    p = B + 1  
    ra = N - p + 1
    
    while la + ra > A:
        p2 = p + min(B, la + ra - A + 1)
        s.append(range(p2 - 1, p - 1, -1))
        p = p2
        la += 1
        ra = N + 1 - p
        
        if la == A and ra > 0:
            return None
    assert la + ra == A
    s.append(range(p, N + 1))
    return list(itertools.chain.from_iterable(s))


ans = solve()
if ans is None:
    print(-1)
else:
    print(*ans)

Solution (Python):
import sys
input = lambda : sys.stdin.readline().rstrip()
sys.setrecursionlimit(max(1000, 10**9))
write = lambda x: sys.stdout.write(x+"\n")


n,a,b = map(int, input().split())

def sub(n,a,b):
    ps = list(range(a))
    for i in range(1, b):
        ps.append(-a*i)
    count = a+b-1
    if count==n:
        return ps
    for i in range(1,b):
        for j in range(1,a):
            ps.append(-a*i+j)
            count += 1
            if count==n:
                break
        if count==n:
            break
    return ps

if a+b>n+1:
    ans = -1
elif a*b<n:
    ans = -1
else:
    
    ps = sub(n,a,b)
    pps = [(i+1,p) for i,p in enumerate(ps)]
    pps.sort(key=lambda x: x[1])
    ans = [item[0] for item in pps]
if ans==-1:
    print(ans)
else:
    write(" ".join(map(str, ans)))

Solution (Python):
import math

import queue
from collections import deque,defaultdict
import heapq as hpq
from sys import stdin,setrecursionlimit


ipt = stdin.readline
setrecursionlimit(10**7)

def main():
    n,a,b = map(int,ipt().split())
    if a*b < n or a+b-1 > n:
        print(-1)
        exit()
    ans = [str(b-i) for i in range(b)]
    si = n-a+2
    ue = n+1
    i = 0
    while True:
        if si <= b or a == 1:
            break
        ans[i] += " "+" ".join(map(str,range(si,ue)))
        ue = si
        si -= a-1
        i += 1
    if i < b and b+1 < ue:
        ans[i] += " "+" ".join(map(str,range(b+1,ue)))
    print(" ".join(ans))
    return

if __name__ == '__main__':
    main()

Solution (Python):
import sys
input = sys.stdin.readline

N, A, B = map(int, input().split())
if A + B - 1 > N:
    print(-1)
    exit()

a = []
b = []
while N > 0:
    if A == 0 or B == 0:
        print(-1)
        exit()
    if B >= N:
        b = list(range(N, 0, -1)) + b
        N = 0
    else:
        b = list(range(N, N-B, -1)) + b
        N -= B
        if A - 1 >= N:
            a += list(range(1, N+1))
            N = 0
        else:
            a += list(range(N-A+2, N+1))
            N -= A - 1
    A -= 1
    B -= 1
ans = a + b
print(*ans)

Solution (Python):

import sys

sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

N, A, B = lr()
if A + B - 1 > N:
    print(-1); exit()
if A * B < N:
    print(-1); exit()

if B == 1:
    q, r = A, 0
else:
    q, r = divmod(N-A, B-1)

if q == A:
    size = [B] * q
else:
    size = [B] * q + [r+1] + [1] * (A-q-1)

end = 1
answer = []
for s in size:
    start = end + s - 1
    answer.extend(list(range(start, end-1, -1)))
    end = start + 1

print(*answer)

Solution (Python):
N, A, B = map(int, input().split())

if A + B - 1 > N or A * B < N:
    print(-1)
    quit()

ans = []

x = N - A
cur = 1
while cur <= N:
    y = min(x + 1, B)
    ans += list(reversed(range(cur, cur + y)))
    cur += y
    x -= y - 1

print(*ans)

Solution (Python):
def solve(n, a, b):
    if n < a + b - 1:
        return [-1]
    if n > a * b:
        return [-1]
    if b == 1:
        return list(range(1, n + 1))
    if a == 1:
        return list(range(n, 0, -1))

    ans = list(range(b, 0, -1))
    ans.extend(range(n - a + 2, n + 1))

    t = b
    for t in range(2 * b - 1, n - a + 1, b - 1):
        ans.extend(range(t, t - b + 1, -1))
    ans.extend(range(n - a + 1, t, -1))
    return ans


n, a, b = map(int, input().split())
print(*solve(n, a, b))

Solution (Python):
import sys
import math
from collections import defaultdict
from bisect import bisect_left, bisect_right

sys.setrecursionlimit(10**7)
def input():
    return sys.stdin.readline()[:-1]

mod = 10**9 + 7

def I(): return int(input())
def LI(): return list(map(int, input().split()))
def LIR(row,col):
    if row <= 0:
        return [[] for _ in range(col)]
    elif col == 1:
        return [I() for _ in range(row)]
    else:
        read_all = [LI() for _ in range(row)]
        return map(list, zip(*read_all))






N,A,B = LI()

if math.ceil(N/A) <= B <= N-A+1:
    numl = [1]*A  
    numl[0] = B
    left = N-A-B+1
    for i in range(1,A):
        val = min(left,B-1)
        numl[i] += val
        left -= val
    ans = []
    now = 1
    for i in range(A):
        ans.extend(list(reversed(range(now,now+numl[i]))))
        now += numl[i]
    print(*ans)
else:
    print(-1)

Solution (Python):
n, a, b = [int(x) for x in input().split()]
if a * b < n or n < a + b - 1:
    print(-1)
else:
    ans = []
    remaining = n - a
    to_insert = 1
    for i in range(a):
        ans.append(to_insert)
        to_insert += 1
        inserted = 1
        for j in range(min(b - 1, remaining)):
            ans.append(to_insert)
            to_insert += 1
            inserted += 1
            remaining -= 1
        ans[-inserted:] = reversed(ans[-inserted:])
    print(*ans)

Solution (Python):
def main():
    N, A, B = map(int, input().split())

    if not (((N - 1) // A + 1) <= B <= (N - A) + 1):
        print(-1)
        return

    if B == 1:
        print(*range(1, N + 1))
        return

    q, r = divmod(N - A, B - 1)

    ctr = [A]
    ctr += [q] * (B - 1 - r)
    ctr += [q + 1] * r

    ans = []
    ma = N
    for x in ctr:
        ans += list(range(ma - x + 1, ma + 1))
        ma -= x
    print(*ans)


if __name__ == '__main__':
    main()

Solution (Python):
N,A,B = map(int,input().split())
if A+B > N+1 or A*B < N:
    print(-1)
    exit()

ls = [1]*B
rem = N-B
i = 0
while rem > 0:
    r = min(A-1, rem)
    ls[i] += r
    rem -= r
    i += 1

bs = [[] for _ in range(B)]
n = 1
for j,l in enumerate(ls):
    for i in range(l):
        bs[j].append(n)
        n += 1
ans = []
for b in reversed(bs):
    ans += b
print(*ans)

Solution (Python):
n,a,b=map(int,input().split())
ans=[];L=[a]*b;x=a*b-n;ct=1
if a+b>n+1 or x<0:print(-1);exit()
for i in range(b-1):
 y=min(a-1,x);L[i]-=y;x-=y
for i in L:
 l=[]
 for j in range(i):
  l+=[str(ct)];ct+=1
 ans+=[' '.join(l)]
print(*reversed(ans))

Solution (Python):
n,a,b=map(int,input().split())
ans=[];L=[a]*b;x=a*b-n;ct=1
if a+b>n+1 or x<0:print(-1);exit()
for i in range(b-1,0,-1):
 y=min(a-1,x);L[i]-=y;x-=y
for i in L:
 l=[]
 for j in range(i):
  l+=[str(ct)];ct+=1
 ans+=[' '.join(l)]
print(*reversed(ans))

Solution (Python):
n,a,b=map(int,input().split())
ans=[];L=[a]*b;x=a*b-n;ct=1
for i in range(b-1,0,-1):
  y=min(a-1,x);L[i]-=y;x-=y
for i in range(b):
  l=[]
  for j in range(L[i]):
    l.append(str(ct))
    ct+=1
  ans.append(' '.join(l))
ans.reverse()
print(-1 if a+b>n+1 or a*b<n else ' '.join(ans))

Solution (Python):
import sys
n,a,b=map(int,input().split())
if a+b>n+1 or a*b<n:
  print(-1)
  sys.exit()

ans=[]
L=[a]*b
x=a*b-n
for i in range(1,b):
  L[i]-=min(a-1,x)
  x-=min(a-1,x)
L.reverse()

ct=1
for i in range(b):
  l=[]
  for j in range(L[i]):
    l.append(str(ct))
    ct+=1
  ans.append(' '.join(l))
ans.reverse()

print(' '.join(ans))

Solution (Python):
n,a,b = map(int, input().split())
if a+b > n+1 or a*b < n:
    print(-1)
    exit()

l = []
used = 0
for i in range(a):
    tmp = []
    for j in range(b):
        tmp.append(used+1)
        used += 1
        if n-used == a-i-1:
            break
    l.extend(tmp[::-1])
print(*l)

Solution (Python):
n,a,b=map(int,input().split())
if not a+b-1<=n<=a*b:
  print(-1)
  exit()
n-=a
l=list()
for i in range(b,a*b+1,b):
  t=min(n,b-1)
  l+=[i-j for j in range(t+1)]
  n-=t
d=dict()
g=sorted(l)
for i,x in enumerate(g,1):
  d[x]=i
l=list(map(lambda x:d[x],l))
print(*l)

Solution (Python):


import sys

def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(N=None): return list(MAP()) if N is None else [INT() for i in range(N)]
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
INF = 10 ** 18
MOD = 10 ** 9 + 7

N, A, B = MAP()

if A == 1 and B != N or B == 1 and A != N:
    print(-1)
    exit()
remain = N - A
if remain < B - 1:
    print(-1)
    exit()
d, m = divmod(remain, B-1) if B > 1 else (0, 0)
li = [[] for i in range(B)]
li[0] = list(range(1, A+1))
j = A + 1
for i in range(1, B):
    tmp = []
    for _ in range(d):
        tmp.append(j)
        j += 1
    if m > 0:
        tmp.append(j)
        j += 1
        m -= 1
    if len(tmp) > A:
        print(-1)
        exit()
    li[i] = tmp
li = li[::-1]
ans = []
for grp in li:
    ans += grp
print(*ans)

Solution (Python):


import sys

def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(N=None): return list(MAP()) if N is None else [INT() for i in range(N)]
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
INF = 10 ** 18
MOD = 10 ** 9 + 7

N, A, B = MAP()

if A * B < N:
    print(-1)
    exit()
if A + B > N+1:
    print(-1)
    exit()
if A == 1 and B != N or B == 1 and A != N:
    print(-1)
    exit()
remain = N - A
if remain < B - 1:
    print(-1)
    exit()
d, m = divmod(remain, B-1) if B > 1 else (0, 0)
if d > A:
    print(-1)
    exit()
li = [[] for i in range(B)]
li[0] = list(range(1, A+1))
j = A + 1
for i in range(1, B):
    tmp = []
    for _ in range(d):
        tmp.append(j)
        j += 1
    if m > 0:
        tmp.append(j)
        j += 1
        m -= 1
    li[i] = tmp
li = li[::-1]
ans = []
for grp in li:
    ans += grp
print(*ans)

Solution (Python):
n,a,b = map(int,input().split())
if a+b>n+1 or a*b<n:
  print(-1)
  exit()
ans = []
for i in range(1,a+1):
  ans.append(i*b)
if b == 1:
  x = list(range(1,n+1))
  print(*x)
  exit()
x = (n-a)//(b-1)
y = (n-a)%(b-1)
for i in range(1,b):
  for j in range(1,x+1):
    ans.append(j*b-i)
  if i <= y:
    ans.append((x+1)*b-i)
ans_true = []
for i,x in enumerate(ans):
  ans_true.append((i+1,x))
ans_true.sort(key=lambda x:x[1])
x = list(zip(*ans_true))[0]
print(*x)

Solution (Python):
n,a,b = map(int,input().split())
if a+b>n+1 or a*b<n:
  print(-1)
  exit()
ans = []
for i in range(1,a+1):
  ans.append(i*b)
if b == 1:
  x = list(range(1,n+1))
  print(*x)
  exit()
x = (n-a)//(b-1)
y = (n-a)%(b-1)
for i in range(1,b):
  for j in range(1,x+1):
    ans.append(j*b-i)
  if i <= y:
    ans.append((x+1)*b-i)
ans_true = []
for i,x in enumerate(ans):
  ans_true.append((i+1,x))
ans_true.sort(key=lambda x:x[1])
x = list(zip(*ans_true))[0]
print(*x)

Solution (Python):
import sys
from bisect import bisect

def Longest_Increasing_Subsequence(N,lst):
    
    
    
    MM=max(lst)+1
    data=[MM]*(N+1)
    
    
    
    data[0]=0
    for i in range(N):
        b=bisect(data,lst[i])
        data[b]=lst[i]

    ANS=1
    for i in range(1,N+1):
        if data[i]!=MM:
            ANS=i
    
    return ANS

def Longest_Decreasing_Subsequence(N,lst):
    
    
    
    MM=max(lst)+1
    data=[MM]*(N+1)
    
    
    
    lst=lst[::-1]
    
    data[0]=0
    for i in range(N):
        b=bisect(data,lst[i])
        data[b]=lst[i]

    ANS=1
    for i in range(1,N+1):
        if data[i]!=MM:
            ANS=i
    
    return ANS



N,A,B=map(int,input().split())
AAA,BBB=A,B

if A>N or B>N:
    print(-1)
    sys.exit()
if B>N-A+1:
    print(-1)
    sys.exit()

ans=[]
L=1
R=N
flag=[0]*(N+1)
flag[0]=1

if A<B:
    B-=1
    while A>0 and B>0 and len(ans)<N:
        for i in range(max(1,R-A+1),R+1):
            if flag[i]==0:
                flag[i]=1
                ans.append(i)
        R-=A
        A-=1
        for i in range(min(N,L+B-1),L-1,-1):
            if flag[i]==0:
                flag[i]=1
                ans.append(i)
        L+=B
        B-=1
        
    for i in range(min(N,L+B-1),L-1,-1):
        if flag[i]==0:
            flag[i]=1
            ans.append(i)

elif A==B:
    B-=1
    while A>0 and B>0 and len(ans)<N:
        for i in range(max(1,R-A+1),R+1):
            if flag[i]==0:
                flag[i]=1
                ans.append(i)
        R-=A
        A-=1
        for i in range(min(N,L+B-1),L-1,-1):
            if flag[i]==0:
                flag[i]=1
                ans.append(i)
        L+=B
        B-=1
        
    for i in range(max(1,R-A+1),R+1):
        if flag[i]==0:
            flag[i]=1
            ans.append(i)

else:
    A-=1
    while A>0 and B>0 and len(ans)<N:
        for i in range(min(N,L+B-1),L-1,-1):
            if flag[i]==0:
                flag[i]=1
                ans.append(i)
        L+=B
        B-=1
        for i in range(max(1,R-A+1),R+1):
            if flag[i]==0:
                flag[i]=1
                ans.append(i)
        R-=A
        A-=1
    
    for i in range(max(1,R-A+1),R+1):
        if flag[i]==0:
            flag[i]=1
            ans.append(i)

if len(ans)>=N:
    ans=ans[:N]
    if  Longest_Increasing_Subsequence(N,ans)==AAA and Longest_Decreasing_Subsequence(N,ans)==BBB:
        print(*ans)
    else:
        print(-1)
else:
    print(-1)

Solution (Python):
import sys

N,A,B = map(int,input().split())

if A+B-1 > N or A*B < N:
    print (-1)
    sys.exit()

ans = []

for i in range(N-A+1,N+1,1):
    ans.append(i)

now = []
for i in range(1,N-A+1,1):

    now.append(i)

    if len(now) == B-1:
        now.reverse()

        for j in now:
            ans.append(j)
        now = []

now.reverse()
for j in now:
    ans.append(j)

print (" ".join(map(str,ans)))

Solution (Python):
n,a,b = map(int,input().split())
if not (a+b-1 <= n <= a*b):
  print(-1)
  exit()
n -= a
l = list()
for i in range(b,a*b+1,b):
  t = min(n,b-1)
  l += [i-j for j in range(t+1)]
  n -= t
d = dict()
g = sorted(l)
for i,x in enumerate(g,1):
  d[x] = i
l = list(map(lambda x:d[x], l))
print(*l)

Solution (Python):
def main():
    n, a, b = map(int, input().split())
    if b < (n-1)//a+1 or n-a+1 < b:
        print(-1)
        return 0
    for i in range((n-1)//a+1, n-a+2):
        cnt_a = (i-(n-1)//a)
        cnt_b = b-cnt_a-1
        length = n-cnt_a*a-cnt_b
        if length <= a:
            break
    j = n+1
    ans = []
    for i in range(cnt_a):
        j -= a
        ans += list(range(j, j+a))
    if cnt_b >= 0:
        j -= length
        ans += list(range(j, j+length))+list(range(j-1, 0, -1))
    print(*ans)


main()