#include <bits/stdc++.h>
int main(void) {
  int A[200000] = {};
  int B[200000] = {};
  int N, max[2];
  scanf("%d", &N);
  for (int i = 0; i < N; i++) scanf("%d", &A[i]);
  int max_num;
  for (int i = 0; i < N + 1; i++) {
    if (max[0] < A[i]) {
      max[1] = max[0];
      max[0] = A[i];
      max_num = i;
    }
    if (max[1] < A[i + 1]) max[1] = A[i + 1];
  }
  printf("一番大きいのは%d 二番目は%d\n", max[0], max[1]);
  for (int k = 0; k < N; k++) {
    if (k != max_num)
      printf("%d\n", max[0]);
    else {
      printf("%d\n", max[1]);
    }
  }
}
