#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 max1 = a[0];
  int memo = 0;
  for (int i = 0; i < n; i++) {
    if (max1 < a[i]) {
      max1 = a[i];
      memo = i;
    }
  }
  int count = 0;
  for (int i = 0; i < n; i++) {
    if (a[i] == max1) {
      count++;
    }
  }
  if (count >= 2) {
    for (int i = 0; i < n; i++) {
      cout << max1 << endl;
    }
  } else {
    int max2 = a[0];
    for (int i = 0; i < n; i++) {
      if (i != memo && max2 < a[i]) {
        max2 = a[i];
      }
    }
    for (int i = 0; i < n; i++) {
      if (i != memo) {
        cout << max1 << endl;
      } else {
        cout << max2 << endl;
      }
    }
  }
  return 0;
}
