#include <bits/stdc++.h>
using namespace std;
int main(void) {
  int n;
  cin >> n;
  vector<int> a(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  vector<int> b = a;
  sort(a.rbegin(), a.rend());
  for (int i = 0; i < n; i++) {
    int ans = a[0];
    if (b[i] = a[0]) ans = a[1];
    cout << ans << endl;
  }
  return 0;
}
