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