#include <bits/stdc++.h>
using namespace std;
struct edge {
  long long to, cost;
};
long long ans, ans2;
long long b[111111];
signed main() {
  long long n, a[111111];
  cin >> n;
  for (long long i = 0; i < n; i++) {
    cin >> a[i];
    b[i] = a[i];
  }
  sort(a, a + n);
  long long max = a[n - 1], max2 = a[n - 2];
  for (long long i = 0; i < n; i++) {
    if (b[i] != max)
      cout << max << endl;
    else
      cout << max2 << endl;
  }
}
