import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        int mx = -1;
        int mx2 = -1;
        int mxid = -1;
        for (int i = 0; i < n; i++) {
            int a = in.nextInt();
            if (a >= mx) {
                mx2 = mx;
                mx = a;
                mxid = i;
            } else if (a >= mx2) {
                mx2 = a;
            }
        }

        for (int i = 0; i < n; i++) {
            if (i == mxid) {
                System.out.println(mx2);
            } else {
                System.out.println(mx);
            }
        }
    }
} import java.util.Scanner; Scanner java.util public class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        int mx = -1;
        int mx2 = -1;
        int mxid = -1;
        for (int i = 0; i < n; i++) {
            int a = in.nextInt();
            if (a >= mx) {
                mx2 = mx;
                mx = a;
                mxid = i;
            } else if (a >= mx2) {
                mx2 = a;
            }
        }

        for (int i = 0; i < n; i++) {
            if (i == mxid) {
                System.out.println(mx2);
            } else {
                System.out.println(mx);
            }
        }
    }
} Main public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        int mx = -1;
        int mx2 = -1;
        int mxid = -1;
        for (int i = 0; i < n; i++) {
            int a = in.nextInt();
            if (a >= mx) {
                mx2 = mx;
                mx = a;
                mxid = i;
            } else if (a >= mx2) {
                mx2 = a;
            }
        }

        for (int i = 0; i < n; i++) {
            if (i == mxid) {
                System.out.println(mx2);
            } else {
                System.out.println(mx);
            }
        }
    } main {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        int mx = -1;
        int mx2 = -1;
        int mxid = -1;
        for (int i = 0; i < n; i++) {
            int a = in.nextInt();
            if (a >= mx) {
                mx2 = mx;
                mx = a;
                mxid = i;
            } else if (a >= mx2) {
                mx2 = a;
            }
        }

        for (int i = 0; i < n; i++) {
            if (i == mxid) {
                System.out.println(mx2);
            } else {
                System.out.println(mx);
            }
        }
    } Scanner in = new Scanner(System.in); in new Scanner(System.in) int n = in.nextInt(); n in.nextInt() in.nextInt in int mx = -1; mx -1 1 int mx2 = -1; mx2 -1 1 int mxid = -1; mxid -1 1 for (int i = 0; i < n; i++) {
            int a = in.nextInt();
            if (a >= mx) {
                mx2 = mx;
                mx = a;
                mxid = i;
            } else if (a >= mx2) {
                mx2 = a;
            }
        } int i = 0; int i = 0; i 0 i < n i n i++ i++ i {
            int a = in.nextInt();
            if (a >= mx) {
                mx2 = mx;
                mx = a;
                mxid = i;
            } else if (a >= mx2) {
                mx2 = a;
            }
        } {
            int a = in.nextInt();
            if (a >= mx) {
                mx2 = mx;
                mx = a;
                mxid = i;
            } else if (a >= mx2) {
                mx2 = a;
            }
        } int a = in.nextInt(); a in.nextInt() in.nextInt in if (a >= mx) {
                mx2 = mx;
                mx = a;
                mxid = i;
            } else if (a >= mx2) {
                mx2 = a;
            } a >= mx a mx {
                mx2 = mx;
                mx = a;
                mxid = i;
            } mx2 = mx mx2 mx mx = a mx a mxid = i mxid i if (a >= mx2) {
                mx2 = a;
            } a >= mx2 a mx2 {
                mx2 = a;
            } mx2 = a mx2 a for (int i = 0; i < n; i++) {
            if (i == mxid) {
                System.out.println(mx2);
            } else {
                System.out.println(mx);
            }
        } int i = 0; int i = 0; i 0 i < n i n i++ i++ i {
            if (i == mxid) {
                System.out.println(mx2);
            } else {
                System.out.println(mx);
            }
        } {
            if (i == mxid) {
                System.out.println(mx2);
            } else {
                System.out.println(mx);
            }
        } if (i == mxid) {
                System.out.println(mx2);
            } else {
                System.out.println(mx);
            } i == mxid i mxid {
                System.out.println(mx2);
            } System.out.println(mx2) System.out.println System.out System System.out mx2 {
                System.out.println(mx);
            } System.out.println(mx) System.out.println System.out System System.out mx String[] args args public class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        int mx = -1;
        int mx2 = -1;
        int mxid = -1;
        for (int i = 0; i < n; i++) {
            int a = in.nextInt();
            if (a >= mx) {
                mx2 = mx;
                mx = a;
                mxid = i;
            } else if (a >= mx2) {
                mx2 = a;
            }
        }

        for (int i = 0; i < n; i++) {
            if (i == mxid) {
                System.out.println(mx2);
            } else {
                System.out.println(mx);
            }
        }
    }
} public class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        int mx = -1;
        int mx2 = -1;
        int mxid = -1;
        for (int i = 0; i < n; i++) {
            int a = in.nextInt();
            if (a >= mx) {
                mx2 = mx;
                mx = a;
                mxid = i;
            } else if (a >= mx2) {
                mx2 = a;
            }
        }

        for (int i = 0; i < n; i++) {
            if (i == mxid) {
                System.out.println(mx2);
            } else {
                System.out.println(mx);
            }
        }
    }
} Main
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        int mx = -1;
        int mx2 = -1;
        int mxid = -1;
        for (int i = 0; i < n; i++) {
            int a = in.nextInt();
            if (a >= mx) {
                mx2 = mx;
                mx = a;
                mxid = i;
            } else if (a >= mx2) {
                mx2 = a;
            }
        }

        for (int i = 0; i < n; i++) {
            if (i == mxid) {
                System.out.println(mx2);
            } else {
                System.out.println(mx);
            }
        }
    }
}