#include <bits/stdc++.h>
using namespace std;
char IO;
int rd() {
  int s = 0, f = 0;
  while (!isdigit(IO = getchar()))
    if (IO == '-') f = 1;
  do s = (s << 1) + (s << 3) + (IO ^ '0');
  while (isdigit(IO = getchar()));
  return f ? -s : s;
}
const int N = 1e5 + 10;
int n, a[N];
int s[N], s1[N];
int main() {
  for (int i = 1, iend = n = rd(); i <= iend; ++i)
    a[i] = rd(), s[i] = max(a[i], s[i - 1]);
  for (int i = n, iend = 1; i >= iend; --i) s1[i] = max(a[i], s1[i + 1]);
  for (int i = 1, iend = n; i <= iend; ++i) {
    printf("%d\n", max(s[i - 1], s1[i + 1]));
  };
}
