#include <bits/stdc++.h>
using namespace std;
int main(void) {
  int n;
  cin >> n;
  int a[n];
  int max, max2;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    if (i == 0) {
      max = a[0];
      max2 = a[0];
    }
    if (a[i] > max) {
      max = a[i];
    } else if (a[i] > max2) {
      max2 = a[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 << endl;
  } else {
    for (int i = 0; i < n; i++) {
      if (a[i] == max)
        cout << max2 << endl;
      else
        cout << max << endl;
    }
  }
  return 0;
}
