#include <bits/stdc++.h>
using namespace std;
int a, b, c, d, e, f, g, h, n;
vector<int> x;
set<long long int> se;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    scanf("%d", &a);
    x.push_back(a);
    se.insert(a);
  }
  d = *max_element(x.begin(), x.end());
  auto it = se.end();
  it--;
  it--;
  long long int k = *it;
  for (int i = 0; i < n; i++) {
    if (x[i] != d) {
      cout << d << endl;
    } else {
      cout << k << endl;
    }
  }
}
