#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  int m = -1, mm = -1;
  for (int i = 0; i < (n); ++i) {
    cin >> a[i];
    if (a[i] > m) {
      mm = m;
      m = a[i];
    } else if (a[i] > mm) {
      mm = a[i];
    }
  }
  cout << m << mm << endl;
  for (int i = 0; i < (n); ++i) {
    if (a[i] == m)
      cout << mm << endl;
    else
      cout << m << endl;
  }
}
