#include <bits/stdc++.h>
using namespace std;
int main() {
  int N;
  cin >> N;
  vector<int> A(N);
  for (int t = 0; t < N; t++) {
    cin >> A.at(t);
  }
  int max = 0;
  for (int t = 0; t < N; t++) {
    if (A.at(t) > max) {
      max = A.at(t);
    }
  }
  int n_of_max = 0;
  for (int t = 0; t < N; t++) {
    if (A.at(t) == max) {
      n_of_max++;
    }
  }
  if (n_of_max = 1) {
    for (int t = 0; t < N; t++) {
      if (A.at(t) != max) {
        cout << max << endl;
      } else {
        int submax = 0;
        for (int i = 0; i < N; i++) {
          if (i != t && A.at(i) > submax) {
            submax = A.at(i);
          }
        }
        cout << submax << endl;
      }
    }
  } else {
    for (int t = 0; t < N; t++) {
      cout << max << endl;
    }
  }
}
