#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, i, max1, max2, mx = 0;
  cin >> n;
  int a[n];
  cin >> a[0];
  max1 = a[0];
  max2 = 0;
  for (i = 1; i < n; i++) {
    cin >> a[i];
    if (a[i] > max1) max1 = a[i];
  }
  for (i = 0; i < n; i++) {
    if (max1 == a[i]) mx++;
    if (a[i] > max2 && a[i] < max1) max2 = a[i];
  }
  if (max2 == 0) max2 = max1;
  if (mx == 0)
    for (i = 0; i < n; i++) {
      if (a[i] == max1)
        cout << max2 << "\n";
      else
        cout << max1 << "\n";
    }
  else
    for (i = 0; i < n; i++) {
      cout << max1 << "\n";
    }
  return 0;
}
