#include <bits/stdc++.h>
#pragma GCC optimize("O3")
using namespace std;
int N;
int A[200000];
int main(void) {
  int i, max = 0, semimax = 0;
  bool maxdup = false;
  cin >> N;
  for (i = 0; i < N; i++) {
    cin >> A[i];
    if (max < A[i]) {
      semimax = max;
      max = A[i];
    } else if (max == A[i]) {
      maxdup = true;
    } else if (semimax < A[i]) {
      semimax = A[i];
    }
  }
  for (i = 0; i < N; i++) {
    if (A[i] == max) {
      if (maxdup == false) {
        cout << semimax;
      } else {
        cout << max;
      }
    } else {
      cout << max;
    }
    cout << endl;
  }
  return 0;
}
