#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using Pii = pair<int, int>;
using Pll = pair<ll, ll>;
int main(int argc, char *argv[]) {
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll N;
  cin >> N;
  vector<ll> A(N);
  for (ll i = 0; i < (N); i++) {
    cin >> A[i];
  }
  ll memo = 0;
  for (ll i = 0; i < (N); i++) {
    memo = max(memo, A[i]);
  }
  bool flag = false;
  ll cnt = 0;
  ll second = 0;
  for (ll i = 0; i < (N); i++) {
    if (memo != A[i]) {
      second = A[i];
    }
    if (memo == A[i]) {
      cnt++;
    }
  }
  if (cnt >= 2) {
    flag = true;
  }
  for (ll i = 0; i < (N); i++) {
    if (flag) {
      cout << memo << endl;
    } else {
      if (A[i] == memo) {
        cout << second << endl;
      } else {
        cout << memo << endl;
      }
    }
  }
  return 0;
}
