#include <bits/stdc++.h>
using namespace std;
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long ans;
  long long n;
  cin >> n;
  long long a[n];
  long long m = 0;
  for (long long i = 0; i < n; i++) {
    cin >> a[i];
    m = max(m, a[i]);
  }
  long long m1 = 0;
  for (long long i = 0; i < n; i++) {
    if (max(m1, a[i]) != m) m1 = max(m1, a[i]);
  }
  if (m1 == 0) {
    for (long long i = 0; i < n; i++) cout << m << " ";
  } else {
    for (long long i = 0; i < n; i++) {
      if (a[i] == m)
        cout << m1 << " ";
      else
        cout << m << " ";
    }
  }
  cout << "\n";
  return 0;
}
