#include <bits/stdc++.h>
using namespace std;
int maxn[200001], maxnnn = -1, amax[200002], d[200001];
int main() {
  int n;
  scanf("%d", &n);
  for (int i = 1; i <= n; ++i) scanf("%d", &d[i]);
  maxn[1] = d[1], maxnnn = d[1];
  for (int i = 2; i <= n; ++i) {
    maxn[i] = maxn[i - 1];
    if (d[i - 1] > maxnnn) maxn[i] = d[i - 1], maxnnn = d[i - 1];
  }
  amax[n] = d[n], maxnnn = d[n];
  for (int i = n - 1; i >= 1; --i) {
    amax[i] = amax[i + 1];
    if (d[i + 1] > maxnnn) amax[i] = d[i + 1], maxnnn = d[i + 1];
  }
  for (int i = 1; i <= n; ++i) printf("%d\n", max(maxn[i], amax[i]));
  return 0;
}
