import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] a = new int[n];
        int[] b = new int[n];
        for (int i= 0;i < n;i++) {
            a[i] = sc.nextInt();
            b[i] = a[i];
        }

        Arrays.sort(b);
        int max1 = b[b.length - 1];
        int max2 = b[b.length - 2];
        for (int i = 0;i<n;i++) {
            if (a[i] == max1) {
                System.out.println(max2);
            } else {
                System.out.println(max1);
            }
        }

    }
} 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[] a = new int[n];
        int[] b = new int[n];
        for (int i= 0;i < n;i++) {
            a[i] = sc.nextInt();
            b[i] = a[i];
        }

        Arrays.sort(b);
        int max1 = b[b.length - 1];
        int max2 = b[b.length - 2];
        for (int i = 0;i<n;i++) {
            if (a[i] == max1) {
                System.out.println(max2);
            } else {
                System.out.println(max1);
            }
        }

    }
} Main public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] a = new int[n];
        int[] b = new int[n];
        for (int i= 0;i < n;i++) {
            a[i] = sc.nextInt();
            b[i] = a[i];
        }

        Arrays.sort(b);
        int max1 = b[b.length - 1];
        int max2 = b[b.length - 2];
        for (int i = 0;i<n;i++) {
            if (a[i] == max1) {
                System.out.println(max2);
            } else {
                System.out.println(max1);
            }
        }

    } main {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] a = new int[n];
        int[] b = new int[n];
        for (int i= 0;i < n;i++) {
            a[i] = sc.nextInt();
            b[i] = a[i];
        }

        Arrays.sort(b);
        int max1 = b[b.length - 1];
        int max2 = b[b.length - 2];
        for (int i = 0;i<n;i++) {
            if (a[i] == max1) {
                System.out.println(max2);
            } else {
                System.out.println(max1);
            }
        }

    } Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int n = sc.nextInt(); n sc.nextInt() sc.nextInt sc int[] a = new int[n]; a new int[n] n int[] b = new int[n]; b new int[n] n for (int i= 0;i < n;i++) {
            a[i] = sc.nextInt();
            b[i] = a[i];
        } int i= 0; int i= 0; i 0 i < n i n i++ i++ i {
            a[i] = sc.nextInt();
            b[i] = a[i];
        } {
            a[i] = sc.nextInt();
            b[i] = a[i];
        } a[i] = sc.nextInt() a[i] a i sc.nextInt() sc.nextInt sc b[i] = a[i] b[i] b i a[i] a i Arrays.sort(b) Arrays.sort Arrays b int max1 = b[b.length - 1]; max1 b[b.length - 1] b b.length - 1 b.length b b.length 1 int max2 = b[b.length - 2]; max2 b[b.length - 2] b b.length - 2 b.length b b.length 2 for (int i = 0;i<n;i++) {
            if (a[i] == max1) {
                System.out.println(max2);
            } else {
                System.out.println(max1);
            }
        } int i = 0; int i = 0; i 0 i<n i n i++ i++ i {
            if (a[i] == max1) {
                System.out.println(max2);
            } else {
                System.out.println(max1);
            }
        } {
            if (a[i] == max1) {
                System.out.println(max2);
            } else {
                System.out.println(max1);
            }
        } if (a[i] == max1) {
                System.out.println(max2);
            } else {
                System.out.println(max1);
            } a[i] == max1 a[i] a i max1 {
                System.out.println(max2);
            } System.out.println(max2) System.out.println System.out System System.out max2 {
                System.out.println(max1);
            } System.out.println(max1) System.out.println System.out System System.out max1 String[] args args public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] a = new int[n];
        int[] b = new int[n];
        for (int i= 0;i < n;i++) {
            a[i] = sc.nextInt();
            b[i] = a[i];
        }

        Arrays.sort(b);
        int max1 = b[b.length - 1];
        int max2 = b[b.length - 2];
        for (int i = 0;i<n;i++) {
            if (a[i] == max1) {
                System.out.println(max2);
            } else {
                System.out.println(max1);
            }
        }

    }
} public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] a = new int[n];
        int[] b = new int[n];
        for (int i= 0;i < n;i++) {
            a[i] = sc.nextInt();
            b[i] = a[i];
        }

        Arrays.sort(b);
        int max1 = b[b.length - 1];
        int max2 = b[b.length - 2];
        for (int i = 0;i<n;i++) {
            if (a[i] == max1) {
                System.out.println(max2);
            } else {
                System.out.println(max1);
            }
        }

    }
} Main
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] a = new int[n];
        int[] b = new int[n];
        for (int i= 0;i < n;i++) {
            a[i] = sc.nextInt();
            b[i] = a[i];
        }

        Arrays.sort(b);
        int max1 = b[b.length - 1];
        int max2 = b[b.length - 2];
        for (int i = 0;i<n;i++) {
            if (a[i] == max1) {
                System.out.println(max2);
            } else {
                System.out.println(max1);
            }
        }

    }
}