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