import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int fast = -1;
        int fastIndex = -1;
        int second = -1;

        for (int i = 0; i < N; i++) {
            int n = sc.nextInt();
            if (fast <=  n) {
                second = fast;
                fast = n;
                fastIndex = i;
            } else if (second < n) {
                second = n;
            }
        }

        for (int i = 0; i < N; i++) {
            if (i == fastIndex) {
                System.out.println(second);
            } else {
                System.out.println(fast);
            }
        }

    }
} import java.util.*; util.* java public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int fast = -1;
        int fastIndex = -1;
        int second = -1;

        for (int i = 0; i < N; i++) {
            int n = sc.nextInt();
            if (fast <=  n) {
                second = fast;
                fast = n;
                fastIndex = i;
            } else if (second < n) {
                second = n;
            }
        }

        for (int i = 0; i < N; i++) {
            if (i == fastIndex) {
                System.out.println(second);
            } else {
                System.out.println(fast);
            }
        }

    }
} Main public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int fast = -1;
        int fastIndex = -1;
        int second = -1;

        for (int i = 0; i < N; i++) {
            int n = sc.nextInt();
            if (fast <=  n) {
                second = fast;
                fast = n;
                fastIndex = i;
            } else if (second < n) {
                second = n;
            }
        }

        for (int i = 0; i < N; i++) {
            if (i == fastIndex) {
                System.out.println(second);
            } else {
                System.out.println(fast);
            }
        }

    } main {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int fast = -1;
        int fastIndex = -1;
        int second = -1;

        for (int i = 0; i < N; i++) {
            int n = sc.nextInt();
            if (fast <=  n) {
                second = fast;
                fast = n;
                fastIndex = i;
            } else if (second < n) {
                second = n;
            }
        }

        for (int i = 0; i < N; i++) {
            if (i == fastIndex) {
                System.out.println(second);
            } else {
                System.out.println(fast);
            }
        }

    } Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int N = sc.nextInt(); N sc.nextInt() sc.nextInt sc int fast = -1; fast -1 1 int fastIndex = -1; fastIndex -1 1 int second = -1; second -1 1 for (int i = 0; i < N; i++) {
            int n = sc.nextInt();
            if (fast <=  n) {
                second = fast;
                fast = n;
                fastIndex = i;
            } else if (second < n) {
                second = n;
            }
        } int i = 0; int i = 0; i 0 i < N i N i++ i++ i {
            int n = sc.nextInt();
            if (fast <=  n) {
                second = fast;
                fast = n;
                fastIndex = i;
            } else if (second < n) {
                second = n;
            }
        } {
            int n = sc.nextInt();
            if (fast <=  n) {
                second = fast;
                fast = n;
                fastIndex = i;
            } else if (second < n) {
                second = n;
            }
        } int n = sc.nextInt(); n sc.nextInt() sc.nextInt sc if (fast <=  n) {
                second = fast;
                fast = n;
                fastIndex = i;
            } else if (second < n) {
                second = n;
            } fast <=  n fast n {
                second = fast;
                fast = n;
                fastIndex = i;
            } second = fast second fast fast = n fast n fastIndex = i fastIndex i if (second < n) {
                second = n;
            } second < n second n {
                second = n;
            } second = n second n for (int i = 0; i < N; i++) {
            if (i == fastIndex) {
                System.out.println(second);
            } else {
                System.out.println(fast);
            }
        } int i = 0; int i = 0; i 0 i < N i N i++ i++ i {
            if (i == fastIndex) {
                System.out.println(second);
            } else {
                System.out.println(fast);
            }
        } {
            if (i == fastIndex) {
                System.out.println(second);
            } else {
                System.out.println(fast);
            }
        } if (i == fastIndex) {
                System.out.println(second);
            } else {
                System.out.println(fast);
            } i == fastIndex i fastIndex {
                System.out.println(second);
            } System.out.println(second) System.out.println System.out System System.out second {
                System.out.println(fast);
            } System.out.println(fast) System.out.println System.out System System.out fast String[] args args public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int fast = -1;
        int fastIndex = -1;
        int second = -1;

        for (int i = 0; i < N; i++) {
            int n = sc.nextInt();
            if (fast <=  n) {
                second = fast;
                fast = n;
                fastIndex = i;
            } else if (second < n) {
                second = n;
            }
        }

        for (int i = 0; i < N; i++) {
            if (i == fastIndex) {
                System.out.println(second);
            } else {
                System.out.println(fast);
            }
        }

    }
} public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int fast = -1;
        int fastIndex = -1;
        int second = -1;

        for (int i = 0; i < N; i++) {
            int n = sc.nextInt();
            if (fast <=  n) {
                second = fast;
                fast = n;
                fastIndex = i;
            } else if (second < n) {
                second = n;
            }
        }

        for (int i = 0; i < N; i++) {
            if (i == fastIndex) {
                System.out.println(second);
            } else {
                System.out.println(fast);
            }
        }

    }
} Main
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int fast = -1;
        int fastIndex = -1;
        int second = -1;

        for (int i = 0; i < N; i++) {
            int n = sc.nextInt();
            if (fast <=  n) {
                second = fast;
                fast = n;
                fastIndex = i;
            } else if (second < n) {
                second = n;
            }
        }

        for (int i = 0; i < N; i++) {
            if (i == fastIndex) {
                System.out.println(second);
            } else {
                System.out.println(fast);
            }
        }

    }
}