#include <bits/stdc++.h>
using namespace std;
long long gcd(long long x, long long y) { return y ? gcd(y, x % y) : x; }
int main() {
  int N;
  cin >> N;
  int A[N];
  int _max = 0;
  int _max2 = 0;
  for (int i = 0; i < (N); ++i) {
    cin >> A[i];
    _max = max(_max, A[i]);
    if (A[i] < _max) _max2 = max(_max2, A[i]);
  }
  int count = 0;
  for (int i = 0; i < (N); ++i) {
    if (A[i] == _max) count++;
  }
  for (int i = 0; i < (N); ++i) {
    int ans;
    if (count >= 2)
      ans = _max;
    else {
      if (A[i] == _max)
        ans = _max2;
      else
        ans = _max;
    }
    cout << ans << '\n';
  }
}
