import kotlin.math.max fun main(arr:Array) { val cards = readLine()!!.split(" ").map { it.toInt() }.sorted() val result = Proc(cards).canWin(cards) val ans = when{ result == Proc.Result.Win -> { "Taro" } result == Proc.Result.Lose -> { "Jiro" } else -> { "Draw" } } println(ans) } class Proc(val cards:List) { val dic = initDic() enum class Result { Win, Lose, Draw } fun initDic():MutableList>>> { return (0..13).map { (0..13).map { (0..13).map { (0..13).map { null as Result? }.toMutableList() }.toMutableList() }.toMutableList() }.toMutableList() } public fun canWin(cardList:List):Result { if(cardList.sum() == 0) { return Result.Lose } dic[cardList[0]][cardList[1]][cardList[2]][cardList[3]]?.let { return it } val maxIndex = cardList.size - 1 var ifWin = false var ifDraw = false for(i in (0..maxIndex)) { if(cardList[i] == 0) { continue } val maxCount = Math.min(3, cardList[i]) for(j in (maxCount downTo 1)) { val newList = cardList.toMutableList() newList[i] -= j val ret = canWin(newList.sorted()) if(ret == Result.Lose) { ifWin = true break } else if(ret == Result.Draw) { ifDraw = true } } if(ifWin) { break } } var result = Result.Lose if(ifWin) { result = Result.Win } else if(ifDraw) { result = Result.Draw } dic[cardList[0]][cardList[1]][cardList[2]][cardList[3]] = result return result } }