#include<bits/stdc++.h>
int main(){
  int N; std::cin >> N;
  std::vector<int>A(N),B;
  for(auto&e : A)
    std::cin >> e;
  B = A;
  std::sort(B.begin(),B.end(),greater<>());
  for(auto e : A){
    std:: cout << (e == B.front() ? B.at(1) : B.front()) << std:: endl;
  
}