#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using piii = pair<pii, pii>;
const ll dx[4] = {0, -1, 1, 0};
const ll dy[4] = {-1, 0, 0, 1};
const int INF = 1e9 + 7;
int gcd(int x, int y) {
  if (x < y) swap(x, y);
  if (y == 0) return x;
  return gcd(y, x % y);
}
void mul(ll a, ll b) { a = a * b % INF; }
double mysqrt(double x) {
  double l = 0, r = x;
  for (int i = 0; i < 64; ++i) {
    double m = (l + r) / 2.0;
    if (m * m < x)
      l = m;
    else
      r = m;
  }
  return l;
}
int main() {
  int n;
  cin >> n;
  int a[200100];
  vector<pii> key;
  int ans = 0;
  for (int i = 0; i < n; ++i) {
    cin >> a[i];
    ans = max(ans, a[i]);
  }
  int second = 0;
  for (int i = 0; i < n; ++i) {
    if (a[i] == ans) continue;
    second = max(second, a[i]);
  }
  for (int i = 0; i < n; ++i) {
    if (a[i] != ans) {
      cout << ans << endl;
    } else {
      cout << second << endl;
    }
  }
  return 0;
}
