#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long N;
  cin >> N;
  vector<long long> V;
  for (long long i = 0; i < N; i++) {
    long long inp;
    cin >> inp;
    V.push_back(inp);
  }
  long long max = *max_element(V.begin(), V.end());
  long long max2 = V[0];
  for (long long i = 1; i < N; i++) {
    if (V[i] > max2 && V[i] < max) max2 = V[i];
  }
  long long count = 0;
  for (long long i = 0; i < N; i++) {
    if (V[i] == max) count++;
  }
  if (count > 1) {
    for (long long i = 0; i < N; i++) cout << max << endl;
  } else {
    for (long long i = 0; i < N; i++) {
      if (V[i] != max)
        cout << max << endl;
      else
        cout << max2 << endl;
    }
  }
  return 0;
}
