#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> ans = a;
  sort(ans.rbegin(), ans.rend());
  for (int i = 0; i < (n); ++i) cout << ans[i] << endl;
  for (int i = 0; i < (n); ++i) {
    if (a[i] == ans[0]) {
      cout << ans[1] << endl;
    } else {
      cout << ans[0] << endl;
    }
  }
  return 0;
}
