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