#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, cnt = 0;
  cin >> n;
  vector<int> A(n);
  for (int i = 0; i < n; i++) cin >> A[i];
  int maxval = *max_element(A.begin(), A.end());
  int maxval2 = A[0];
  for (int i = 1; i < n; i++) {
    if (A[i] == maxval) cnt++;
    if (A[i] != maxval) {
      maxval2 = max(maxval2, A[i]);
    }
  }
  vector<int> ans(n, maxval);
  if (cnt == 1) {
    int indx = max_element(A.begin(), A.end()) - A.begin();
    ans[indx] = maxval2;
  }
  for (int i = 0; i < n; i++) cout << ans[i] << endl;
}
