#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  int a[n];
  int maximum = 0;
  int maximum2 = 0;
  bool isMaximums = false;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    maximum = max(maximum, a[i]);
  }
  for (int i = 0; i < n; i++) {
    if (a[i] == maximum) {
      isMaximums = true;
      break;
    } else {
      maximum2 = max(maximum2, a[i]);
    }
  }
  for (int i = 0; i < n; i++) {
    if (maximum > a[i] || isMaximums)
      cout << maximum << endl;
    else
      cout << maximum2 << endl;
  }
}
