import java.util.* fun main(arr:Array) { val teamCount = readLine()!!.toInt() val taisen = (1..teamCount).map { readLine()!!.map { it }.toTypedArray() }.toTypedArray() taisen[0].indices.forEach { if(it > 0) { if(taisen[0][it] == '-') { taisen[0][it] = 'o' taisen[it][0] = 'x' } } } val queue = PriorityQueue(kotlin.Comparator { a, b -> taisen[b].count { it == 'o' }.compareTo(taisen[a].count{ it == 'o'}) }) queue.addAll(1..(teamCount-1)) while (queue.isNotEmpty()) { val l = queue.poll() val target = (1..teamCount - 1).filter { taisen[l][it] == '-' } if(target.isEmpty()) { continue } val w = target.sortedBy { taisen[it].count { it == 'o' } }!!.first() taisen[l][w] = 'x' taisen[w][l] = 'o' queue.add(l) } val ans = taisen.map { it.count { it == 'o' } }.distinct().sortedDescending().indexOf(taisen[0].count { it == 'o' }) + 1 println(ans) } val dic = mutableMapOf>() val coins = (1..9).map { 111111 * it }.reversed().toTypedArray() fun getAns(idx:Int, target :Long):Long { if(target < coins.last() ) { return 1 } if(idx > coins.lastIndex) { return 1 } if(!dic.containsKey(idx)) { dic[idx] = mutableMapOf() } dic[idx]!![target]?.let { return it } var ans = 0.toLong() for(i in 0..target) { if(i*coins[idx] > target) { break } ans += getAns(idx + 1, target - i*coins[idx]) } dic[idx]!![target] = ans return ans }