#include <bits/stdc++.h>
using namespace std;
int main() {
  long long n;
  cin >> n;
  vector<long long> a(n);
  for (long long i = 0; i < n; i++) cin >> a.at(i);
  int max = *max_element(a.begin(), a.end());
  cerr << "maxの値:" << max << endl;
  for (long long i = 0; i < n; i++) {
    if (a.at(i) != max)
      cout << max << endl;
    else {
      vector<long long> b(a);
      sort(b.begin(), b.end());
      cout << b.at(1) << endl;
    }
  }
}
