#include<bits/stdc++.h>
using namespace std;
int n,a[200010],max1,max2;
int main()
{
    cin>>n;
    for(int i=1;i<=n;i++)
    {
        cin>>a[i];
        if(a[i]>=max1)max2=max1,max1=a[i];
        else if(a[i]>max2)max2=a[i];
    }
    for(int i=1;i<=n;i++)
        if(a[i]==max1)cout<<max2<<endl;else cout<<max1<<endl;
    return 0;
}#include<bits/stdc++.h>
using namespace std;
int n,a[200010],max1,max2;
int main()
{
    cin>>n;
    for(int i=1;i<=n;i++)
    {
        cin>>a[i];
        if(a[i]>=max1)max2=max1,max1=a[i];
        else if(a[i]>max2)max2=a[i];
    }
    for(int i=1;i<=n;i++)
        if(a[i]==max1)cout<<max2<<endl;else cout<<max1<<endl;
    return 0;
}