int main() {
    int N, a = -1, b = -1;
    cin >> N;
    vector<int> A(N, 0), B(200000, 0);
    
    for (int i = 0; i < N; i++) cin >> A[i];
    for (int i = 0; i < N; i++) ++B[A[i]];
    for (int i = 200000; i > 0; i--) {
        if (B[i] > 0 && a < 0) {
            a = i;
        }
        else if (B[i] > 0 && a >= 0) {
            b = i; break;
        }
    }

    for (int i = 0; i < N; i++) {
        if (A[i] != a)  cout << a << endl;
        else if (B[a] > 1) cout << a << endl;
        else cout << b << endl;
    }
}