#include <bits/stdc++.h>
using namespace std;

int main(){
  int n; cin>>n;
  vector<int> a(n),b(n);
  for (int i=0; i<n; i++) cin>>a[i];
  b=a;
  sort(b.begin(), b.end());
  int max_a=b[n-1];
  int next_a=b[n-2];
  for (int j=0; j<n; j++){
    if (a[j]!=max_a) cout<<max_a<<endl;
    else cout<<next_a<<endl;
  }
}