#include <bits/stdc++.h>
using namespace std;
int main() {
  int N;
  cin >> N;
  vector<int> list(N);
  vector<int> list2(N);
  vector<int> list3(N);
  int max = 0;
  for (int i = 0; i < (int)(N); i++) {
    cin >> list.at(i);
    if (max < list.at(i)) {
      max = list.at(i);
    }
  }
  sort((list).begin(), (list).end());
  reverse((list).begin(), (list).end());
  list2 = list;
  list3 = list;
  for (int i = 0; i < (int)(N); i++) {
    if (list2[i] == max) {
      list2.erase(list2.begin());
    }
  }
  int second = list2[0];
  for (int i = 0; i < (int)(N); i++) {
    if (max == list3[i]) {
      cout << second << endl;
    } else {
      cout << max << endl;
    }
  }
}
