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