import java.util.Scanner;

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

        for (int i = 0; i < n; i++) {
            if (max[0] == a[i])
                System.out.println(max[1]);
            else
                System.out.println(max[0]);
        }
    }
} import java.util.Scanner; Scanner 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[] max = new int[2];
        for (int i = 0; i < n; i++) {
            a[i] = sc.nextInt();
            if (max[0] <= a[i]) {
                max[1] = max[0];
                max[0] = a[i];
            } else if (max[1] < a[i]) {
                max[1] = a[i];
            }
        }

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

        int n = sc.nextInt();
        int[] a = new int[n];

        int[] max = new int[2];
        for (int i = 0; i < n; i++) {
            a[i] = sc.nextInt();
            if (max[0] <= a[i]) {
                max[1] = max[0];
                max[0] = a[i];
            } else if (max[1] < a[i]) {
                max[1] = a[i];
            }
        }

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

        int n = sc.nextInt();
        int[] a = new int[n];

        int[] max = new int[2];
        for (int i = 0; i < n; i++) {
            a[i] = sc.nextInt();
            if (max[0] <= a[i]) {
                max[1] = max[0];
                max[0] = a[i];
            } else if (max[1] < a[i]) {
                max[1] = a[i];
            }
        }

        for (int i = 0; i < n; i++) {
            if (max[0] == a[i])
                System.out.println(max[1]);
            else
                System.out.println(max[0]);
        }
    } 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[] max = new int[2]; max new int[2] 2 for (int i = 0; i < n; i++) {
            a[i] = sc.nextInt();
            if (max[0] <= a[i]) {
                max[1] = max[0];
                max[0] = a[i];
            } else if (max[1] < a[i]) {
                max[1] = a[i];
            }
        } int i = 0; int i = 0; i 0 i < n i n i++ i++ i {
            a[i] = sc.nextInt();
            if (max[0] <= a[i]) {
                max[1] = max[0];
                max[0] = a[i];
            } else if (max[1] < a[i]) {
                max[1] = a[i];
            }
        } {
            a[i] = sc.nextInt();
            if (max[0] <= a[i]) {
                max[1] = max[0];
                max[0] = a[i];
            } else if (max[1] < a[i]) {
                max[1] = a[i];
            }
        } a[i] = sc.nextInt() a[i] a i sc.nextInt() sc.nextInt sc if (max[0] <= a[i]) {
                max[1] = max[0];
                max[0] = a[i];
            } else if (max[1] < a[i]) {
                max[1] = a[i];
            } max[0] <= a[i] max[0] max 0 a[i] a i {
                max[1] = max[0];
                max[0] = a[i];
            } max[1] = max[0] max[1] max 1 max[0] max 0 max[0] = a[i] max[0] max 0 a[i] a i if (max[1] < a[i]) {
                max[1] = a[i];
            } max[1] < a[i] max[1] max 1 a[i] a i {
                max[1] = a[i];
            } max[1] = a[i] max[1] max 1 a[i] a i for (int i = 0; i < n; i++) {
            if (max[0] == a[i])
                System.out.println(max[1]);
            else
                System.out.println(max[0]);
        } int i = 0; int i = 0; i 0 i < n i n i++ i++ i {
            if (max[0] == a[i])
                System.out.println(max[1]);
            else
                System.out.println(max[0]);
        } {
            if (max[0] == a[i])
                System.out.println(max[1]);
            else
                System.out.println(max[0]);
        } if (max[0] == a[i])
                System.out.println(max[1]);
            else
                System.out.println(max[0]); max[0] == a[i] max[0] max 0 a[i] a i System.out.println(max[1]) System.out.println System.out System System.out max[1] max 1 System.out.println(max[0]) System.out.println System.out System System.out max[0] max 0 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[] max = new int[2];
        for (int i = 0; i < n; i++) {
            a[i] = sc.nextInt();
            if (max[0] <= a[i]) {
                max[1] = max[0];
                max[0] = a[i];
            } else if (max[1] < a[i]) {
                max[1] = a[i];
            }
        }

        for (int i = 0; i < n; i++) {
            if (max[0] == a[i])
                System.out.println(max[1]);
            else
                System.out.println(max[0]);
        }
    }
} 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[] max = new int[2];
        for (int i = 0; i < n; i++) {
            a[i] = sc.nextInt();
            if (max[0] <= a[i]) {
                max[1] = max[0];
                max[0] = a[i];
            } else if (max[1] < a[i]) {
                max[1] = a[i];
            }
        }

        for (int i = 0; i < n; i++) {
            if (max[0] == a[i])
                System.out.println(max[1]);
            else
                System.out.println(max[0]);
        }
    }
} Main
import java.util.Scanner;

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

        for (int i = 0; i < n; i++) {
            if (max[0] == a[i])
                System.out.println(max[1]);
            else
                System.out.println(max[0]);
        }
    }
}