#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main() {
  int n;
  cin >> n;
  vector<int> v(n);
  vector<int> v1(n);
  vector<bool> ok(n, true);
  int mx = 0;
  for (int i = 0; i < (n); ++i) {
    cin >> v[i];
    v1[i] = v[i];
  }
  sort(v1.begin(), v1.end());
  int c = 0;
  for (int i = 0; i < (n); ++i) {
    if (v[i] == v1[n - 1]) {
      c++;
      ok[i] = false;
    } else
      mx = max(mx, v[i]);
  }
  if (c == 1) {
    for (int i = 0; i < (n); ++i) {
      if (ok[i]) {
        cout << v1[n - 1] << endl;
      } else {
        cout << mx << endl;
      }
    }
  } else {
    for (int i = 0; i < (n); ++i) {
      cout << v[n - 1] << endl;
    }
  }
}
