#include <bits/stdc++.h>
using namespace std;
long long mod = 2019;
long long INF = (long long)2e18;
signed main() {
  long long N;
  cin >> N;
  vector<long long> A(N);
  for (long long i = 0; i < N; i++) cin >> A[i];
  long long max_value = *max_element(A.begin(), A.end());
  long long max_count = 0;
  long long second_max = 0;
  for (long long i = 0; i < N; i++) {
    if (max_value == A[i]) ++max_count;
    if (max_value != A[i]) second_max = max(second_max, A[i]);
  }
  if (max_count == 2) {
    for (long long i = 0; i < N; i++) cout << max_value << endl;
  } else {
    for (long long i = 0; i < N; i++) {
      if (max_value != A[i])
        cout << max_value << endl;
      else
        cout << second_max << endl;
    }
  }
}
