import kotlin.math.max fun main(arr:Array) { val itemCount = readLine()!!.toInt() val numberList = readLine()!!.split(" ").map { it.toInt() } val ans = if(canWin(numberList.sorted())) "Alice" else "Bob" println(ans) } val dic = mutableMapOf() fun canWin(numberList:List):Boolean { if(numberList.isEmpty() || numberList.all { it == 1 }) { return false } val key = numberList.joinToString("-") dic[key]?.let { return it } val maxIndex = numberList.lastIndex var canWin = false for(i in (0..maxIndex)) { if(numberList[i] == 1) { continue } val prime = getPrimeDivide(numberList[i]).toMutableMap() for(p in prime.keys) { for(j in (1..Math.min(2,prime[p]!!))) { val dv = Math.pow(p.toDouble(), j.toDouble()).toInt() val newList = numberList.toMutableList() newList[i] = numberList[i] / dv if(!canWin(newList.sorted())) { canWin = true break } } if(canWin) { break } } if(canWin) { break } } dic[key] = canWin return canWin } val primeDic = (0..10000).map { getPrimeDivide(it) } fun getPrimeDivide(num:Int):Map { var div = 1 var current = num val ret = mutableMapOf() while (current > 1) { div++ var cnt = 0 while (current % div == 0) { cnt++ current /= div } if(cnt > 0) { ret[div] = cnt % 3 } } return ret }