#include <bits/stdc++.h>
using namespace std;
const int maxn = 200010;
int a[maxn], b[maxn];
bool cmp(int a, int b) { return a > b; }
int main() {
  int n;
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
    b[i] = a[i];
  }
  sort(b + 1, b + n + 1, cmp);
  int maxa = b[1];
  int i = 1;
  while (i <= n && b[i] == b[1]) i++;
  if (i > n) {
    for (int i = 1; i <= n; i++) cout << maxa << endl;
  } else {
    int maxb = b[i];
    for (int i = 1; i <= n; i++) {
      if (a[i] == maxa)
        cout << maxb << endl;
      else
        cout << maxa << endl;
    }
  }
  return 0;
}
