import java.util.*;

class Main {
    public static void main(String[] args) {
        new Solver().run();
    }
}

class Solver {

    public void run() {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int[] A = new int[N];

        int top1 = 0;
        int idx1 = 0;
        for (int i = 0; i < N; i++) {
            A[i] = sc.nextInt();
            if (top1 < A[i]) {
                top1 = A[i];
                idx1 = i;
            }
        }

        int top2 = 0;
        for (int i = 0; i < N; i++) {
            if (i != idx1  && top2 < A[i]) {
                top2 = A[i];
            }
        }

        long max = Integer.MIN_VALUE;
        for (int i = 0; i < N; i++) {
            if (A[i] == top1) {
                System.out.println(top2);
            } else {
                System.out.println(top1);
            }
        }

        return;
    }

} import java.util.*; util.* java class Main {
    public static void main(String[] args) {
        new Solver().run();
    }
} Main public static void main(String[] args) {
        new Solver().run();
    } main {
        new Solver().run();
    } new Solver().run() new Solver().run new Solver() String[] args args class Solver {

    public void run() {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int[] A = new int[N];

        int top1 = 0;
        int idx1 = 0;
        for (int i = 0; i < N; i++) {
            A[i] = sc.nextInt();
            if (top1 < A[i]) {
                top1 = A[i];
                idx1 = i;
            }
        }

        int top2 = 0;
        for (int i = 0; i < N; i++) {
            if (i != idx1  && top2 < A[i]) {
                top2 = A[i];
            }
        }

        long max = Integer.MIN_VALUE;
        for (int i = 0; i < N; i++) {
            if (A[i] == top1) {
                System.out.println(top2);
            } else {
                System.out.println(top1);
            }
        }

        return;
    }

} Solver public void run() {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int[] A = new int[N];

        int top1 = 0;
        int idx1 = 0;
        for (int i = 0; i < N; i++) {
            A[i] = sc.nextInt();
            if (top1 < A[i]) {
                top1 = A[i];
                idx1 = i;
            }
        }

        int top2 = 0;
        for (int i = 0; i < N; i++) {
            if (i != idx1  && top2 < A[i]) {
                top2 = A[i];
            }
        }

        long max = Integer.MIN_VALUE;
        for (int i = 0; i < N; i++) {
            if (A[i] == top1) {
                System.out.println(top2);
            } else {
                System.out.println(top1);
            }
        }

        return;
    } run {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int[] A = new int[N];

        int top1 = 0;
        int idx1 = 0;
        for (int i = 0; i < N; i++) {
            A[i] = sc.nextInt();
            if (top1 < A[i]) {
                top1 = A[i];
                idx1 = i;
            }
        }

        int top2 = 0;
        for (int i = 0; i < N; i++) {
            if (i != idx1  && top2 < A[i]) {
                top2 = A[i];
            }
        }

        long max = Integer.MIN_VALUE;
        for (int i = 0; i < N; i++) {
            if (A[i] == top1) {
                System.out.println(top2);
            } else {
                System.out.println(top1);
            }
        }

        return;
    } 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 top1 = 0; top1 0 int idx1 = 0; idx1 0 for (int i = 0; i < N; i++) {
            A[i] = sc.nextInt();
            if (top1 < A[i]) {
                top1 = A[i];
                idx1 = i;
            }
        } int i = 0; int i = 0; i 0 i < N i N i++ i++ i {
            A[i] = sc.nextInt();
            if (top1 < A[i]) {
                top1 = A[i];
                idx1 = i;
            }
        } {
            A[i] = sc.nextInt();
            if (top1 < A[i]) {
                top1 = A[i];
                idx1 = i;
            }
        } A[i] = sc.nextInt() A[i] A i sc.nextInt() sc.nextInt sc if (top1 < A[i]) {
                top1 = A[i];
                idx1 = i;
            } top1 < A[i] top1 A[i] A i {
                top1 = A[i];
                idx1 = i;
            } top1 = A[i] top1 A[i] A i idx1 = i idx1 i int top2 = 0; top2 0 for (int i = 0; i < N; i++) {
            if (i != idx1  && top2 < A[i]) {
                top2 = A[i];
            }
        } int i = 0; int i = 0; i 0 i < N i N i++ i++ i {
            if (i != idx1  && top2 < A[i]) {
                top2 = A[i];
            }
        } {
            if (i != idx1  && top2 < A[i]) {
                top2 = A[i];
            }
        } if (i != idx1  && top2 < A[i]) {
                top2 = A[i];
            } i != idx1  && top2 < A[i] i != idx1 i idx1 top2 < A[i] top2 A[i] A i {
                top2 = A[i];
            } top2 = A[i] top2 A[i] A i long max = Integer.MIN_VALUE; max Integer.MIN_VALUE Integer Integer.MIN_VALUE for (int i = 0; i < N; i++) {
            if (A[i] == top1) {
                System.out.println(top2);
            } else {
                System.out.println(top1);
            }
        } int i = 0; int i = 0; i 0 i < N i N i++ i++ i {
            if (A[i] == top1) {
                System.out.println(top2);
            } else {
                System.out.println(top1);
            }
        } {
            if (A[i] == top1) {
                System.out.println(top2);
            } else {
                System.out.println(top1);
            }
        } if (A[i] == top1) {
                System.out.println(top2);
            } else {
                System.out.println(top1);
            } A[i] == top1 A[i] A i top1 {
                System.out.println(top2);
            } System.out.println(top2) System.out.println System.out System System.out top2 {
                System.out.println(top1);
            } System.out.println(top1) System.out.println System.out System System.out top1 return;
import java.util.*;

class Main {
    public static void main(String[] args) {
        new Solver().run();
    }
}

class Solver {

    public void run() {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int[] A = new int[N];

        int top1 = 0;
        int idx1 = 0;
        for (int i = 0; i < N; i++) {
            A[i] = sc.nextInt();
            if (top1 < A[i]) {
                top1 = A[i];
                idx1 = i;
            }
        }

        int top2 = 0;
        for (int i = 0; i < N; i++) {
            if (i != idx1  && top2 < A[i]) {
                top2 = A[i];
            }
        }

        long max = Integer.MIN_VALUE;
        for (int i = 0; i < N; i++) {
            if (A[i] == top1) {
                System.out.println(top2);
            } else {
                System.out.println(top1);
            }
        }

        return;
    }

}