#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  for (int i = 0; i < n; i++) {
    cin >> a.at(i);
  }
  int max = 0;
  int semi = 0;
  for (int i = 1; i < n; i++) {
    if (max < a.at(i)) {
      semi = max;
      max = a.at(i);
    } else {
      if (semi < a.at(i)) {
        semi = a.at(i);
      }
    }
  }
  for (int i = 0; i < n; i++) {
    if (a.at(i) < max) {
      cout << max << endl;
    } else {
      cout << semi << endl;
    }
  }
}
