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