#include <bits/stdc++.h>
using namespace std;
int main() {
  int N;
  cin >> N;
  vector<int> a(N);
  vector<int> b(N);
  for (int i = 0; i < N; i++) {
    cin >> a.at(i);
    b.at(i) = a.at(i);
  }
  sort(b.begin(), b.end());
  int max_num = *max_element(a.begin(), a.end());
  for (int i = 0; i < N; i++) {
    if (a.at(i) < max_num) {
      cout << max_num << endl;
    } else {
      cout << b.at(1) << endl;
    }
  }
}
