fun main(args:Array) { val n = readLine()!!.toInt() val map = mutableMapOf() (1..n).map { readLine() val (num, score) = readLine()!!.split(" ").map { it.toInt() } val words = readLine()!!.split(" ") words.map { word -> if(map.get(word) == null) map[word] = 0 map[word] = map[word]!! + score } } val freq_list = mutableMapOf>() map.toList().sortedBy { it.second * -1 }.mapIndexed { i, pair -> val (word, freq) = pair when { i <= 9 -> { if( freq_list.get(freq) == null ) freq_list[freq] = mutableListOf() freq_list[freq]!!.add( "${word} ${freq}" ) } else -> null } } freq_list.toList().sortedBy { it.first * -1 }.map { val (freq, list) = it list.sortedBy { it }.map { println(it) } } }