import
java.util.ArrayList;
class
GFG{
public
static
boolean
possible(
int
x,
int
S,
int
N)
{
int
minSum = (x * (x +
1
)) /
2
;
int
maxSum = (x * ((
2
* N) - x +
1
)) /
2
;
if
(S < minSum || S > maxSum) {
return
false
;
}
return
true
;
}
public
static
void
findPermutation(
int
N,
int
L,
int
R,
int
S)
{
int
x = R - L +
1
;
if
(!possible(x, S, N)) {
System.out.print(-
1
);
return
;
}
else
{
ArrayList<Integer> v =
new
ArrayList<>();
for
(
int
i = N; i >=
1
; --i) {
if
((S - i) >=
0
&& possible(x -
1
, S - i,
i -
1
)) {
S = S - i;
x--;
v.add(i);
}
if
(S ==
0
) {
break
;
}
}
if
(S !=
0
) {
System.out.print(-
1
);
return
;
}
ArrayList<Integer> v1 =
new
ArrayList<Integer>();
for
(
int
i =
1
; i <= N; ++i) {
boolean
it = v.contains(i);
if
(!it) {
v1.add(i);
}
}
int
j =
0
, f =
0
;
for
(
int
i =
1
; i < L; ++i) {
System.out.print(v1.get(j) +
" "
);
j++;
}
for
(
int
i = L; i <= R; ++i) {
System.out.print(v.get(f) +
" "
);
f++;
}
for
(
int
i = R +
1
; i <= N; ++i) {
System.out.print(v1.get(j) +
" "
);
j++;
}
}
return
;
}
public
static
void
main(String args[])
{
int
N =
6
, L =
3
, R =
5
, S =
8
;
findPermutation(N, L, R, S);
}
}