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