#include <bits/stdc++.h>
using namespace std;
const int N = 200010;
inline char get() {
  static char buf[1024];
  static int pos = 0, size = 0;
  if (pos == size) {
    size = fread(buf, 1, 1024, stdin);
    pos = 0;
    if (!size)
      return EOF;
    else
      return buf[pos++];
  } else
    return buf[pos++];
}
int read() {
  int sum = 0, fh = 1;
  char ch = get();
  while (!(ch >= '0' && ch <= '9')) {
    if (ch == '-') fh = -1;
    ch = get();
  }
  while (ch >= '0' && ch <= '9' && ch != EOF)
    sum = sum * 10 + ch - 48, ch = get();
  return sum * fh;
}
int n, d[N], ma[N][2];
int main() {
  n = read();
  for (int i = 1; i <= n; i++) {
    d[i] = read();
    ma[i][0] = max(ma[i - 1][0], d[i]);
  }
  for (int i = n; i >= 1; i--) ma[i][1] = max(ma[i + 1][0], d[i]);
  for (int i = 1; i <= n; i++) printf("%d\n", max(ma[i - 1][0], ma[i + 1][1]));
  return 0;
}
