#include <bits/stdc++.h>
using namespace std;
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  long long N;
  cin >> N;
  long long A[200005];
  long long B[200005];
  long long m = -1;
  bool f = false;
  for (int i = 0; i < N; i++) {
    cin >> A[i];
    if (A[i] > m) {
      m = A[i];
      f = false;
    } else if (A[i] == m) {
      f = true;
    }
    B[i] = A[i];
  }
  sort(B, B + N);
  for (int i = 0; i < N; i++) {
    if (f)
      cout << A[i] << endl;
    else {
      if (A[i] == m)
        cout << B[N - 2] << endl;
      else
        cout << m << endl;
    }
  }
  return 0;
}
