#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
typedef long long ll;
#define _GLIBCXX_DEBUG
typedef vector<int> vec;
typedef vector<ll> lvec;
typedef vector<char>cvec;
typedef pair<ll, ll> LP;
typedef tuple<ll, ll, ll> LT;
typedef pair<int, int> P;
typedef tuple<int, int, int> T;
int scnum(vector<int>x(n)){
  sort(rall(x));
  return x[1];
int main()	{
  int n;
  cin>>n;
  vector<int>a(n);
  int cm=0;
  rep(i,n) {
    cin>>a[i];
    cm=max(cm,a[i]);
  }
  cm2=scnum(a);
  rep(i,n){
    if(cm==a[i])
      cout<<cm2<<endl;
    else
      cout<<cm<<endl;
  }
}