#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  int max = 0;
  int index = 0;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    if (max > a[i]) {
      max = a[i];
      index = i;
    }
  }
  sort(a.begin(), a.end());
  int max2 = a[2];
  for (int i = 0; i < n; i++) {
    if (i == index)
      cout << max2 << endl;
    else
      cout << max << endl;
  }
  return 0;
}
