#include <bits/stdc++.h>
using namespace std;
const int INF = 1e9;
const int MOD = 1e9 + 7;
signed main() {
  int n;
  cin >> n;
  int a[n], t[n];
  for (int i = 0; i < (n); i++) {
    cin >> a[i];
    t[i] = a[i];
  }
  sort(t, t + n);
  if (t[n - 1] == t[n - 2]) {
    for (int i = 0; i < (n); i++) {
      cout << a[n - 1] << endl;
    }
  } else {
    for (int i = 0; i < (n); i++) {
      if (a[i] != t[n - 1])
        cout << t[n - 1] << endl;
      else
        cout << t[n - 2] << endl;
    }
  }
}
