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

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

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

        for (int i=0; i<N; i++) {
            if(A[i] == max) {
                System.out.println(max2);
            } else {
                System.out.println(max);
            }
        }
    } main {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int[] A = new int[N];
        A[0] = sc.nextInt();
        A[1] = sc.nextInt();
        int max;
        int max2;
        if (A[0] > A[1]) {
            max = A[0];
            max2 = A[1];
        } else if (A[0] < A[1]) {
            max = A[1];
            max2 = A[0];
        } else {
            max = A[0];
            max2 = A[0];
        }
        for(int i=2; i<N; i++){
            A[i] = sc.nextInt();
            if (A[i] > max) {
                max = A[i];
            } else if (A[i] > max2) {
                max2 = A[i];
            }
        }

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

        for (int i=0; i<N; i++) {
            if(A[i] == max) {
                System.out.println(max2);
            } else {
                System.out.println(max);
            }
        }
    }
} public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int[] A = new int[N];
        A[0] = sc.nextInt();
        A[1] = sc.nextInt();
        int max;
        int max2;
        if (A[0] > A[1]) {
            max = A[0];
            max2 = A[1];
        } else if (A[0] < A[1]) {
            max = A[1];
            max2 = A[0];
        } else {
            max = A[0];
            max2 = A[0];
        }
        for(int i=2; i<N; i++){
            A[i] = sc.nextInt();
            if (A[i] > max) {
                max = A[i];
            } else if (A[i] > max2) {
                max2 = A[i];
            }
        }

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

        for (int i=0; i<N; i++) {
            if(A[i] == max) {
                System.out.println(max2);
            } else {
                System.out.println(max);
            }
        }
    }
}