fun main(args:Array) { val turnCount = readLine()!!.toInt() val cards1 = readLine()!!.split(" ").map { it.toInt() } val cards2 = readLine()!!.split(" ").map { it.toInt() } val ans = getResult(cards1, cards2, 0, turnCount).let { it.first / it.second.toDouble() } println(ans) } fun getResult(myCards:List, otherCards:List, subTotal:Int, turnCount:Int):Pair { if(myCards.size == 0) { return if(subTotal > (turnCount - subTotal)) 1 to 1 else 0 to 1 } var winCount = 0 to 0 for(i in myCards.indices) { val newMyCards = myCards.withIndex().filter { it.index != i }.map { it.value } for(j in otherCards.indices) { val newOtherCards = otherCards.withIndex().filter { it.index != j }.map { it.value } val ret = getResult(newMyCards, newOtherCards, if (myCards[i] > otherCards[j]) subTotal + 1 else subTotal, turnCount) winCount = winCount.first + ret.first to winCount.second + ret.second } } return winCount }