#include <bits/stdc++.h>
using namespace std;
const long long int INF = 99999999999999;
const long long int MOD = 1000000007;
int main() {
  long long int n;
  cin >> n;
  vector<long long int> v;
  for (long long int i = 0; i < long long int(n); i++) {
    long long int x;
    cin >> x;
    v.push_back(x);
  };
  long long int mx = 0, sec = 0;
  for (long long int i = 0; i < long long int(n); i++) {
    mx = max(mx, v[i]);
  }
  for (long long int i = 0; i < long long int(n); i++) {
    if (v[i] < mx) {
      sec = max(sec, v[i]);
    }
  }
  long long int count = 0;
  for (long long int i = 0; i < long long int(n); i++) {
    if (v[i] == mx) {
      count++;
    }
  }
  vector<long long int> ans(n);
  if (count == 1) {
    for (long long int i = 0; i < long long int(n); i++) {
      if (v[i] == mx) {
        ans[i] = sec;
      } else {
        ans[i] = mx;
      }
    }
  }
  if (count > 1) {
    vector<long long int> ans(n, mx);
  }
  for (long long int i = 0; i < long long int(n); i++) {
    cout << ans[i] << endl;
  }
  return 0;
}
