import java.lang.StringBuilder fun main(args: Array) { val(n,s) = readLine()!!.trim().split(" ").map { it.toInt() } total = s for(i in 1..n) { itemList.add(Item(i-1, readLine()!!.toInt())) } itemList.sortByDescending { it.value } val zenhan = getHalfList(itemList.subList(0, itemList.size / 2), 0, 0) val kouhan = getHalfList(itemList.subList(itemList.size / 2, itemList.size), 0, 0) val ans = mutableListOf() zenhan.filter { it.key < total }.forEach{ val key = total - it.key val zen = it.value kouhan[key]?.let { it.forEach { val kou = it zen.forEach { ans.add(it + kou) } } } } ans.sortDescending() ans.forEach { println(convAns(it)) } } fun convAns(num:Int):String { val ans = StringBuilder() for(i in itemList.indices) { val key = 1 shl (itemList.lastIndex - i) if(num and key > 0) { ans.append(" ") ans.append(i + 1) } } return ans.toString().substring(1) } var total = 0 class Item(val index:Int, val value:Int) val itemList = mutableListOf() fun getHalfList(list:List, index:Int, subTotal:Int):Map> { if(index > list.lastIndex) { val ret = mutableMapOf>() ret[subTotal] = listOf(0) return ret } val ans = mutableMapOf>() val ret1 = getHalfList(list, index + 1, subTotal + list[index].value) val ret2 = getHalfList(list, index + 1, subTotal) val key = 1 shl (itemList.lastIndex - list[index].index) ret1.forEach{ val total = it.key if(!ans.containsKey(total)) { ans[total] = mutableListOf() } ans[total]!!.addAll(it.value.map { it + key }) } ret2.forEach { val total = it.key if(!ans.containsKey(total)) { ans[total] = mutableListOf() } ans[total]!!.addAll(it.value) } return ans }