#include <bits/stdc++.h>
using namespace std;
int main(void) {
  int N;
  cin >> N;
  vector<long long int> a(N, 0);
  vector<long long int> b(N, 0);
  for (int i = 0; i < N; i++) {
    cin >> a[i];
    b[i] = a[i];
  }
  sort(b.begin(), b.end());
  long long int max1;
  long long int max2;
  max1 = b[N - 1];
  max2 = 0;
  int k = 0;
  while (b[k] != max1) {
    k++;
    if (b[k] != max1) {
      max2 = b[k];
    }
  }
  if (max2 == 0) {
    max2 = max1;
  }
  if (max1 == max2) {
    for (int l = 0; l < N; l++) {
      cout << max1 << endl;
    }
  } else {
    for (int j = 0; j < N; j++) {
      if (a[j] == max1) {
        cout << max2 << endl;
      } else {
        cout << max1 << endl;
      }
    }
  }
  return 0;
}
