#include<bits/stdc++.h>

using namespace std;

int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  int max1 = 0, ind = 0;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    if (max1 < a[i]) {
      max1 = a[i];
      ind = i;
    }
  }
  a.erase(a.begin() + ind);
  for (int i = 0; i < n - 1; i++) {
     if (max2 < a[i]) max2 = a[i];
  }
  for (int i = 0; i < n; i++) {
    if (i != ind) cout << max1 << "\n";
    else cout << max2 << "\n";
  }
}  