#include <bits/stdc++.h>
using namespace std;
long long n, a[200005], x, y;
set<long long> s;
void solve() {
  cin >> n;
  for (__typeof((n + 1)) i = (1); i < (n + 1); i++) cin >> a[i], s.insert(a[i]);
  auto it = s.end();
  it--;
  x = *it;
  it--;
  if ((long long)s.size() != 1)
    y = *it;
  else {
    for (__typeof((n + 1)) i = (1); i < (n + 1); i++) cout << x << "\n";
    return;
  }
  for (__typeof((n + 1)) i = (1); i < (n + 1); i++) {
    if (a[i] == x)
      cout << y << "\n";
    else
      cout << x << "\n";
  }
}
void prep() {}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  long long t = 1;
  prep();
  cout << fixed << setprecision(12);
  while (t--) solve();
  return 0;
}
