fun main(args: Array){ val weightCount = readLine()!!.toInt() weightList = readLine()!!.split(" ").map { it.toInt() } totalWeight = weightList.sumBy { it } val ans = if(getAns(0, 0)) "possible" else "impossible" println(ans) } var weightList = listOf() var totalWeight = 0 val dic = mutableMapOf>() fun getAns(pos:Int, subTotal:Int):Boolean { if(subTotal * 2 == totalWeight) { return true } if(subTotal * 2 > totalWeight) { return false } if(pos > weightList.lastIndex) { return false } if(!dic.containsKey(pos)) { dic[pos] = mutableMapOf() } dic[pos]!![subTotal]?.let { return it } val ret1 = getAns(pos + 1, subTotal) val ret2 = getAns(pos + 1, subTotal + weightList[pos]) dic[pos]!![subTotal] = (ret1 || ret2) return (ret1 || ret2) }