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