#include <iostream>
#include <algorithm>

using namespace std;

int main() {
    int N;
    cin >> N;
    int A[N], S[N];
    for (int i = 0; i < N; ++i) {
        cin >> A[i];
        S[i] = A[i];
    }
    sort(S, S + N);
    for (int i = 0; i < N; ++i) cout << (A[i] == S[N - 1] ? S[N - 2] : S[N - 1]) << endl;
}
