import
java.io.*;
import
java.util.*;
class
GFG {
public
static
void
nextPermutation(List<Integer> nums)
{
int
n = nums.size();
int
k, l;
for
(k = n -
2
; k >=
0
; k--) {
if
(nums.get(k) < nums.get(k +
1
)) {
break
;
}
}
if
(k <
0
) {
Collections.reverse(nums);
}
else
{
for
(l = n -
1
; l > k; l--) {
if
(nums.get(l) > nums.get(k)) {
break
;
}
}
Collections.swap(nums, k, l);
List<Integer> subList = nums.subList(k +
1
, n);
Collections.reverse(subList);
}
}
public
static
int
factorial(
int
n)
{
return
(n ==
1
|| n ==
0
) ?
1
: factorial(n -
1
) * n;
}
public
static
List<List<Integer> >
permute(List<Integer> nums)
{
List<List<Integer> > permuted =
new
ArrayList<>();
int
n = nums.size();
int
factn = factorial(n);
for
(
int
i =
0
; i < factn; i++) {
permuted.add(
new
ArrayList<>(nums));
nextPermutation(nums);
}
return
permuted;
}
public
static
void
findPermutation(
int
n,
int
a,
int
b)
{
List<Integer> nums =
new
ArrayList<>(n);
for
(
int
i =
0
; i < n; i++) {
nums.add(i +
1
);
}
List<List<Integer> > allpermutations
= permute(nums);
int
total = allpermutations.size();
int
ansindex = -
1
;
for
(
int
i =
0
; i < total; i++) {
int
minc =
0
, maxc =
0
;
for
(
int
j =
1
; j < n -
1
; j++) {
if
(allpermutations.get(i).get(j)
> allpermutations.get(i).get(j -
1
)
&& allpermutations.get(i).get(j)
> allpermutations.get(i).get(
j +
1
)) {
maxc++;
}
if
(allpermutations.get(i).get(j)
< allpermutations.get(i).get(j -
1
)
&& allpermutations.get(i).get(j)
< allpermutations.get(i).get(
j +
1
)) {
minc++;
}
}
if
(minc == a && maxc == b) {
ansindex = i;
break
;
}
}
if
(ansindex == -
1
) {
System.out.println(-
1
);
}
else
{
for
(
int
i =
0
; i < n; i++) {
System.out.print(
allpermutations.get(ansindex).get(i)
+
" "
);
}
}
}
public
static
void
main(String[] args)
{
int
N =
6
, A =
2
, B =
2
;
findPermutation(N, A, B);
}
}