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