#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  vector<int> v(n);
  vector<int> a(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  v = a;
  sort(v.begin(), v.end());
  int x = count(v.begin(), v.end(), v[n - 1]);
  for (int i = 0; i < n; i++) {
    if (a[i] != v[n - 1]) {
      cout << v[n - 1] << endl;
      x--;
    } else if (x > 0) {
      cout << v[n - 1] << endl;
      x--;
    } else {
      cout << v[n - 2] << endl;
    }
  }
}
