fun pancakeSort(a: IntArray) {
    
    fun indexOfMax(n: Int): Int = (0 until n).maxByOrNull{ a[it] }!!

    
    fun flip(index: Int) {
        a.reverse(0, index + 1)
    }

    for (n in a.size downTo 2) {