#include <bits/stdc++.h>
using namespace std;
long long power(long long x, long long y);
long long gcd(long long a, long long b);
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long n;
  cin >> n;
  long long a[n];
  set<long long> s;
  long long mx = 0;
  vector<long long> v;
  for (long long i = 0; i < n; i++) {
    cin >> a[i];
    mx = max(a[i], mx);
    s.insert(a[i]);
    v.push_back(a[i]);
  }
  sort(v.begin(), v.end());
  if (s.size() == 1) {
    for (long long i = 0; i < n; i++) {
      cout << mx << "\n";
    }
  } else {
    vector<long long>::iterator lower;
    lower = lower_bound(v.begin(), v.end(), mx);
    long long u = lower - v.begin();
    u--;
    for (long long i = 0; i < n; i++) {
      if (a[i] == mx)
        cout << v[u] << "\n";
      else
        cout << mx << "\n";
    }
  }
}
long long power(long long x, long long y) {
  long long res = 1;
  x %= 998244353;
  while (y > 0) {
    if (y & 1) res = (res * x) % 998244353;
    y = y >> 1;
    x = (x * x) % 998244353;
  }
  return res % 998244353;
}
long long gcd(long long a, long long b) {
  if (a == 0) return b;
  return gcd(b % a, a);
}
