import Foundation
let n = Int(readLine()!)!
var a: [Int] = .init(repeating: 0, count: n)
for i in 0..<n {
  a[i] = Int(readLine()!)!
}
let sort = a.sorted()
let maxV = sort.last!
let maxVPrev = sort[sort.count - 2]

for i in 0..<n {
  if maxV == maxVPrev {
    print(maxV)
  } else if maxV == a[i] {
    print(maxVPrev)
  } else {
    print(maxV)
  }
}