import java.util.*;

public class Main {
    public static void main(String[] args){
        Scanner s = new Scanner(System.in);
        int n=Integer.parseInt(s.nextLine());
        List<Integer> is = new ArrayList<Integer>();
        for(int i=0;i<n;i++){
            is.add(Integer.parseInt(s.nextLine()));
        }
        int m = Collections.max(is);
        int mi = is.indexOf(m);
        is.remove(is.indexOf(m));
        int m1 = Collections.max(is);
        for(int i=0;i<n;i++){
            if(i != mi){
                System.out.println(m);
                continue;
            }
            System.out.println(m1);
        }

    }
} import java.util.*; util.* java public class Main {
    public static void main(String[] args){
        Scanner s = new Scanner(System.in);
        int n=Integer.parseInt(s.nextLine());
        List<Integer> is = new ArrayList<Integer>();
        for(int i=0;i<n;i++){
            is.add(Integer.parseInt(s.nextLine()));
        }
        int m = Collections.max(is);
        int mi = is.indexOf(m);
        is.remove(is.indexOf(m));
        int m1 = Collections.max(is);
        for(int i=0;i<n;i++){
            if(i != mi){
                System.out.println(m);
                continue;
            }
            System.out.println(m1);
        }

    }
} Main public static void main(String[] args){
        Scanner s = new Scanner(System.in);
        int n=Integer.parseInt(s.nextLine());
        List<Integer> is = new ArrayList<Integer>();
        for(int i=0;i<n;i++){
            is.add(Integer.parseInt(s.nextLine()));
        }
        int m = Collections.max(is);
        int mi = is.indexOf(m);
        is.remove(is.indexOf(m));
        int m1 = Collections.max(is);
        for(int i=0;i<n;i++){
            if(i != mi){
                System.out.println(m);
                continue;
            }
            System.out.println(m1);
        }

    } main {
        Scanner s = new Scanner(System.in);
        int n=Integer.parseInt(s.nextLine());
        List<Integer> is = new ArrayList<Integer>();
        for(int i=0;i<n;i++){
            is.add(Integer.parseInt(s.nextLine()));
        }
        int m = Collections.max(is);
        int mi = is.indexOf(m);
        is.remove(is.indexOf(m));
        int m1 = Collections.max(is);
        for(int i=0;i<n;i++){
            if(i != mi){
                System.out.println(m);
                continue;
            }
            System.out.println(m1);
        }

    } Scanner s = new Scanner(System.in); s new Scanner(System.in) int n=Integer.parseInt(s.nextLine()); n Integer.parseInt(s.nextLine()) Integer.parseInt Integer s.nextLine() s.nextLine s List<Integer> is = new ArrayList<Integer>(); is new ArrayList<Integer>() for(int i=0;i<n;i++){
            is.add(Integer.parseInt(s.nextLine()));
        } int i=0; int i=0; i 0 i<n i n i++ i++ i {
            is.add(Integer.parseInt(s.nextLine()));
        } {
            is.add(Integer.parseInt(s.nextLine()));
        } is.add(Integer.parseInt(s.nextLine())) is.add is Integer.parseInt(s.nextLine()) Integer.parseInt Integer s.nextLine() s.nextLine s int m = Collections.max(is); m Collections.max(is) Collections.max Collections is int mi = is.indexOf(m); mi is.indexOf(m) is.indexOf is m is.remove(is.indexOf(m)) is.remove is is.indexOf(m) is.indexOf is m int m1 = Collections.max(is); m1 Collections.max(is) Collections.max Collections is for(int i=0;i<n;i++){
            if(i != mi){
                System.out.println(m);
                continue;
            }
            System.out.println(m1);
        } int i=0; int i=0; i 0 i<n i n i++ i++ i {
            if(i != mi){
                System.out.println(m);
                continue;
            }
            System.out.println(m1);
        } {
            if(i != mi){
                System.out.println(m);
                continue;
            }
            System.out.println(m1);
        } if(i != mi){
                System.out.println(m);
                continue;
            } i != mi i mi {
                System.out.println(m);
                continue;
            } System.out.println(m) System.out.println System.out System System.out m continue; System.out.println(m1) System.out.println System.out System System.out m1 String[] args args public class Main {
    public static void main(String[] args){
        Scanner s = new Scanner(System.in);
        int n=Integer.parseInt(s.nextLine());
        List<Integer> is = new ArrayList<Integer>();
        for(int i=0;i<n;i++){
            is.add(Integer.parseInt(s.nextLine()));
        }
        int m = Collections.max(is);
        int mi = is.indexOf(m);
        is.remove(is.indexOf(m));
        int m1 = Collections.max(is);
        for(int i=0;i<n;i++){
            if(i != mi){
                System.out.println(m);
                continue;
            }
            System.out.println(m1);
        }

    }
} public class Main {
    public static void main(String[] args){
        Scanner s = new Scanner(System.in);
        int n=Integer.parseInt(s.nextLine());
        List<Integer> is = new ArrayList<Integer>();
        for(int i=0;i<n;i++){
            is.add(Integer.parseInt(s.nextLine()));
        }
        int m = Collections.max(is);
        int mi = is.indexOf(m);
        is.remove(is.indexOf(m));
        int m1 = Collections.max(is);
        for(int i=0;i<n;i++){
            if(i != mi){
                System.out.println(m);
                continue;
            }
            System.out.println(m1);
        }

    }
} Main
import java.util.*;

public class Main {
    public static void main(String[] args){
        Scanner s = new Scanner(System.in);
        int n=Integer.parseInt(s.nextLine());
        List<Integer> is = new ArrayList<Integer>();
        for(int i=0;i<n;i++){
            is.add(Integer.parseInt(s.nextLine()));
        }
        int m = Collections.max(is);
        int mi = is.indexOf(m);
        is.remove(is.indexOf(m));
        int m1 = Collections.max(is);
        for(int i=0;i<n;i++){
            if(i != mi){
                System.out.println(m);
                continue;
            }
            System.out.println(m1);
        }

    }
}