#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  int a[n];
  for (int i = 0; i < n; i++) cin >> a[i];
  int max = a[0];
  int pos;
  for (int i = 0; i < n; i++) {
    if (max < a[i]) {
      max = a[i];
      pos = i;
    }
  }
  int count = 0;
  for (int i = 0; i < n; i++) {
    if (max == a[i]) count++;
  }
  if (count > 1) {
    for (int i = 0; i < n; i++) cout << max << " ";
    cout << endl;
  } else {
    int tmp = a[0];
    for (int i = 0; i < n; i++) {
      if (a[i] > tmp && a[i] != max) {
        tmp = a[i];
      }
    }
    for (int i = 0; i < n; ++i) {
      if (i == pos) {
        cout << tmp << " ";
      } else {
        cout << max << " ";
      }
    }
    cout << endl;
  }
  return 0;
}
