#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, max_int, second_max_int;
  cin >> n;
  vector<int> v_a(n);
  for (int i = 0; i < n; i++) cin >> v_a[i];
  max_int = *max_element(v_a.begin(), v_a.end());
  second_max_int = 0;
  for (int k = 0; k < n; k++) {
    if (v_a[k] != max_int) {
      second_max_int = max(v_a[k], second_max_int);
    }
  }
  for (int j = 0; j < n; j++) {
    if (v_a[j] != max_int) {
      cout << max_int << '\n';
    } else {
      cout << second_max_int << '\n';
    }
  }
  return 0;
}
