#include <bits/stdc++.h>
int main(void) {
  int N, A[N];
  scanf("%d", &N);
  for (int k = 0; k < N; k++) scanf("%d", &A[k]);
  int i, max[200000];
  int l;
  for (l = 0; l < N; l++) max[l] = A[0];
  int j;
  for (i = 1; i < N; i++)
    for (j = 0; j < i; j++)
      if (max[i] < A[j]) max[i] = A[j];
  for (i = 1; i < N; i++)
    for (j = i + 1; j < N; j++)
      if (max[i] < A[j]) max[i] = A[j];
  max[0] = A[1];
  int m;
  for (m = 2; m < N; m++)
    if (max[0] < A[m]) max[0] = A[m];
  for (int n = 0; n < N; n++) printf("%d\n", max[n]);
  return 0;
}
