#include <bits/stdc++.h>
using namespace std;
int n;
int a[200020];
int b[200020];
int main() {
  cin >> n;
  int cnt = 0;
  int haha = 0;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
    b[i] = a[i];
    cnt = max(cnt, a[i]);
  }
  for (int i = 1; i <= n; i++) {
    if (a[i] < cnt) {
      haha = max(haha, a[i]);
    }
  }
  for (int i = 1; i <= n; i++) {
    if (haha == 0) {
      cout << cnt << endl;
      continue;
    }
    if (a[i] == cnt) {
      cout << haha << endl;
    } else {
      cout << cnt << endl;
    }
  }
}
