#include <bits/stdc++.h>
using namespace std;
int main() {
  long long N;
  cin >> N;
  vector<long long> vec(N);
  for (int i = 0; i < N; i++) cin >> vec[i];
  vector<long long> sorted;
  sorted = vec;
  sort(sorted.begin(), sorted.end());
  long long first, second;
  first = sorted.back();
  if (first == sorted[0]) {
    second = first;
  } else {
    for (int i = N - 1; i >= 0; i--) {
      if (first != sorted[i]) {
        second = sorted[i];
        break;
      }
    }
  }
  for (int i = 0; i < N; i++) {
    if (vec[i] == first) {
      cout << second << endl;
    } else {
      cout << first << endl;
    }
  }
  return 0;
}
