#include <bits/stdc++.h>
using namespace std;
long double PI = 3.14159265358979323846;
const long long M = 1e12;
const long long inf = 1e18;
const long long ms = 10000000;
static int fastline = []() {
  std::ios::sync_with_stdio(false);
  cin.tie(NULL);
  return 0;
}();
;
long long ans, n, m;
void solve() {
  cin >> n;
  long long ar[n + 1], maxi = INT_MIN, maxi1 = INT_MIN;
  for (int i = 1; i <= n; i++) cin >> ar[i];
  for (int i = 1; i <= n; i++) maxi = max(maxi, ar[i]);
  for (int i = 1; i <= n; i++) {
    if (ar[i] != maxi) maxi1 = max(maxi1, ar[i]);
  }
  if (maxi1 == INT_MIN) maxi1 = maxi;
  for (int i = 1; i <= n; i++) {
    if (maxi == ar[i])
      cout << maxi1 << endl;
    else
      cout << maxi << endl;
  }
}
int main() {
  { solve(); }
  return 0;
}
