#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
int n, ans, temp, max1, max2;
bool same = true;
int main() {
  cin >> n;
  vector<int> a(n);
  for (int i = 0; i < (n); ++i) {
    cin >> a[i];
  }
  max1 = 0;
  max2 = 0;
  for (int i = 0; i < (n); ++i) {
    max1 = max(max1, a[i]);
  }
  for (int i = 0; i < (n); ++i) {
    if (a[i] != max1) {
      max2 = max(max2, a[i]);
      same = false;
    }
  }
  if (same) max2 = max1;
  for (int i = 0; i < (n); ++i) {
    cout << (a[i] == max1 ? max2 : max1) << endl;
  }
  return 0;
}
