#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define MAX_N 10000000
#define ll longlong
using namespace std;

int main() {
  int n,ans=0; cin>>n;
  vector<int> a(n); vector<int> b(n);
  rep(i,n) {
    cin>>a[i]; b[i]=a[i];
  }
  sort(b.begin(),b.end());
  rep(i,n) {
      if(a_max==a[i]) cout<<b[n-2]<<endl;
      else cout<<b[n-1]<<endl;
    }
    return 0;
}