#include <bits/stdc++.h>
using namespace std;
constexpr long long MOD = 1000000007;
using ll = long long;
int main() {
  ll n;
  cin >> n;
  ll a[n];
  ll b[n];
  for (ll i = 0; i < n; i++) {
    cin >> a[i];
    b[i] = a[i];
  }
  sort(b, b + n);
  bool flag = false;
  if (a[n - 1] == a[n - 2]) flag = true;
  ll maxi = 0;
  for (ll i = 0; i < n; i++) {
    maxi = max(maxi, a[i]);
  }
  for (ll i = 0; i < n; i++) {
    if (a[i] == maxi) {
      if (flag)
        cout << b[n - 1] << endl;
      else
        cout << b[n - 2] << endl;
    } else
      cout << b[n - 1] << endl;
  }
}
