#include <bits/stdc++.h>
using namespace std;
int main() {
  int i, n, a[200000], max, sec, I, ok;
  cin >> n;
  cin >> a[0];
  max = a[0];
  sec = max;
  for (i = 1; i < n; i++) {
    cin >> a[i];
    if (a[i] == max) ok = 0;
    if (a[i] > max) {
      if (max > sec) sec = max;
      max = a[i];
      I = i;
      ok = 1;
    } else if (a[i] > sec)
      sec = a[0];
  }
  if (ok) {
    for (i = 0; i < I; i++) cout << max << endl;
    cout << sec << endl;
    for (i = I + 1; i < n; i++) cout << max << endl;
  } else
    for (i = 0; i < n; i++) cout << max << endl;
}
