#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;

int main(){
    int N;
    cin >> N;
    vector<int> A(N);
    for (int i = 0; i < N;i++){
        cin >> A[i];
    }

    int max_value = *max_element(A.begin(), A.end());
    int max_index = *max_index(A.begin(), A.end());
    A[max_index] = 0;
    int smax_value = *max_element(A.begin(), A.end());
    int smax_index = *max_index(A.begin(), A.end());
    A[max_index] = max_value;

    for (int i = 0; i < N;i++){
        if(A[i] == max_value){
            cout << smax_value << endl;
        }else{
        cout << max_value << endl;
        }
    }
    return 0;
}