#include<bits/stdc++.h>
using namespace std;
#define fi(i,a,b) for(int i=a;i<b;i++)
#define rfi(i,a,b) for(int i=a-1;i>=b;i--)
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);

typedef tree<int,null_type,less<int>,rb_tree_tag, tree_order_statistics_node_update> indexed_set;
typedef long long int lli;
typedef long double ld;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<long long, long long> pll;
typedef vector<int> vi;
typedef vector<long long> vll;
typedef vector<pair<int,int>> vp;
typedef pair<int,pair<int,int>> ddp;
typedef pair<long long,pll> ldp;

#define mp make_pair
#define eb emplace_back
#define pb push_back
#define all(v) v.begin(), v.end()
#define mod 1000000007
#define MAX 100000+5;

/* __A.v.i.n.a.s.h_._P.r.a.s.a.d__ */
/* __N.I.T_._D.U.R.G.A.P.U.R__ */
/* _K.e.E.p_._C.a.L.m_._A.n.D_._c.O.d.E_ */

int main()
    {
        fastio
        int n;
        cin >> n;
        int a[n];int maxm=0;
        for(int i=0;i<n;i++)
        {
            cin >> a[i];
            if(a[i]>maxm)
            maxm=a[i];
        }
        int max2=0;
        for(int i=0;i<n;i++)
        {
            if(a[i]!=maxm )
            {
            max2=a[i];
            break;
            }
        }
        for(int i=0;i<n;i++)
        {
            if(a[i]<maxm && a[i]>max2 )
            {
            max2=a[i];
            }
        }
         for(int i=0;i<n;i++)
        {
            if(a[i]==maxm)
            cout << max2 << endl;
            else
            cout << maxm << endl;
        }
        return 0;
    }