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

typedef long long ll;
const double EPS = 1e-9;
typedef vector<int> vint;
typedef pair<int, int> pint;
#define rep(i, n) REP(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for(int i = x; i < n; i++)

int main() {
  int n;
  int max=-1;
  int sbmax=-1;
  cin >> n;
  vector<int> vec(n);
  rep(i,n){
    cin >> vec[i];
    if (max < vec[i]){
      max=vec[i];
      sbmax=max;
  }
  rep(i,n){
    if (vec[i]==max) cout << sbmax << endl;
    else cout << max << endl;
  }
  
  return 0;
}
