#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds ;
#define ll int
#define ld long double
#define rep(i,a,b) for(ll i=a;i<b;i+=1)
#define all(c) (c).begin(),(c).end()
#define pb push_back
#define sz(a) int((a).size())
#define hell (ll)998244353
#define f first
#define s second
#define sll(x) scanf("%lld",&x)
#define si(x) scanf("%d",&x)
typedef tree< ll , null_type , less<ll> , rb_tree_tag , tree_order_statistics_node_update > ordered_set ;
ll t = 1 ;
void solve()
{
    ll n; 
    cin >> n ;
    vector<ll> v(n) ;
    multiset<ll> seta ;
    rep( i , 0 , n )
    {
        cin >> v[i] ;
        seta.insert(v[i]);
    }
    rep( i , 0 , n )
    {
        seta.erase(seta.find(v[i]));
        cout << *prev(seta.end()) << '\n' ;
        seta.insert(v[i]);
    }
}
signed main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    //cin>>t;
    while(t--)
        solve() ;
    return 0 ;
}

