fun main(arr:Array) { val inpt = readLine()!!.map { it }.toMutableList() val ans = mutableListOf() (1..inpt.size).forEach { val idx = inpt.lastIndexOf(inpt.max()!!) if(idx == 0) { ans.add(inpt[0]) inpt.removeAt(0) } else { val tmp = inpt[idx] inpt[idx] = inpt[0] inpt[0] = tmp ans.addAll(inpt) println(ans.joinToString("")) return } } println(ans.joinToString("")) }