#include <bits/stdc++.h>
using namespace std;
int32_t main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  ;
  long long n, m = INT_MIN, x, ind;
  cin >> n;
  long long array[n], b[n];
  multiset<long long> s;
  for (long long i(0); i < n; i++) {
    cin >> x;
    array[i] = x;
    b[i] = x;
    s.insert(x);
  }
  sort(array, array + n);
  for (long long i(0); i < n; i++) {
    if (b[i] == array[n - 1]) {
      if (s.count(b[i]) == 1)
        cout << array[n - 2] << "\n";
      else
        cout << array[n - 1] << "\n";
    } else
      cout << array[n - 1] << "\n";
  }
  return 0;
}
