#include <bits/stdc++.h>
using namespace std;
const int inf = 1000000000;
int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  vector<int> b(n);
  int ma = 0;
  int ma2 = 0;
  for (int i = 0; i < (n); i++) {
    cin >> a[i];
    ma = max(a[i], ma);
  }
  for (int i = 0; i < (n); i++) {
    if (a[i] != ma) {
      ma2 = max(ma2, a[i]);
    }
  }
  for (int i = 0; i < (n); i++) {
    if (a[i] == ma) {
      if (a[i] == ma2) {
        cout << a[i] << endl;
      } else {
        cout << ma2 << endl;
      }
    } else {
      cout << ma << endl;
    }
  }
}
