#include <bits/stdc++.h>
using namespace std;
long long int gcd(long long int a, long long int b) {
  return b ? gcd(b, a % b) : a;
}
long long int lcm(long long int a, long long int b) {
  return (a / gcd(a, b)) * b;
}
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
template <class T>
bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T>
bool chmin(T &a, const T &b) {
  if (b < a) {
    a = b;
    return 1;
  }
  return 0;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  long long int N, max = 0, submax = -1, max_c = 0;
  cin >> N;
  long long int A[N];
  for (long long int i = 0, i_len = (N); i < i_len; i++) {
    cin >> A[i];
    if (A[i] > submax) {
      if (A[i] >= max) {
        if (A[i] != max) max_c = 0;
        max = A[i];
        max_c++;
      } else {
        submax = A[i];
      }
    }
  }
  for (long long int i = 0, i_len = (N); i < i_len; i++) {
    if (A[i] == max && max_c == 1) {
      cout << submax << endl;
    } else {
      cout << max << endl;
    }
  }
}
