#include <bits/stdc++.h>
using namespace std;
const int max_n = 2e5;
int main() {
  int n;
  cin >> n;
  int a[max_n];
  for (int i = 0; i < n; ++i) {
    cin >> a[i];
  }
  int k = 0, l = 0;
  if (a[0] > a[1]) {
    l = 1;
  }
  for (int i = 0; i < n; ++i) {
    if (a[k] < a[i]) {
      l = k;
      k = i;
    } else if (a[l] < a[i]) {
      l = i;
    }
  }
  for (int i = 0; i < n; ++i) {
    if (i == k) {
      cout << a[l] << endl;
    } else {
      cout << a[k] << endl;
    }
  }
}
