fun main(args: Array<String>) {
    val aArray = LongArray(readLine()!!.toInt()) {
        readLine()!!.toLong()
    }

    val maxVal = aArray.max()
    val tempList = aArray.toMutableList()
    tempList.remove(maxVal)
    val secondVal = tempList.max()
    repeat(aArray.size) { i ->
        if (aArray[i] == maxVal) println(secondVal) else println(maxVal)
    }
}
