import java.util.*;

class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        int N = sc.nextInt();
        int[] As = new int[N];
        int[] sortedAs = new int[N];
        for (int i=0; i<N; i++) {
            As[i] = sc.nextInt();
        }

        System.arraycopy(As, 0, sortedAs, 0, As.length);
        Arrays.sort(sortedAs);
        

        int max = sortedAs[N-1];
        
        if (max == sortedAs[N-2]) {
            for (int i=0; i<N; i++) {
                System.out.println(max);
            }
        } else {
            for (int a : As) {
                if (a == max) {
                    System.out.println(sortedAs[N-2]);
                } else {
                    System.out.println(max);
                }
            }
        }
    }
}
 import java.util.*; util.* java class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        int N = sc.nextInt();
        int[] As = new int[N];
        int[] sortedAs = new int[N];
        for (int i=0; i<N; i++) {
            As[i] = sc.nextInt();
        }

        System.arraycopy(As, 0, sortedAs, 0, As.length);
        Arrays.sort(sortedAs);
        

        int max = sortedAs[N-1];
        
        if (max == sortedAs[N-2]) {
            for (int i=0; i<N; i++) {
                System.out.println(max);
            }
        } else {
            for (int a : As) {
                if (a == max) {
                    System.out.println(sortedAs[N-2]);
                } else {
                    System.out.println(max);
                }
            }
        }
    }
} Main public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        int N = sc.nextInt();
        int[] As = new int[N];
        int[] sortedAs = new int[N];
        for (int i=0; i<N; i++) {
            As[i] = sc.nextInt();
        }

        System.arraycopy(As, 0, sortedAs, 0, As.length);
        Arrays.sort(sortedAs);
        

        int max = sortedAs[N-1];
        
        if (max == sortedAs[N-2]) {
            for (int i=0; i<N; i++) {
                System.out.println(max);
            }
        } else {
            for (int a : As) {
                if (a == max) {
                    System.out.println(sortedAs[N-2]);
                } else {
                    System.out.println(max);
                }
            }
        }
    } main {
        Scanner sc = new Scanner(System.in);

        int N = sc.nextInt();
        int[] As = new int[N];
        int[] sortedAs = new int[N];
        for (int i=0; i<N; i++) {
            As[i] = sc.nextInt();
        }

        System.arraycopy(As, 0, sortedAs, 0, As.length);
        Arrays.sort(sortedAs);
        

        int max = sortedAs[N-1];
        
        if (max == sortedAs[N-2]) {
            for (int i=0; i<N; i++) {
                System.out.println(max);
            }
        } else {
            for (int a : As) {
                if (a == max) {
                    System.out.println(sortedAs[N-2]);
                } else {
                    System.out.println(max);
                }
            }
        }
    } Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int N = sc.nextInt(); N sc.nextInt() sc.nextInt sc int[] As = new int[N]; As new int[N] N int[] sortedAs = new int[N]; sortedAs new int[N] N for (int i=0; i<N; i++) {
            As[i] = sc.nextInt();
        } int i=0; int i=0; i 0 i<N i N i++ i++ i {
            As[i] = sc.nextInt();
        } {
            As[i] = sc.nextInt();
        } As[i] = sc.nextInt() As[i] As i sc.nextInt() sc.nextInt sc System.arraycopy(As, 0, sortedAs, 0, As.length) System.arraycopy System As 0 sortedAs 0 As.length As As.length Arrays.sort(sortedAs) Arrays.sort Arrays sortedAs int max = sortedAs[N-1]; max sortedAs[N-1] sortedAs N-1 N 1 if (max == sortedAs[N-2]) {
            for (int i=0; i<N; i++) {
                System.out.println(max);
            }
        } else {
            for (int a : As) {
                if (a == max) {
                    System.out.println(sortedAs[N-2]);
                } else {
                    System.out.println(max);
                }
            }
        } max == sortedAs[N-2] max sortedAs[N-2] sortedAs N-2 N 2 {
            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 a : As) {
                if (a == max) {
                    System.out.println(sortedAs[N-2]);
                } else {
                    System.out.println(max);
                }
            }
        } for (int a : As) {
                if (a == max) {
                    System.out.println(sortedAs[N-2]);
                } else {
                    System.out.println(max);
                }
            } int a As {
                if (a == max) {
                    System.out.println(sortedAs[N-2]);
                } else {
                    System.out.println(max);
                }
            } {
                if (a == max) {
                    System.out.println(sortedAs[N-2]);
                } else {
                    System.out.println(max);
                }
            } if (a == max) {
                    System.out.println(sortedAs[N-2]);
                } else {
                    System.out.println(max);
                } a == max a max {
                    System.out.println(sortedAs[N-2]);
                } System.out.println(sortedAs[N-2]) System.out.println System.out System System.out sortedAs[N-2] sortedAs N-2 N 2 {
                    System.out.println(max);
                } System.out.println(max) System.out.println System.out System System.out max String[] args args
import java.util.*;

class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        int N = sc.nextInt();
        int[] As = new int[N];
        int[] sortedAs = new int[N];
        for (int i=0; i<N; i++) {
            As[i] = sc.nextInt();
        }

        System.arraycopy(As, 0, sortedAs, 0, As.length);
        Arrays.sort(sortedAs);
        

        int max = sortedAs[N-1];
        
        if (max == sortedAs[N-2]) {
            for (int i=0; i<N; i++) {
                System.out.println(max);
            }
        } else {
            for (int a : As) {
                if (a == max) {
                    System.out.println(sortedAs[N-2]);
                } else {
                    System.out.println(max);
                }
            }
        }
    }
}

