#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, s = 0;
  cin >> n;
  int ar[n], ar1[n];
  for (int i = 0; i < n; i++) {
    cin >> ar[i];
    ar1[i] = ar[i];
    s += ar[i];
  }
  int f = 0;
  for (int i = 0; i < n - 1; i++) {
    if (ar[i] != ar[i + 1]) {
      f = 1;
      break;
    }
  }
  sort(ar, ar + n);
  if (f == 0) {
    for (int i = 0; i < n; i++) cout << ar[n - 1] << endl;
    ;
  } else {
    int q;
    for (int i = n - 1; i >= 0; i--) {
      if (ar[i] != ar[n - 1]) {
        q = ar[i];
        break;
      }
    }
    for (int i = 0; i < n; i++) {
      if (ar1[i] != ar[n - 1])
        cout << ar[n - 1] << endl;
      else
        cout << q << endl;
    }
  }
  return 0;
}
