#include <bits/stdc++.h>
using namespace std;
int main() {
  long long int n, in;
  cin >> n;
  vector<long long> v;
  for (int i = 0; i < n; i++) {
    cin >> in;
    v.push_back(in);
  }
  map<long long, int> m;
  long long ans = v[0], cnt = 0, ans2 = v[0];
  for (int i = 0; i < n; i++) {
    m[v[i]]++;
    if (ans < v[i]) {
      ans2 = ans;
      ans = v[i];
    } else if (v[i] > ans2 && v[i] != ans)
      ans2 = v[i];
  }
  bool flag = false;
  if (m[ans] > 1) flag = true;
  for (int i = 0; i < n; i++) {
    if (v[i] == ans) {
      long long val = INT_MIN;
      if (flag) {
        cout << ans << endl;
      } else {
        cout << ans2 << endl;
      }
    } else
      cout << ans << endl;
  }
  return 0;
}
