#include <bits/stdc++.h>
using namespace std;
void solve() {
  long long i, j = 0, r = 200, p, q, k = 0, ans = 0, d, y = 0, h, flag = 0, n,
               m = 0, a = 1000000007, b = 1000000007, id, c, h1, h2, a1, b1;
  cin >> n;
  vector<long long> v(n), as(n);
  for (i = 0; i < n; i++) cin >> v[i], as[i] = v[i];
  sort(v.begin(), v.end());
  if (as[0] == as[n - 1]) {
    for (i = 0; i < n; i++) {
      cout << v[0] << endl;
    }
    return;
  }
  for (i = 0; i < n; i++) {
    if (as[i] != v[n - 1])
      cout << v[n - 1] << endl;
    else if (as[i] == v[n - 1])
      cout << v[n - 2] << endl;
    else
      cout << v[n - 1] << endl;
  }
}
signed main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int t = 1;
  while (t--) solve();
}
