#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int n;
  cin >> n;
  valarray<int> a(n);
  for (int i = 0; i < n; ++i) {
    cin >> a[i];
  }
  valarray<int> b = a;
  int max1 = b.max();
  valarray<bool> m = b != max1;
  valarray<int> r = b[m];
  int max2 = r.size() == 0 ? max1 : r.max();
  for (int i = 0; i < n; ++i) {
    if (b[i] == max1) {
      cout << max2 << "\n";
    } else {
      cout << max1 << "\n";
    }
  }
}
