#include <bits/stdc++.h>
using namespace std;


int main()
{


    int n;
    cin>>n;

    vector<int> A(n);
    int max_wk=0;
    for(int i=0;i<n;i++){
        cin>>A.at(i);
        max_wk = max(max_wk,A.at(i));
    }

    int max_wk2=0;
    for(int i=0;i<n;i++){
        if(A.at(i)!=max_wk)
           max_wk2 = max(max_wk2,A.at(i));
    }

    for(int i=0;i<n;i++){
        if(max_wk!=A.at(i))
            cout<<max_wk<<endl;
        else
            cout<<max_wk2<<endl;
    }