
fun main(args:Array<String>):Unit {
    val map = mutableMapOf<String, Int> ()
    repeat(readLine()!!.trim().toInt()){
        val (name, num) = readLine()!!.trim().split(' ')
        if (map.containsKey(name)){
            map[name] = map[name]!! + num.toInt()
        }else{
            map[name] = num.toInt()
        }
    }
    map.toList().sortedWith(compareBy({it.first.length}, Pair<String, Int>::first)).forEach { println("${it.first} ${it.second}") }
}
