import java.util.*;
import java.io.*;

public class Main {
    public static void main(String[] args) {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        int N;
        List<Integer> numbers = new ArrayList<>();
        try {
            N  = Integer.parseInt(br.readLine());
            for (int i=0; i<N; i++) {
                numbers.add(i, Integer.parseInt(br.readLine()));
            }
            int max = 0;
            int index = -1;
            for (int i=0; i<N; i++) {
                if (numbers.get(i) > max) {
                    max = numbers.get(i);
                    index = numbers.indexOf(max);
                }
            }
            int second = 0;
            int index2 = -1;
            for (int i=0; i<N; i++) {
                if (i != index && numbers.get(i) > second) {
                    second = numbers.get(i);
                    index2 = numbers.indexOf(second);
                }
            }
            if (max == second) {
                for (int i=0; i<N; i++) {
                    System.out.println(max);
                }
            }
            else {
                for (int i=0; i<N; i++) {
                    if (i == index) {
                        System.out.println(second);
                    }
                    else {
                        System.out.println(max);
                    }
                }
            }
        }
        catch(Exception e) {
        }
    }
} import java.util.*; util.* java import java.io.*; io.* java public class Main {
    public static void main(String[] args) {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        int N;
        List<Integer> numbers = new ArrayList<>();
        try {
            N  = Integer.parseInt(br.readLine());
            for (int i=0; i<N; i++) {
                numbers.add(i, Integer.parseInt(br.readLine()));
            }
            int max = 0;
            int index = -1;
            for (int i=0; i<N; i++) {
                if (numbers.get(i) > max) {
                    max = numbers.get(i);
                    index = numbers.indexOf(max);
                }
            }
            int second = 0;
            int index2 = -1;
            for (int i=0; i<N; i++) {
                if (i != index && numbers.get(i) > second) {
                    second = numbers.get(i);
                    index2 = numbers.indexOf(second);
                }
            }
            if (max == second) {
                for (int i=0; i<N; i++) {
                    System.out.println(max);
                }
            }
            else {
                for (int i=0; i<N; i++) {
                    if (i == index) {
                        System.out.println(second);
                    }
                    else {
                        System.out.println(max);
                    }
                }
            }
        }
        catch(Exception e) {
        }
    }
} Main public static void main(String[] args) {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        int N;
        List<Integer> numbers = new ArrayList<>();
        try {
            N  = Integer.parseInt(br.readLine());
            for (int i=0; i<N; i++) {
                numbers.add(i, Integer.parseInt(br.readLine()));
            }
            int max = 0;
            int index = -1;
            for (int i=0; i<N; i++) {
                if (numbers.get(i) > max) {
                    max = numbers.get(i);
                    index = numbers.indexOf(max);
                }
            }
            int second = 0;
            int index2 = -1;
            for (int i=0; i<N; i++) {
                if (i != index && numbers.get(i) > second) {
                    second = numbers.get(i);
                    index2 = numbers.indexOf(second);
                }
            }
            if (max == second) {
                for (int i=0; i<N; i++) {
                    System.out.println(max);
                }
            }
            else {
                for (int i=0; i<N; i++) {
                    if (i == index) {
                        System.out.println(second);
                    }
                    else {
                        System.out.println(max);
                    }
                }
            }
        }
        catch(Exception e) {
        }
    } main {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        int N;
        List<Integer> numbers = new ArrayList<>();
        try {
            N  = Integer.parseInt(br.readLine());
            for (int i=0; i<N; i++) {
                numbers.add(i, Integer.parseInt(br.readLine()));
            }
            int max = 0;
            int index = -1;
            for (int i=0; i<N; i++) {
                if (numbers.get(i) > max) {
                    max = numbers.get(i);
                    index = numbers.indexOf(max);
                }
            }
            int second = 0;
            int index2 = -1;
            for (int i=0; i<N; i++) {
                if (i != index && numbers.get(i) > second) {
                    second = numbers.get(i);
                    index2 = numbers.indexOf(second);
                }
            }
            if (max == second) {
                for (int i=0; i<N; i++) {
                    System.out.println(max);
                }
            }
            else {
                for (int i=0; i<N; i++) {
                    if (i == index) {
                        System.out.println(second);
                    }
                    else {
                        System.out.println(max);
                    }
                }
            }
        }
        catch(Exception e) {
        }
    } BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); br new BufferedReader(new InputStreamReader(System.in)) int N; N List<Integer> numbers = new ArrayList<>(); numbers new ArrayList<>() try {
            N  = Integer.parseInt(br.readLine());
            for (int i=0; i<N; i++) {
                numbers.add(i, Integer.parseInt(br.readLine()));
            }
            int max = 0;
            int index = -1;
            for (int i=0; i<N; i++) {
                if (numbers.get(i) > max) {
                    max = numbers.get(i);
                    index = numbers.indexOf(max);
                }
            }
            int second = 0;
            int index2 = -1;
            for (int i=0; i<N; i++) {
                if (i != index && numbers.get(i) > second) {
                    second = numbers.get(i);
                    index2 = numbers.indexOf(second);
                }
            }
            if (max == second) {
                for (int i=0; i<N; i++) {
                    System.out.println(max);
                }
            }
            else {
                for (int i=0; i<N; i++) {
                    if (i == index) {
                        System.out.println(second);
                    }
                    else {
                        System.out.println(max);
                    }
                }
            }
        }
        catch(Exception e) {
        } catch(Exception e) {
        } Exception e {
        } {
            N  = Integer.parseInt(br.readLine());
            for (int i=0; i<N; i++) {
                numbers.add(i, Integer.parseInt(br.readLine()));
            }
            int max = 0;
            int index = -1;
            for (int i=0; i<N; i++) {
                if (numbers.get(i) > max) {
                    max = numbers.get(i);
                    index = numbers.indexOf(max);
                }
            }
            int second = 0;
            int index2 = -1;
            for (int i=0; i<N; i++) {
                if (i != index && numbers.get(i) > second) {
                    second = numbers.get(i);
                    index2 = numbers.indexOf(second);
                }
            }
            if (max == second) {
                for (int i=0; i<N; i++) {
                    System.out.println(max);
                }
            }
            else {
                for (int i=0; i<N; i++) {
                    if (i == index) {
                        System.out.println(second);
                    }
                    else {
                        System.out.println(max);
                    }
                }
            }
        } N  = Integer.parseInt(br.readLine()) N Integer.parseInt(br.readLine()) Integer.parseInt Integer br.readLine() br.readLine br for (int i=0; i<N; i++) {
                numbers.add(i, Integer.parseInt(br.readLine()));
            } int i=0; int i=0; i 0 i<N i N i++ i++ i {
                numbers.add(i, Integer.parseInt(br.readLine()));
            } {
                numbers.add(i, Integer.parseInt(br.readLine()));
            } numbers.add(i, Integer.parseInt(br.readLine())) numbers.add numbers i Integer.parseInt(br.readLine()) Integer.parseInt Integer br.readLine() br.readLine br int max = 0; max 0 int index = -1; index -1 1 for (int i=0; i<N; i++) {
                if (numbers.get(i) > max) {
                    max = numbers.get(i);
                    index = numbers.indexOf(max);
                }
            } int i=0; int i=0; i 0 i<N i N i++ i++ i {
                if (numbers.get(i) > max) {
                    max = numbers.get(i);
                    index = numbers.indexOf(max);
                }
            } {
                if (numbers.get(i) > max) {
                    max = numbers.get(i);
                    index = numbers.indexOf(max);
                }
            } if (numbers.get(i) > max) {
                    max = numbers.get(i);
                    index = numbers.indexOf(max);
                } numbers.get(i) > max numbers.get(i) numbers.get numbers i max {
                    max = numbers.get(i);
                    index = numbers.indexOf(max);
                } max = numbers.get(i) max numbers.get(i) numbers.get numbers i index = numbers.indexOf(max) index numbers.indexOf(max) numbers.indexOf numbers max int second = 0; second 0 int index2 = -1; index2 -1 1 for (int i=0; i<N; i++) {
                if (i != index && numbers.get(i) > second) {
                    second = numbers.get(i);
                    index2 = numbers.indexOf(second);
                }
            } int i=0; int i=0; i 0 i<N i N i++ i++ i {
                if (i != index && numbers.get(i) > second) {
                    second = numbers.get(i);
                    index2 = numbers.indexOf(second);
                }
            } {
                if (i != index && numbers.get(i) > second) {
                    second = numbers.get(i);
                    index2 = numbers.indexOf(second);
                }
            } if (i != index && numbers.get(i) > second) {
                    second = numbers.get(i);
                    index2 = numbers.indexOf(second);
                } i != index && numbers.get(i) > second i != index i index numbers.get(i) > second numbers.get(i) numbers.get numbers i second {
                    second = numbers.get(i);
                    index2 = numbers.indexOf(second);
                } second = numbers.get(i) second numbers.get(i) numbers.get numbers i index2 = numbers.indexOf(second) index2 numbers.indexOf(second) numbers.indexOf numbers second if (max == second) {
                for (int i=0; i<N; i++) {
                    System.out.println(max);
                }
            }
            else {
                for (int i=0; i<N; i++) {
                    if (i == index) {
                        System.out.println(second);
                    }
                    else {
                        System.out.println(max);
                    }
                }
            } max == second max second {
                for (int i=0; i<N; i++) {
                    System.out.println(max);
                }
            } for (int i=0; i<N; i++) {
                    System.out.println(max);
                } int i=0; int i=0; i 0 i<N i N i++ i++ i {
                    System.out.println(max);
                } {
                    System.out.println(max);
                } System.out.println(max) System.out.println System.out System System.out max {
                for (int i=0; i<N; i++) {
                    if (i == index) {
                        System.out.println(second);
                    }
                    else {
                        System.out.println(max);
                    }
                }
            } for (int i=0; i<N; i++) {
                    if (i == index) {
                        System.out.println(second);
                    }
                    else {
                        System.out.println(max);
                    }
                } int i=0; int i=0; i 0 i<N i N i++ i++ i {
                    if (i == index) {
                        System.out.println(second);
                    }
                    else {
                        System.out.println(max);
                    }
                } {
                    if (i == index) {
                        System.out.println(second);
                    }
                    else {
                        System.out.println(max);
                    }
                } if (i == index) {
                        System.out.println(second);
                    }
                    else {
                        System.out.println(max);
                    } i == index i index {
                        System.out.println(second);
                    } System.out.println(second) System.out.println System.out System System.out second {
                        System.out.println(max);
                    } System.out.println(max) System.out.println System.out System System.out max String[] args args public class Main {
    public static void main(String[] args) {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        int N;
        List<Integer> numbers = new ArrayList<>();
        try {
            N  = Integer.parseInt(br.readLine());
            for (int i=0; i<N; i++) {
                numbers.add(i, Integer.parseInt(br.readLine()));
            }
            int max = 0;
            int index = -1;
            for (int i=0; i<N; i++) {
                if (numbers.get(i) > max) {
                    max = numbers.get(i);
                    index = numbers.indexOf(max);
                }
            }
            int second = 0;
            int index2 = -1;
            for (int i=0; i<N; i++) {
                if (i != index && numbers.get(i) > second) {
                    second = numbers.get(i);
                    index2 = numbers.indexOf(second);
                }
            }
            if (max == second) {
                for (int i=0; i<N; i++) {
                    System.out.println(max);
                }
            }
            else {
                for (int i=0; i<N; i++) {
                    if (i == index) {
                        System.out.println(second);
                    }
                    else {
                        System.out.println(max);
                    }
                }
            }
        }
        catch(Exception e) {
        }
    }
} public class Main {
    public static void main(String[] args) {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        int N;
        List<Integer> numbers = new ArrayList<>();
        try {
            N  = Integer.parseInt(br.readLine());
            for (int i=0; i<N; i++) {
                numbers.add(i, Integer.parseInt(br.readLine()));
            }
            int max = 0;
            int index = -1;
            for (int i=0; i<N; i++) {
                if (numbers.get(i) > max) {
                    max = numbers.get(i);
                    index = numbers.indexOf(max);
                }
            }
            int second = 0;
            int index2 = -1;
            for (int i=0; i<N; i++) {
                if (i != index && numbers.get(i) > second) {
                    second = numbers.get(i);
                    index2 = numbers.indexOf(second);
                }
            }
            if (max == second) {
                for (int i=0; i<N; i++) {
                    System.out.println(max);
                }
            }
            else {
                for (int i=0; i<N; i++) {
                    if (i == index) {
                        System.out.println(second);
                    }
                    else {
                        System.out.println(max);
                    }
                }
            }
        }
        catch(Exception e) {
        }
    }
} Main
import java.util.*;
import java.io.*;

public class Main {
    public static void main(String[] args) {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        int N;
        List<Integer> numbers = new ArrayList<>();
        try {
            N  = Integer.parseInt(br.readLine());
            for (int i=0; i<N; i++) {
                numbers.add(i, Integer.parseInt(br.readLine()));
            }
            int max = 0;
            int index = -1;
            for (int i=0; i<N; i++) {
                if (numbers.get(i) > max) {
                    max = numbers.get(i);
                    index = numbers.indexOf(max);
                }
            }
            int second = 0;
            int index2 = -1;
            for (int i=0; i<N; i++) {
                if (i != index && numbers.get(i) > second) {
                    second = numbers.get(i);
                    index2 = numbers.indexOf(second);
                }
            }
            if (max == second) {
                for (int i=0; i<N; i++) {
                    System.out.println(max);
                }
            }
            else {
                for (int i=0; i<N; i++) {
                    if (i == index) {
                        System.out.println(second);
                    }
                    else {
                        System.out.println(max);
                    }
                }
            }
        }
        catch(Exception e) {
        }
    }
}