import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        // Your code here!
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] array = new int[n];
        int first = -1;
        int second = -2;
        for (int i = 0; i < n; i++) {
            array[i] = sc.nextInt();
            
            if (array[i] > first) {
                second = first;
                first = array[i];
            } else if (array[i] > second) {
                second = array[i];
            }
        }
        
        for (int i = 0; i < n; i++) {
            if (array[i] == first) {
                System.out.println(second);
            } else {
                System.out.println(first);
            }
        }
    }
} import java.util.*; util.* java public class Main {
    public static void main(String[] args) throws Exception {
        // Your code here!
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] array = new int[n];
        int first = -1;
        int second = -2;
        for (int i = 0; i < n; i++) {
            array[i] = sc.nextInt();
            
            if (array[i] > first) {
                second = first;
                first = array[i];
            } else if (array[i] > second) {
                second = array[i];
            }
        }
        
        for (int i = 0; i < n; i++) {
            if (array[i] == first) {
                System.out.println(second);
            } else {
                System.out.println(first);
            }
        }
    }
} Main public static void main(String[] args) throws Exception {
        // Your code here!
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] array = new int[n];
        int first = -1;
        int second = -2;
        for (int i = 0; i < n; i++) {
            array[i] = sc.nextInt();
            
            if (array[i] > first) {
                second = first;
                first = array[i];
            } else if (array[i] > second) {
                second = array[i];
            }
        }
        
        for (int i = 0; i < n; i++) {
            if (array[i] == first) {
                System.out.println(second);
            } else {
                System.out.println(first);
            }
        }
    } main {
        // Your code here!
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] array = new int[n];
        int first = -1;
        int second = -2;
        for (int i = 0; i < n; i++) {
            array[i] = sc.nextInt();
            
            if (array[i] > first) {
                second = first;
                first = array[i];
            } else if (array[i] > second) {
                second = array[i];
            }
        }
        
        for (int i = 0; i < n; i++) {
            if (array[i] == first) {
                System.out.println(second);
            } else {
                System.out.println(first);
            }
        }
    } Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int n = sc.nextInt(); n sc.nextInt() sc.nextInt sc int[] array = new int[n]; array new int[n] n int first = -1; first -1 1 int second = -2; second -2 2 for (int i = 0; i < n; i++) {
            array[i] = sc.nextInt();
            
            if (array[i] > first) {
                second = first;
                first = array[i];
            } else if (array[i] > second) {
                second = array[i];
            }
        } int i = 0; int i = 0; i 0 i < n i n i++ i++ i {
            array[i] = sc.nextInt();
            
            if (array[i] > first) {
                second = first;
                first = array[i];
            } else if (array[i] > second) {
                second = array[i];
            }
        } {
            array[i] = sc.nextInt();
            
            if (array[i] > first) {
                second = first;
                first = array[i];
            } else if (array[i] > second) {
                second = array[i];
            }
        } array[i] = sc.nextInt() array[i] array i sc.nextInt() sc.nextInt sc if (array[i] > first) {
                second = first;
                first = array[i];
            } else if (array[i] > second) {
                second = array[i];
            } array[i] > first array[i] array i first {
                second = first;
                first = array[i];
            } second = first second first first = array[i] first array[i] array i if (array[i] > second) {
                second = array[i];
            } array[i] > second array[i] array i second {
                second = array[i];
            } second = array[i] second array[i] array i for (int i = 0; i < n; i++) {
            if (array[i] == first) {
                System.out.println(second);
            } else {
                System.out.println(first);
            }
        } int i = 0; int i = 0; i 0 i < n i n i++ i++ i {
            if (array[i] == first) {
                System.out.println(second);
            } else {
                System.out.println(first);
            }
        } {
            if (array[i] == first) {
                System.out.println(second);
            } else {
                System.out.println(first);
            }
        } if (array[i] == first) {
                System.out.println(second);
            } else {
                System.out.println(first);
            } array[i] == first array[i] array i first {
                System.out.println(second);
            } System.out.println(second) System.out.println System.out System System.out second {
                System.out.println(first);
            } System.out.println(first) System.out.println System.out System System.out first String[] args args public class Main {
    public static void main(String[] args) throws Exception {
        // Your code here!
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] array = new int[n];
        int first = -1;
        int second = -2;
        for (int i = 0; i < n; i++) {
            array[i] = sc.nextInt();
            
            if (array[i] > first) {
                second = first;
                first = array[i];
            } else if (array[i] > second) {
                second = array[i];
            }
        }
        
        for (int i = 0; i < n; i++) {
            if (array[i] == first) {
                System.out.println(second);
            } else {
                System.out.println(first);
            }
        }
    }
} public class Main {
    public static void main(String[] args) throws Exception {
        // Your code here!
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] array = new int[n];
        int first = -1;
        int second = -2;
        for (int i = 0; i < n; i++) {
            array[i] = sc.nextInt();
            
            if (array[i] > first) {
                second = first;
                first = array[i];
            } else if (array[i] > second) {
                second = array[i];
            }
        }
        
        for (int i = 0; i < n; i++) {
            if (array[i] == first) {
                System.out.println(second);
            } else {
                System.out.println(first);
            }
        }
    }
} Main
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        // Your code here!
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] array = new int[n];
        int first = -1;
        int second = -2;
        for (int i = 0; i < n; i++) {
            array[i] = sc.nextInt();
            
            if (array[i] > first) {
                second = first;
                first = array[i];
            } else if (array[i] > second) {
                second = array[i];
            }
        }
        
        for (int i = 0; i < n; i++) {
            if (array[i] == first) {
                System.out.println(second);
            } else {
                System.out.println(first);
            }
        }
    }
}
