import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Scanner;

public class Main {
    
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        List<Integer> list = new ArrayList<Integer>();
        List<Integer> lo = new ArrayList<Integer>();
        
        for (int i = 0; i < N; i++) {
            int t = sc.nextInt();
            list.add( t);
            lo.add( t);
        }
        Collections.sort(list);
        int max = list.get(N-1);
        int smax = -1;
        boolean fl_dmax = false;
        if(list.get(N-2) == max)    fl_dmax = true;
        for(int i=list.size()-1; i>=0; i--) {
            if(list.get(i) < max) {
                smax = list.get(i);
                break;
            }
        }

        for (int i = 0; i < lo.size(); i++) {
            if( lo.get(i) != max ) {
                System.out.println(max);
            }else{
                System.out.println( fl_dmax? max: smax );
            }
        }
    }
} import java.util.ArrayList; ArrayList java.util import java.util.Collections; Collections java.util import java.util.List; List java.util import java.util.Scanner; Scanner java.util public class Main {
    
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        List<Integer> list = new ArrayList<Integer>();
        List<Integer> lo = new ArrayList<Integer>();
        
        for (int i = 0; i < N; i++) {
            int t = sc.nextInt();
            list.add( t);
            lo.add( t);
        }
        Collections.sort(list);
        int max = list.get(N-1);
        int smax = -1;
        boolean fl_dmax = false;
        if(list.get(N-2) == max)    fl_dmax = true;
        for(int i=list.size()-1; i>=0; i--) {
            if(list.get(i) < max) {
                smax = list.get(i);
                break;
            }
        }

        for (int i = 0; i < lo.size(); i++) {
            if( lo.get(i) != max ) {
                System.out.println(max);
            }else{
                System.out.println( fl_dmax? max: smax );
            }
        }
    }
} Main public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        List<Integer> list = new ArrayList<Integer>();
        List<Integer> lo = new ArrayList<Integer>();
        
        for (int i = 0; i < N; i++) {
            int t = sc.nextInt();
            list.add( t);
            lo.add( t);
        }
        Collections.sort(list);
        int max = list.get(N-1);
        int smax = -1;
        boolean fl_dmax = false;
        if(list.get(N-2) == max)    fl_dmax = true;
        for(int i=list.size()-1; i>=0; i--) {
            if(list.get(i) < max) {
                smax = list.get(i);
                break;
            }
        }

        for (int i = 0; i < lo.size(); i++) {
            if( lo.get(i) != max ) {
                System.out.println(max);
            }else{
                System.out.println( fl_dmax? max: smax );
            }
        }
    } main {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        List<Integer> list = new ArrayList<Integer>();
        List<Integer> lo = new ArrayList<Integer>();
        
        for (int i = 0; i < N; i++) {
            int t = sc.nextInt();
            list.add( t);
            lo.add( t);
        }
        Collections.sort(list);
        int max = list.get(N-1);
        int smax = -1;
        boolean fl_dmax = false;
        if(list.get(N-2) == max)    fl_dmax = true;
        for(int i=list.size()-1; i>=0; i--) {
            if(list.get(i) < max) {
                smax = list.get(i);
                break;
            }
        }

        for (int i = 0; i < lo.size(); i++) {
            if( lo.get(i) != max ) {
                System.out.println(max);
            }else{
                System.out.println( fl_dmax? max: smax );
            }
        }
    } Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int N = sc.nextInt(); N sc.nextInt() sc.nextInt sc List<Integer> list = new ArrayList<Integer>(); list new ArrayList<Integer>() List<Integer> lo = new ArrayList<Integer>(); lo new ArrayList<Integer>() for (int i = 0; i < N; i++) {
            int t = sc.nextInt();
            list.add( t);
            lo.add( t);
        } int i = 0; int i = 0; i 0 i < N i N i++ i++ i {
            int t = sc.nextInt();
            list.add( t);
            lo.add( t);
        } {
            int t = sc.nextInt();
            list.add( t);
            lo.add( t);
        } int t = sc.nextInt(); t sc.nextInt() sc.nextInt sc list.add( t) list.add list t lo.add( t) lo.add lo t Collections.sort(list) Collections.sort Collections list int max = list.get(N-1); max list.get(N-1) list.get list N-1 N 1 int smax = -1; smax -1 1 boolean fl_dmax = false; fl_dmax false if(list.get(N-2) == max)    fl_dmax = true; list.get(N-2) == max list.get(N-2) list.get list N-2 N 2 max fl_dmax = true fl_dmax true for(int i=list.size()-1; i>=0; i--) {
            if(list.get(i) < max) {
                smax = list.get(i);
                break;
            }
        } int i=list.size()-1; int i=list.size()-1; i list.size()-1 list.size() list.size list 1 i>=0 i 0 i-- i-- i {
            if(list.get(i) < max) {
                smax = list.get(i);
                break;
            }
        } {
            if(list.get(i) < max) {
                smax = list.get(i);
                break;
            }
        } if(list.get(i) < max) {
                smax = list.get(i);
                break;
            } list.get(i) < max list.get(i) list.get list i max {
                smax = list.get(i);
                break;
            } smax = list.get(i) smax list.get(i) list.get list i break; for (int i = 0; i < lo.size(); i++) {
            if( lo.get(i) != max ) {
                System.out.println(max);
            }else{
                System.out.println( fl_dmax? max: smax );
            }
        } int i = 0; int i = 0; i 0 i < lo.size() i lo.size() lo.size lo i++ i++ i {
            if( lo.get(i) != max ) {
                System.out.println(max);
            }else{
                System.out.println( fl_dmax? max: smax );
            }
        } {
            if( lo.get(i) != max ) {
                System.out.println(max);
            }else{
                System.out.println( fl_dmax? max: smax );
            }
        } if( lo.get(i) != max ) {
                System.out.println(max);
            }else{
                System.out.println( fl_dmax? max: smax );
            } lo.get(i) != max lo.get(i) lo.get lo i max {
                System.out.println(max);
            } System.out.println(max) System.out.println System.out System System.out max {
                System.out.println( fl_dmax? max: smax );
            } System.out.println( fl_dmax? max: smax ) System.out.println System.out System System.out fl_dmax? max: smax fl_dmax max smax String[] args args public class Main {
    
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        List<Integer> list = new ArrayList<Integer>();
        List<Integer> lo = new ArrayList<Integer>();
        
        for (int i = 0; i < N; i++) {
            int t = sc.nextInt();
            list.add( t);
            lo.add( t);
        }
        Collections.sort(list);
        int max = list.get(N-1);
        int smax = -1;
        boolean fl_dmax = false;
        if(list.get(N-2) == max)    fl_dmax = true;
        for(int i=list.size()-1; i>=0; i--) {
            if(list.get(i) < max) {
                smax = list.get(i);
                break;
            }
        }

        for (int i = 0; i < lo.size(); i++) {
            if( lo.get(i) != max ) {
                System.out.println(max);
            }else{
                System.out.println( fl_dmax? max: smax );
            }
        }
    }
} public class Main {
    
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        List<Integer> list = new ArrayList<Integer>();
        List<Integer> lo = new ArrayList<Integer>();
        
        for (int i = 0; i < N; i++) {
            int t = sc.nextInt();
            list.add( t);
            lo.add( t);
        }
        Collections.sort(list);
        int max = list.get(N-1);
        int smax = -1;
        boolean fl_dmax = false;
        if(list.get(N-2) == max)    fl_dmax = true;
        for(int i=list.size()-1; i>=0; i--) {
            if(list.get(i) < max) {
                smax = list.get(i);
                break;
            }
        }

        for (int i = 0; i < lo.size(); i++) {
            if( lo.get(i) != max ) {
                System.out.println(max);
            }else{
                System.out.println( fl_dmax? max: smax );
            }
        }
    }
} Main
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Scanner;

public class Main {
    
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        List<Integer> list = new ArrayList<Integer>();
        List<Integer> lo = new ArrayList<Integer>();
        
        for (int i = 0; i < N; i++) {
            int t = sc.nextInt();
            list.add( t);
            lo.add( t);
        }
        Collections.sort(list);
        int max = list.get(N-1);
        int smax = -1;
        boolean fl_dmax = false;
        if(list.get(N-2) == max)    fl_dmax = true;
        for(int i=list.size()-1; i>=0; i--) {
            if(list.get(i) < max) {
                smax = list.get(i);
                break;
            }
        }

        for (int i = 0; i < lo.size(); i++) {
            if( lo.get(i) != max ) {
                System.out.println(max);
            }else{
                System.out.println( fl_dmax? max: smax );
            }
        }
    }
}
