#include <bits/stdc++.h>
using namespace std;
long long inf = 1e10;
long long w[105], v[105];
long long dp[300005];
long long a[200005];
long long b[200005];
int main() {
  long long n;
  cin >> n;
  long long max = -inf;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    b[i] = a[i];
    if (max < a[i]) {
      max = a[i];
    }
  }
  sort(a, a + n);
  long long ans = 0;
  for (int i = n - 1; i >= 0; i--) {
    if (a[i] != max) {
      ans = i;
      break;
    }
  }
  for (int i = 0; i < n; i++) {
    if (b[i] != max) {
      cout << a[n - 1] << endl;
    } else {
      cout << a[ans] << endl;
    }
  }
  return 0;
}
