#include <bits/stdc++.h>
using namespace std;
template <class T>
inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T>
inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
using Graph = vector<vector<long long>>;
signed main() {
  long long a;
  cin >> a;
  vector<long long> b(a), c(a);
  for (long long i = 0; i < a; i++) cin >> b[i];
  for (long long i = 0; i < a; i++) c[i] = b[i];
  sort(c.begin(), c.end());
  long long d = c[a - 1];
  long long e = c[a - 2];
  for (long long i = 0; i < a; i++) {
    if (b[i] != d)
      cout << e << endl;
    else
      cout << d << endl;
  }
}
