#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  long long n, a, b;
  cin >> n;
  vector<long long> A(n);
  for (long long i = 0; i < n; ++i) cin >> A[i];
  sort(A.rbegin(), A.rend());
  a = A[0], b = A[1];
  for (long long i = 0; i < n; ++i) {
    if (A[i] == a)
      cout << (b) << endl;
    else
      cout << (a) << endl;
  }
  return 0;
}
