#include <bits/stdc++.h>
using namespace std;
const int MOD = (int)1e9 + 7;
const int INF = (int)1e9;
const long long LINF = (long long)1e18;
const long double PI = acos((long double)-1);
const long double EPS = 1e-9;
void TimeExecution() {
  cout << "\n\n===>> Time Execution: " << clock() / (double)1000 << " sec(s).";
}
int n, prev;
int ma = 0;
int ma2 = 0;
int snt = 0;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cin >> n;
  int a[n + 1];
  for (int i = (1); i <= (n); i++) {
    cin >> a[i];
    if (ma < a[i]) ma = a[i];
    if ((ma2 < a[i] && a[i] < ma) || ma2 == 0) ma2 = a[i];
  }
  for (int i = (1); i <= (n); i++)
    if (a[i] == ma) snt++;
  if (snt > 1) ma2 = ma;
  for (int i = (1); i <= (n); i++) {
    if (a[i] != ma)
      cout << ma;
    else
      cout << ma2;
    cout << "\n";
  }
  return 0;
}
