#include <bits/stdc++.h>
using namespace std;
inline int toInt(string s) {
  int v;
  istringstream sin(s);
  sin >> v;
  return v;
}
template <class T>
inline string toString(T x) {
  ostringstream sout;
  sout << x;
  return sout.str();
}
template <class T>
inline T sqr(T x) {
  return x * x;
}
const double EPS = 1e-10;
const double PI = acos(-1.0);
void solve(long long N, std::vector<long long> A) {
  vector<long long> S = A;
  sort((S).begin(), (S).end());
  long long m = S[S.size() - 1];
  long long sub = m;
  for (int i = N - 1; i >= 0; i--) {
    if (S[i] < m) {
      sub = S[i];
      break;
    }
  }
  for (int i = 1; i <= N; i++) {
    if (A[i - 1] == m)
      cout << sub << endl;
    else
      cout << m << endl;
  }
  return;
}
int main() {
  long long N;
  scanf("%lld", &N);
  std::vector<long long> A(N);
  for (int i = 0; i < N; i++) {
    scanf("%lld", &A[i]);
  }
  solve(N, std::move(A));
  return 0;
}
