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