#include <bits/stdc++.h>
int main() {
  int n, a[200005], i, j, x, d;
  while (~scanf("%d", &n)) {
    for (i = 0; i < n; i++) {
      scanf("%d", &a[i]);
    }
    for (j = 1; j < 3; j++)
      for (i = 1; i < n - 1 - j; i++) {
        if (a[i] > a[i + 1]) {
          d = a[i];
          a[i] = a[i + 1];
          a[i + 1] = d;
        }
      }
    if (n == 2)
      printf("%d\n", a[n - 1]);
    else
      printf("%d\n", a[n - 2]);
    for (i = 0; i < n - 1; i++) printf("%d\n", a[n - 1]);
  }
}
