import java.util.ArrayList; import java.util.Collections; import java.util.Comparator; import java.util.Scanner; public class Yuki015 { public static void main(String[] args) { Yuki015 p = new Yuki015(); } public class HanbunTuple implements Comparable { public long value; public long bit; HanbunTuple(long value, long bit) { this.value = value; this.bit = bit; } @Override public int compareTo(HanbunTuple o) { return Long.compare(this.value, o.value); } } public Yuki015() { Scanner scanner = new Scanner(System.in); final int N = scanner.nextInt(); final int S = scanner.nextInt(); int[] P = new int[N]; for (int i = 0; i < N; i++) { P[i] = scanner.nextInt(); } int sizeL = N / 2; ArrayList leftList = new ArrayList(2 << sizeL); ArrayList rightList = new ArrayList(2 << sizeL); leftList.add(new HanbunTuple(0, 0)); for (int i = 0; i < sizeL; i++) { int size = leftList.size(); for (int j = 0; j < size; j++) { HanbunTuple tuple = leftList.get(j); leftList.add(new HanbunTuple(tuple.value + P[i], tuple.bit | 1 << i)); } } rightList.add(new HanbunTuple(0, 0)); for (int i = sizeL; i < N; i++) { int size = rightList.size(); for (int j = 0; j < size; j++) { HanbunTuple tuple = rightList.get(j); rightList.add(new HanbunTuple(tuple.value + P[i], tuple.bit | 1 << i)); } } Collections.sort(rightList); for (HanbunTuple tuple : leftList) { final int index = Collections.binarySearch(rightList, tuple, new Comparator() { @Override public int compare(HanbunTuple o1, HanbunTuple o2) { return Long.compare(o1.value, S - o2.value); } }); if (index < 0) { continue; } for (int rightIndex = index; rightIndex < rightList.size(); rightIndex++) { if (rightList.get(rightIndex).value + tuple.value != S) { break; } for (long bitIndex = 0; bitIndex < N; bitIndex++) { if ((rightList.get(rightIndex).bit + tuple.bit & 1 << bitIndex) > 0) { //インデックスが1ずれるため System.out.print(bitIndex + 1); System.out.print(" "); } } System.out.println(); } } } }