#include <bits/stdc++.h>
using namespace std;
void data() {}
const int N = 5e5 + 100;
const long long mod = 1e9 + 7;
int main() {
  data();
  int n;
  cin >> n;
  int a[n + 1];
  int mx = 0;
  int kol = 0;
  set<int> second;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
    mx = max(mx, a[i]);
    second.insert(a[i]);
  }
  second.erase(*second.rbegin());
  int ans2 = *second.rbegin();
  for (int i = 1; i <= n; i++) {
    if (mx == a[i]) {
      kol++;
    }
  }
  for (int i = 1; i <= n; i++) {
    if (a[i] != mx) {
      cout << mx << '\n';
      continue;
    }
    if (kol > 1) {
      cout << mx << '\n';
      continue;
    }
    cout << ans2 << '\n';
  }
}
