#include <bits/stdc++.h>
using namespace std;
int Set(int N, int pos) { return N = N | (1 << pos); }
int Reset(int N, int pos) { return N = N & ~(1 << pos); }
bool Check(int N, int pos) { return (bool)(N & (1 << pos)); }
long long BM(long long a, long long b, long long m) {
  if (b == 0) return 1;
  long long x = BM(a, b / 2, m);
  x = ((x % m) * (x % m)) % m;
  if (b % 2) x = ((x % m) * (a % m)) % m;
  return x;
}
int ara[100005 * 2], ans[100005 * 2], Left[100005 * 2], Right[100005 * 2];
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  for (__typeof(1) i = 1; i <= n; i++) {
    cin >> ara[i];
  }
  for (__typeof(1) i = 1; i <= n; i++) {
    Left[i] = max(Left[i - 1], ara[i]);
  }
  for (int i = n; i >= 1; i--) {
    Right[i] = max(Right[n + 1], ara[i]);
  }
  for (int i = 1; i <= n; i++) {
    ans[i] = max(Left[i - 1], Right[i + 1]);
  }
  for (__typeof(1) i = 1; i <= n; i++) {
    cout << ans[i] << endl;
  }
  return 0;
}
