#include <bits/stdc++.h>
using namespace std;
const int INF = 1 << 30;
const long long LINF = 1LL << 60;
const long long mod = 1e9 + 7;
template <class T>
bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T>
bool chmin(T &a, const T &b) {
  if (b < a) {
    a = b;
    return 1;
  }
  return 0;
}
long long n;
long long a[200000 + 5];
long long till[200000 + 5];
long long bk[200000 + 5];
int main() {
  scanf("%lld", &n);
  for (int i = (1); i <= (n); i++) {
    long long cur;
    scanf("%lld", &cur);
    a[i] = cur;
    if (till[i - 1] < cur)
      till[i] = cur;
    else
      till[i] = till[i - 1];
  }
  for (int i = n; i >= 1; i--) {
    if (a[i] > bk[i - 1])
      bk[i] = a[i];
    else
      bk[i] = bk[i + 1];
  }
  for (int i = (1); i <= (n); i++) {
    cout << max(till[i - 1], bk[i + 1]) << "\n";
  }
  return 0;
}
