#include <bits/stdc++.h>
using namespace std;
int n;
int a[200000];
long long ans = 1;
int main() {
  cin >> n;
  int c = 0;
  int max_ = -1;
  int pos;
  int smax;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    if (a[i] > max_) {
      smax = max_;
      max_ = a[i];
    }
  }
  for (int i = 0; i < n; i++) {
    if (a[i] == max_) {
      c++;
      pos = i;
    }
  }
  sort(a, a + n);
  if (c > 1) {
    for (int i = 0; i < n; i++) cout << max_ << endl;
    return 0;
  }
  for (int i = 0; i < n; i++) {
    if (i == pos) {
      cout << smax << endl;
    } else {
      cout << max_ << endl;
    }
  }
}
