import
java.util.*;
class
Main {
public
static
void
the_allpossible_getter(List<List<Integer>> allsub, List<Integer> v, List<Integer> res,
int
n,
int
index) {
if
(index >= n) {
allsub.add(
new
ArrayList<>(res));
return
;
}
res.add(v.get(index));
the_allpossible_getter(allsub, v, res, n, index +
1
);
res.remove(res.size() -
1
);
the_allpossible_getter(allsub, v, res, n, index +
1
);
}
public
static
void
main(String[] args) {
List<Integer> v = Arrays.asList(
1
,
2
, -
4
, -
2
,
3
,
0
);
int
n = v.size();
List<Integer> res =
new
ArrayList<>();
List<List<Integer>> allsub =
new
ArrayList<>();
the_allpossible_getter(allsub, v, res, n,
0
);
int
maxsum = Integer.MIN_VALUE;
List<Integer> maxsub =
new
ArrayList<>();
for
(List<Integer> it : allsub) {
int
sum =
0
;
for
(Integer vt : it) {
sum += vt;
}
if
(sum > maxsum) {
maxsum = sum;
maxsub = it;
}
}
System.out.println(maxsum);
for
(Integer it : maxsub) {
System.out.print(it +
" "
);
}
}
}