#include <bits/stdc++.h>
using namespace std;
int main() {
  int N;
  cin >> N;
  vector<int> A(N);
  for (int i = 0; i < N; ++i) {
    cin >> A[i];
  }
  vector<int> B(N);
  for (int i = 0; i < N; ++i) {
    B[i] = A[i];
  }
  sort(B.begin(), B.end());
  int res[N];
  for (int i = 0; i < N; ++i) {
    res[i] = B[N - 1];
  }
  res[N - 2] = B[N - 2];
  for (int i = 0; i < N; ++i) {
    cout << res[i] << endl;
  }
}
