#include <bits/stdc++.h>
using namespace std;
int main() {
  int N;
  cin >> N;
  int A[N];
  int maxa = 0;
  int maxN = 0;
  for (int i = 0; i < N; i++) {
    cin >> A[i];
    if (maxa < A[i]) {
      maxa = A[i];
      maxN = i;
    }
  }
  sort(A, A + N, greater<int>());
  if (A[0] == A[1]) {
    for (int i = 0; i < N; i++) {
      cout << A[0] << endl;
    }
  } else {
    for (int i = 0; i < N; i++) {
      if (i != maxN) {
        cout << A[0] << endl;
      } else {
        cout << A[i] << endl;
      }
    }
  }
}
