#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  int a[n];
  set<int> x;
  int max_val = 0;
  int dummy[n];
  for (int i = 0; i < (n); ++i) {
    cin >> a[i];
    x.insert(a[i]);
    max_val = max(max_val, a[i]);
  }
  auto itr = x.begin();
  itr++;
  int second_max_val = *itr;
  int count = 0;
  for (int i = 0; i < (n); ++i) {
    if (a[i] == max_val) count++;
  }
  for (int i = 0; i < (n); ++i) {
    if (count > 1) {
      cout << max_val << endl;
    } else {
      if (a[i] == max_val) {
        cout << second_max_val << endl;
      } else {
        cout << max_val << endl;
      }
    }
  }
  return 0;
}
