#include <bits/stdc++.h>
using namespace std;
int main() {
  int N, max, next;
  cin >> N;
  int A[N];
  for (int i = 0; i < N; i++) cin >> A[i];
  for (int i = 0; i < N; i++) {
    if (i == 0) {
      max = A[i];
      next = A[i];
    } else {
      if (max <= A[i]) {
        next = max;
        max = A[i];
      } else if (next < A[i]) {
        next = A[i];
      }
    }
  }
  if (next == max) {
    for (int i = 0; i < N; i++) {
      cout << next << endl;
    }
  } else {
    for (int i = 0; i < N; i++) {
      if (A[i] == max)
        cout << next << endl;
      else
        cout << max << endl;
    }
  }
  return 0;
}
