#include <bits/stdc++.h>
using namespace std;
long long INF = 1e18 + 10;
long long MOD = 1000000009;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int n;
  cin >> n;
  int a[n];
  int maxx = INT_MIN, maxx2 = INT_MIN, maxc = 0;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    maxx = max(maxx, a[i]);
  }
  for (int i = 0; i < n; i++) {
    if (a[i] != maxx)
      maxx2 = max(maxx2, a[i]);
    else
      maxc++;
  }
  for (int i = 0; i < n; i++)
    cout << ((a[i] == maxx && maxc == 1) ? maxx2 : maxx) << endl;
}
