#include <bits/stdc++.h>
using namespace std;
int n;
int a[20000021];
int qian[20000021];
int hou[20000021];
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    scanf("%d", &a[i]);
  }
  a[0] = a[n + 1] = -1;
  for (int i = 1; i <= n; i++) {
    for (int j = i - 1; j > 0; j--) {
      qian[i] = max(qian[i], a[j]);
    }
    for (int j = i + 1; j <= n; j++) {
      hou[i] = max(hou[i], a[j]);
    }
  }
  for (int i = 1; i <= n; i++) {
    printf("%d\n", max(qian[i], hou[i]));
  }
  return 0;
}
