#include <bits/stdc++.h>
using namespace std;
using pint = pair<int, int>;
using vec = vector<int>;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
template <class T>
inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template <class T>
inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const double pi = acos(-1);
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  ll n;
  ;
  cin >> n;
  vll a(n);
  vll cnt(1000000000000000000ll);
  ll ans = 0;
  for (int i = 0; i < (int)(n); i++) {
    cin >> a[i];
    cnt[a[i]]++;
  }
  sort(a.begin(), a.end());
  ans = a[n - 1];
  for (int i = 0; i < (int)(n); i++) {
    if (ans > a[i])
      cout << ans << endl;
    else {
      if (cnt[a[i]] >= 2)
        cout << ans << endl;
      else
        cout << a[n - 2] << endl;
    }
  }
}
