import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = Integer.parseInt(sc.next());
        int maxValue = 0;
        int maxIndex = 0;
        int secondMaxValue = 0;
        for (int i = 0; i < N; i++) {
            int tmp = Integer.parseInt(sc.next());
            if (tmp > maxValue) {
                maxValue = tmp;
                maxIndex = i;
            } else if (tmp > secondMaxValue) {
                secondMaxValue = tmp;
            }
        }

        StringBuilder builder = new StringBuilder();
        for (int i = 0; i < N; i++) {
            if (i == maxIndex) {
                builder.append(secondMaxValue);
            } else {
                builder.append(maxValue);
            }
            builder.append("\n");
        }

        System.out.println(builder.toString());
    }
} import java.util.Scanner; Scanner java.util public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = Integer.parseInt(sc.next());
        int maxValue = 0;
        int maxIndex = 0;
        int secondMaxValue = 0;
        for (int i = 0; i < N; i++) {
            int tmp = Integer.parseInt(sc.next());
            if (tmp > maxValue) {
                maxValue = tmp;
                maxIndex = i;
            } else if (tmp > secondMaxValue) {
                secondMaxValue = tmp;
            }
        }

        StringBuilder builder = new StringBuilder();
        for (int i = 0; i < N; i++) {
            if (i == maxIndex) {
                builder.append(secondMaxValue);
            } else {
                builder.append(maxValue);
            }
            builder.append("\n");
        }

        System.out.println(builder.toString());
    }
} Main public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = Integer.parseInt(sc.next());
        int maxValue = 0;
        int maxIndex = 0;
        int secondMaxValue = 0;
        for (int i = 0; i < N; i++) {
            int tmp = Integer.parseInt(sc.next());
            if (tmp > maxValue) {
                maxValue = tmp;
                maxIndex = i;
            } else if (tmp > secondMaxValue) {
                secondMaxValue = tmp;
            }
        }

        StringBuilder builder = new StringBuilder();
        for (int i = 0; i < N; i++) {
            if (i == maxIndex) {
                builder.append(secondMaxValue);
            } else {
                builder.append(maxValue);
            }
            builder.append("\n");
        }

        System.out.println(builder.toString());
    } main {
        Scanner sc = new Scanner(System.in);
        int N = Integer.parseInt(sc.next());
        int maxValue = 0;
        int maxIndex = 0;
        int secondMaxValue = 0;
        for (int i = 0; i < N; i++) {
            int tmp = Integer.parseInt(sc.next());
            if (tmp > maxValue) {
                maxValue = tmp;
                maxIndex = i;
            } else if (tmp > secondMaxValue) {
                secondMaxValue = tmp;
            }
        }

        StringBuilder builder = new StringBuilder();
        for (int i = 0; i < N; i++) {
            if (i == maxIndex) {
                builder.append(secondMaxValue);
            } else {
                builder.append(maxValue);
            }
            builder.append("\n");
        }

        System.out.println(builder.toString());
    } Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int N = Integer.parseInt(sc.next()); N Integer.parseInt(sc.next()) Integer.parseInt Integer sc.next() sc.next sc int maxValue = 0; maxValue 0 int maxIndex = 0; maxIndex 0 int secondMaxValue = 0; secondMaxValue 0 for (int i = 0; i < N; i++) {
            int tmp = Integer.parseInt(sc.next());
            if (tmp > maxValue) {
                maxValue = tmp;
                maxIndex = i;
            } else if (tmp > secondMaxValue) {
                secondMaxValue = tmp;
            }
        } int i = 0; int i = 0; i 0 i < N i N i++ i++ i {
            int tmp = Integer.parseInt(sc.next());
            if (tmp > maxValue) {
                maxValue = tmp;
                maxIndex = i;
            } else if (tmp > secondMaxValue) {
                secondMaxValue = tmp;
            }
        } {
            int tmp = Integer.parseInt(sc.next());
            if (tmp > maxValue) {
                maxValue = tmp;
                maxIndex = i;
            } else if (tmp > secondMaxValue) {
                secondMaxValue = tmp;
            }
        } int tmp = Integer.parseInt(sc.next()); tmp Integer.parseInt(sc.next()) Integer.parseInt Integer sc.next() sc.next sc if (tmp > maxValue) {
                maxValue = tmp;
                maxIndex = i;
            } else if (tmp > secondMaxValue) {
                secondMaxValue = tmp;
            } tmp > maxValue tmp maxValue {
                maxValue = tmp;
                maxIndex = i;
            } maxValue = tmp maxValue tmp maxIndex = i maxIndex i if (tmp > secondMaxValue) {
                secondMaxValue = tmp;
            } tmp > secondMaxValue tmp secondMaxValue {
                secondMaxValue = tmp;
            } secondMaxValue = tmp secondMaxValue tmp StringBuilder builder = new StringBuilder(); builder new StringBuilder() for (int i = 0; i < N; i++) {
            if (i == maxIndex) {
                builder.append(secondMaxValue);
            } else {
                builder.append(maxValue);
            }
            builder.append("\n");
        } int i = 0; int i = 0; i 0 i < N i N i++ i++ i {
            if (i == maxIndex) {
                builder.append(secondMaxValue);
            } else {
                builder.append(maxValue);
            }
            builder.append("\n");
        } {
            if (i == maxIndex) {
                builder.append(secondMaxValue);
            } else {
                builder.append(maxValue);
            }
            builder.append("\n");
        } if (i == maxIndex) {
                builder.append(secondMaxValue);
            } else {
                builder.append(maxValue);
            } i == maxIndex i maxIndex {
                builder.append(secondMaxValue);
            } builder.append(secondMaxValue) builder.append builder secondMaxValue {
                builder.append(maxValue);
            } builder.append(maxValue) builder.append builder maxValue builder.append("\n") builder.append builder "\n" System.out.println(builder.toString()) System.out.println System.out System System.out builder.toString() builder.toString builder String[] args args public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = Integer.parseInt(sc.next());
        int maxValue = 0;
        int maxIndex = 0;
        int secondMaxValue = 0;
        for (int i = 0; i < N; i++) {
            int tmp = Integer.parseInt(sc.next());
            if (tmp > maxValue) {
                maxValue = tmp;
                maxIndex = i;
            } else if (tmp > secondMaxValue) {
                secondMaxValue = tmp;
            }
        }

        StringBuilder builder = new StringBuilder();
        for (int i = 0; i < N; i++) {
            if (i == maxIndex) {
                builder.append(secondMaxValue);
            } else {
                builder.append(maxValue);
            }
            builder.append("\n");
        }

        System.out.println(builder.toString());
    }
} public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = Integer.parseInt(sc.next());
        int maxValue = 0;
        int maxIndex = 0;
        int secondMaxValue = 0;
        for (int i = 0; i < N; i++) {
            int tmp = Integer.parseInt(sc.next());
            if (tmp > maxValue) {
                maxValue = tmp;
                maxIndex = i;
            } else if (tmp > secondMaxValue) {
                secondMaxValue = tmp;
            }
        }

        StringBuilder builder = new StringBuilder();
        for (int i = 0; i < N; i++) {
            if (i == maxIndex) {
                builder.append(secondMaxValue);
            } else {
                builder.append(maxValue);
            }
            builder.append("\n");
        }

        System.out.println(builder.toString());
    }
} Main
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = Integer.parseInt(sc.next());
        int maxValue = 0;
        int maxIndex = 0;
        int secondMaxValue = 0;
        for (int i = 0; i < N; i++) {
            int tmp = Integer.parseInt(sc.next());
            if (tmp > maxValue) {
                maxValue = tmp;
                maxIndex = i;
            } else if (tmp > secondMaxValue) {
                secondMaxValue = tmp;
            }
        }

        StringBuilder builder = new StringBuilder();
        for (int i = 0; i < N; i++) {
            if (i == maxIndex) {
                builder.append(secondMaxValue);
            } else {
                builder.append(maxValue);
            }
            builder.append("\n");
        }

        System.out.println(builder.toString());
    }
}