#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define SZ(x) ((int)(x).size())
typedef long long ll;

typedef long double ld;
using namespace std;


int main() {
    ll N;
    cin>>N;
    ll A[N],B[N];
    REP(i,N){
        cin >>A[i];
        cout<<A[i]<<endl;
    }
    REP(i,N){
        int Max=0,Max2=0;
        Max=max_element(A[0],A[i-1]);
        Max2=max_element(A[i+1],A[N]);

        if(Max<Max2){
            cout<<Max2<<endl;
        }else{
            cout<<Max<<endl;
        }
    }

}
 