import java.util.*;
import java.lang.*;

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 = 0, second = 0;
        for (int i = 0; i < n; i++) {
            a[i] = sc.nextInt();
            if (max <= a[i]) {
                second = max;
                max = a[i];
            } else if (second < a[i]) {
                second = a[i];
            }
        }
        
        for (int i = 0; i < n; i++) {
            if (a[i] != max) {
                System.out.println(max);
            } else {
                System.out.println(second);
            }
        }
    }
} import java.util.*; util.* java import java.lang.*; lang.* 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 max = 0, second = 0;
        for (int i = 0; i < n; i++) {
            a[i] = sc.nextInt();
            if (max <= a[i]) {
                second = max;
                max = a[i];
            } else if (second < a[i]) {
                second = a[i];
            }
        }
        
        for (int i = 0; i < n; i++) {
            if (a[i] != max) {
                System.out.println(max);
            } else {
                System.out.println(second);
            }
        }
    }
} Main public static void main(String args[]) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] a = new int[n];
        int max = 0, second = 0;
        for (int i = 0; i < n; i++) {
            a[i] = sc.nextInt();
            if (max <= a[i]) {
                second = max;
                max = a[i];
            } else if (second < a[i]) {
                second = a[i];
            }
        }
        
        for (int i = 0; i < n; i++) {
            if (a[i] != max) {
                System.out.println(max);
            } else {
                System.out.println(second);
            }
        }
    } main {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] a = new int[n];
        int max = 0, second = 0;
        for (int i = 0; i < n; i++) {
            a[i] = sc.nextInt();
            if (max <= a[i]) {
                second = max;
                max = a[i];
            } else if (second < a[i]) {
                second = a[i];
            }
        }
        
        for (int i = 0; i < n; i++) {
            if (a[i] != max) {
                System.out.println(max);
            } else {
                System.out.println(second);
            }
        }
    } 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 = 0 max 0 second = 0; second 0 for (int i = 0; i < n; i++) {
            a[i] = sc.nextInt();
            if (max <= a[i]) {
                second = max;
                max = a[i];
            } else if (second < a[i]) {
                second = a[i];
            }
        } int i = 0; int i = 0; i 0 i < n i n i++ i++ i {
            a[i] = sc.nextInt();
            if (max <= a[i]) {
                second = max;
                max = a[i];
            } else if (second < a[i]) {
                second = a[i];
            }
        } {
            a[i] = sc.nextInt();
            if (max <= a[i]) {
                second = max;
                max = a[i];
            } else if (second < a[i]) {
                second = a[i];
            }
        } a[i] = sc.nextInt() a[i] a i sc.nextInt() sc.nextInt sc if (max <= a[i]) {
                second = max;
                max = a[i];
            } else if (second < a[i]) {
                second = a[i];
            } max <= a[i] max a[i] a i {
                second = max;
                max = a[i];
            } second = max second max max = a[i] max a[i] a i if (second < a[i]) {
                second = a[i];
            } second < a[i] second a[i] a i {
                second = a[i];
            } second = a[i] second a[i] a i for (int i = 0; i < n; i++) {
            if (a[i] != max) {
                System.out.println(max);
            } else {
                System.out.println(second);
            }
        } int i = 0; int i = 0; i 0 i < n i n i++ i++ i {
            if (a[i] != max) {
                System.out.println(max);
            } else {
                System.out.println(second);
            }
        } {
            if (a[i] != max) {
                System.out.println(max);
            } else {
                System.out.println(second);
            }
        } if (a[i] != max) {
                System.out.println(max);
            } else {
                System.out.println(second);
            } a[i] != max a[i] a i max {
                System.out.println(max);
            } System.out.println(max) System.out.println System.out System System.out max {
                System.out.println(second);
            } System.out.println(second) System.out.println System.out System System.out second 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 = 0, second = 0;
        for (int i = 0; i < n; i++) {
            a[i] = sc.nextInt();
            if (max <= a[i]) {
                second = max;
                max = a[i];
            } else if (second < a[i]) {
                second = a[i];
            }
        }
        
        for (int i = 0; i < n; i++) {
            if (a[i] != max) {
                System.out.println(max);
            } else {
                System.out.println(second);
            }
        }
    }
} 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 = 0, second = 0;
        for (int i = 0; i < n; i++) {
            a[i] = sc.nextInt();
            if (max <= a[i]) {
                second = max;
                max = a[i];
            } else if (second < a[i]) {
                second = a[i];
            }
        }
        
        for (int i = 0; i < n; i++) {
            if (a[i] != max) {
                System.out.println(max);
            } else {
                System.out.println(second);
            }
        }
    }
} Main
import java.util.*;
import java.lang.*;

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