#include <bits/stdc++.h>
using namespace std;
int N;
vector<int> A;
int main() {
  cin >> N;
  for (int i = 0; i < (N); ++i) {
    int tmp;
    cin >> tmp;
    A.push_back(tmp);
  }
  int max_value = 0;
  int max_count = 0;
  int second_value = 0;
  sort(A.rbegin(), A.rend());
  max_value = A[0];
  vector<int> A2(A.size());
  copy(A.begin(), A.end(), A2.begin());
  for (int i = 0; i < (N); ++i) {
    if (A[0] == A[i]) {
      max_count++;
    } else if (A[0] != A[i]) {
      second_value = A[i];
      break;
    }
  }
  for (int i = 0; i < (N); ++i) {
    if (max_count > 1) {
      cout << max_value << endl;
    } else {
      if (max_value == A2[i]) {
        cout << second_value << endl;
      } else {
        cout << max_value << endl;
      }
    }
  }
}
