#include <bits/stdc++.h>
using namespace std;
int main(void) {
  int N, A[200000];
  int num, i, max = 0, count = 0, maxcount, max2 = 0;
  cin >> N;
  for (i = 0; i < N; i++) {
    cin >> A[i];
  }
  for (i = 0; i < N; i++) {
    if (max < A[i]) {
      max = A[i];
      maxcount = i;
    }
    if (A[i] > max2 && A[i] < max) {
      max2 = A[i];
    }
  }
  for (i = 0; i < N; i++) {
    if (A[i] == max) count++;
  }
  for (i = 0; i < N; i++) {
    if (i != maxcount) {
      cout << max << endl;
    } else if (i == maxcount && count >= 2) {
      cout << max << endl;
    } else if (i == maxcount && count == 1) {
      cout << max2 << endl;
    }
  }
  return 0;
}
