#include <bits/stdc++.h>
using namespace std;
int main() {
  int N;
  cin >> N;
  vector<int> A(N);
  auto* const a = &A[0];
  for (int i = 0; i < N; ++i) cin >> a[i];
  sort(a, a + N, greater<int>());
  int first = a[0];
  int second = a[1];
  if (first == second)
    for (int i = 0; i < N; ++i) cout << first << endl;
  else
    for (int i = 0; i < N; ++i)
      cout << (first == a[i] ? second : first) << endl;
  return 0;
}
