import java.util.Scanner;

public class Main {
    private static final int MOD = 1_000_000_007;
    private static final String YES = "YES";
    private static final String NO = "NO";

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

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

        int[] ans = solve(N, A);
        for (int i=0; i<N; i++) {
            System.out.println(ans[i]);
        }
    }

    private static int[] solve(int N, int[] A) {
        int[] ans = new int[N];

        int max =  Math.max(A[0], A[1]);
        int max2 = Math.min(A[0], A[1]);

        for (int i=2; i<N; i++) {
            if (A[i] >= max) {
                max2 = max;
                max = A[i];
            } else if (A[i] >= max2) {
                max2 = A[i];
            }
        }

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

        return ans;
    }
} import java.util.Scanner; Scanner java.util public class Main {
    private static final int MOD = 1_000_000_007;
    private static final String YES = "YES";
    private static final String NO = "NO";

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

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

        int[] ans = solve(N, A);
        for (int i=0; i<N; i++) {
            System.out.println(ans[i]);
        }
    }

    private static int[] solve(int N, int[] A) {
        int[] ans = new int[N];

        int max =  Math.max(A[0], A[1]);
        int max2 = Math.min(A[0], A[1]);

        for (int i=2; i<N; i++) {
            if (A[i] >= max) {
                max2 = max;
                max = A[i];
            } else if (A[i] >= max2) {
                max2 = A[i];
            }
        }

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

        return ans;
    }
} Main private static final int MOD = 1_000_000_007; MOD 1_000_000_007 private static final String YES = "YES"; YES "YES" private static final String NO = "NO"; NO "NO" public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

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

        int[] ans = solve(N, A);
        for (int i=0; i<N; i++) {
            System.out.println(ans[i]);
        }
    } main {
        Scanner sc = new Scanner(System.in);

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

        int[] ans = solve(N, A);
        for (int i=0; i<N; i++) {
            System.out.println(ans[i]);
        }
    } 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 for (int i=0; i<N; i++) {
            A[i] = sc.nextInt();
        } int i=0; int i=0; i 0 i<N i N i++ i++ i {
            A[i] = sc.nextInt();
        } {
            A[i] = sc.nextInt();
        } A[i] = sc.nextInt() A[i] A i sc.nextInt() sc.nextInt sc int[] ans = solve(N, A); ans solve(N, A) solve N A for (int i=0; i<N; i++) {
            System.out.println(ans[i]);
        } int i=0; int i=0; i 0 i<N i N i++ i++ i {
            System.out.println(ans[i]);
        } {
            System.out.println(ans[i]);
        } System.out.println(ans[i]) System.out.println System.out System System.out ans[i] ans i String[] args args private static int[] solve(int N, int[] A) {
        int[] ans = new int[N];

        int max =  Math.max(A[0], A[1]);
        int max2 = Math.min(A[0], A[1]);

        for (int i=2; i<N; i++) {
            if (A[i] >= max) {
                max2 = max;
                max = A[i];
            } else if (A[i] >= max2) {
                max2 = A[i];
            }
        }

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

        return ans;
    } solve {
        int[] ans = new int[N];

        int max =  Math.max(A[0], A[1]);
        int max2 = Math.min(A[0], A[1]);

        for (int i=2; i<N; i++) {
            if (A[i] >= max) {
                max2 = max;
                max = A[i];
            } else if (A[i] >= max2) {
                max2 = A[i];
            }
        }

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

        return ans;
    } int[] ans = new int[N]; ans new int[N] N int max =  Math.max(A[0], A[1]); max Math.max(A[0], A[1]) Math.max Math A[0] A 0 A[1] A 1 int max2 = Math.min(A[0], A[1]); max2 Math.min(A[0], A[1]) Math.min Math A[0] A 0 A[1] A 1 for (int i=2; i<N; i++) {
            if (A[i] >= max) {
                max2 = 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 {
            if (A[i] >= max) {
                max2 = max;
                max = A[i];
            } else if (A[i] >= max2) {
                max2 = A[i];
            }
        } {
            if (A[i] >= max) {
                max2 = max;
                max = A[i];
            } else if (A[i] >= max2) {
                max2 = A[i];
            }
        } if (A[i] >= max) {
                max2 = max;
                max = A[i];
            } else if (A[i] >= max2) {
                max2 = A[i];
            } A[i] >= max A[i] A i max {
                max2 = max;
                max = A[i];
            } max2 = max max2 max 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) {
                ans[i] = max2;
            } else {
                ans[i] = max;
            }
        } int i=0; int i=0; i 0 i<N i N i++ i++ i {
            if (A[i] == max) {
                ans[i] = max2;
            } else {
                ans[i] = max;
            }
        } {
            if (A[i] == max) {
                ans[i] = max2;
            } else {
                ans[i] = max;
            }
        } if (A[i] == max) {
                ans[i] = max2;
            } else {
                ans[i] = max;
            } A[i] == max A[i] A i max {
                ans[i] = max2;
            } ans[i] = max2 ans[i] ans i max2 {
                ans[i] = max;
            } ans[i] = max ans[i] ans i max return ans; ans int N N int[] A A public class Main {
    private static final int MOD = 1_000_000_007;
    private static final String YES = "YES";
    private static final String NO = "NO";

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

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

        int[] ans = solve(N, A);
        for (int i=0; i<N; i++) {
            System.out.println(ans[i]);
        }
    }

    private static int[] solve(int N, int[] A) {
        int[] ans = new int[N];

        int max =  Math.max(A[0], A[1]);
        int max2 = Math.min(A[0], A[1]);

        for (int i=2; i<N; i++) {
            if (A[i] >= max) {
                max2 = max;
                max = A[i];
            } else if (A[i] >= max2) {
                max2 = A[i];
            }
        }

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

        return ans;
    }
} public class Main {
    private static final int MOD = 1_000_000_007;
    private static final String YES = "YES";
    private static final String NO = "NO";

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

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

        int[] ans = solve(N, A);
        for (int i=0; i<N; i++) {
            System.out.println(ans[i]);
        }
    }

    private static int[] solve(int N, int[] A) {
        int[] ans = new int[N];

        int max =  Math.max(A[0], A[1]);
        int max2 = Math.min(A[0], A[1]);

        for (int i=2; i<N; i++) {
            if (A[i] >= max) {
                max2 = max;
                max = A[i];
            } else if (A[i] >= max2) {
                max2 = A[i];
            }
        }

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

        return ans;
    }
} Main
import java.util.Scanner;

public class Main {
    private static final int MOD = 1_000_000_007;
    private static final String YES = "YES";
    private static final String NO = "NO";

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

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

        int[] ans = solve(N, A);
        for (int i=0; i<N; i++) {
            System.out.println(ans[i]);
        }
    }

    private static int[] solve(int N, int[] A) {
        int[] ans = new int[N];

        int max =  Math.max(A[0], A[1]);
        int max2 = Math.min(A[0], A[1]);

        for (int i=2; i<N; i++) {
            if (A[i] >= max) {
                max2 = max;
                max = A[i];
            } else if (A[i] >= max2) {
                max2 = A[i];
            }
        }

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

        return ans;
    }
}