import java.util.Arrays;
import java.util.Comparator;
import java.util.List;
import java.util.Scanner;
import java.util.stream.Collectors;

public class Main {
    public static void main(String[] args) {
        Scanner stdin = new Scanner(System.in);
        int n = Integer.parseInt(stdin.nextLine());
        int[] a = new int[n];
        for (int i = 0; i < n; i++) a[i] = Integer.parseInt(stdin.nextLine());
        
        List<Integer> b = Arrays.stream(a).boxed().sorted(Comparator.reverseOrder()).collect(Collectors.toList());
        for (int i = 0; i < n; i++) {
            if (a[i] == b.get(0)) {
                System.out.println(b.get(1));
            } else {
                System.out.println(b.get(0));
            }
        }
    }

} import java.util.Arrays; Arrays java.util import java.util.Comparator; Comparator java.util import java.util.List; List java.util import java.util.Scanner; Scanner java.util import java.util.stream.Collectors; Collectors java.util.stream public class Main {
    public static void main(String[] args) {
        Scanner stdin = new Scanner(System.in);
        int n = Integer.parseInt(stdin.nextLine());
        int[] a = new int[n];
        for (int i = 0; i < n; i++) a[i] = Integer.parseInt(stdin.nextLine());
        
        List<Integer> b = Arrays.stream(a).boxed().sorted(Comparator.reverseOrder()).collect(Collectors.toList());
        for (int i = 0; i < n; i++) {
            if (a[i] == b.get(0)) {
                System.out.println(b.get(1));
            } else {
                System.out.println(b.get(0));
            }
        }
    }

} Main public static void main(String[] args) {
        Scanner stdin = new Scanner(System.in);
        int n = Integer.parseInt(stdin.nextLine());
        int[] a = new int[n];
        for (int i = 0; i < n; i++) a[i] = Integer.parseInt(stdin.nextLine());
        
        List<Integer> b = Arrays.stream(a).boxed().sorted(Comparator.reverseOrder()).collect(Collectors.toList());
        for (int i = 0; i < n; i++) {
            if (a[i] == b.get(0)) {
                System.out.println(b.get(1));
            } else {
                System.out.println(b.get(0));
            }
        }
    } main {
        Scanner stdin = new Scanner(System.in);
        int n = Integer.parseInt(stdin.nextLine());
        int[] a = new int[n];
        for (int i = 0; i < n; i++) a[i] = Integer.parseInt(stdin.nextLine());
        
        List<Integer> b = Arrays.stream(a).boxed().sorted(Comparator.reverseOrder()).collect(Collectors.toList());
        for (int i = 0; i < n; i++) {
            if (a[i] == b.get(0)) {
                System.out.println(b.get(1));
            } else {
                System.out.println(b.get(0));
            }
        }
    } Scanner stdin = new Scanner(System.in); stdin new Scanner(System.in) int n = Integer.parseInt(stdin.nextLine()); n Integer.parseInt(stdin.nextLine()) Integer.parseInt Integer stdin.nextLine() stdin.nextLine stdin int[] a = new int[n]; a new int[n] n for (int i = 0; i < n; i++) a[i] = Integer.parseInt(stdin.nextLine()); int i = 0; int i = 0; i 0 i < n i n i++ i++ i a[i] = Integer.parseInt(stdin.nextLine()); a[i] = Integer.parseInt(stdin.nextLine()) a[i] a i Integer.parseInt(stdin.nextLine()) Integer.parseInt Integer stdin.nextLine() stdin.nextLine stdin List<Integer> b = Arrays.stream(a).boxed().sorted(Comparator.reverseOrder()).collect(Collectors.toList()); b Arrays.stream(a).boxed().sorted(Comparator.reverseOrder()).collect(Collectors.toList()) Arrays.stream(a).boxed().sorted(Comparator.reverseOrder()).collect Arrays.stream(a).boxed().sorted(Comparator.reverseOrder()) Arrays.stream(a).boxed().sorted Arrays.stream(a).boxed() Arrays.stream(a).boxed Arrays.stream(a) Arrays.stream Arrays a Comparator.reverseOrder() Comparator.reverseOrder Comparator Collectors.toList() Collectors.toList Collectors for (int i = 0; i < n; i++) {
            if (a[i] == b.get(0)) {
                System.out.println(b.get(1));
            } else {
                System.out.println(b.get(0));
            }
        } int i = 0; int i = 0; i 0 i < n i n i++ i++ i {
            if (a[i] == b.get(0)) {
                System.out.println(b.get(1));
            } else {
                System.out.println(b.get(0));
            }
        } {
            if (a[i] == b.get(0)) {
                System.out.println(b.get(1));
            } else {
                System.out.println(b.get(0));
            }
        } if (a[i] == b.get(0)) {
                System.out.println(b.get(1));
            } else {
                System.out.println(b.get(0));
            } a[i] == b.get(0) a[i] a i b.get(0) b.get b 0 {
                System.out.println(b.get(1));
            } System.out.println(b.get(1)) System.out.println System.out System System.out b.get(1) b.get b 1 {
                System.out.println(b.get(0));
            } System.out.println(b.get(0)) System.out.println System.out System System.out b.get(0) b.get b 0 String[] args args public class Main {
    public static void main(String[] args) {
        Scanner stdin = new Scanner(System.in);
        int n = Integer.parseInt(stdin.nextLine());
        int[] a = new int[n];
        for (int i = 0; i < n; i++) a[i] = Integer.parseInt(stdin.nextLine());
        
        List<Integer> b = Arrays.stream(a).boxed().sorted(Comparator.reverseOrder()).collect(Collectors.toList());
        for (int i = 0; i < n; i++) {
            if (a[i] == b.get(0)) {
                System.out.println(b.get(1));
            } else {
                System.out.println(b.get(0));
            }
        }
    }

} public class Main {
    public static void main(String[] args) {
        Scanner stdin = new Scanner(System.in);
        int n = Integer.parseInt(stdin.nextLine());
        int[] a = new int[n];
        for (int i = 0; i < n; i++) a[i] = Integer.parseInt(stdin.nextLine());
        
        List<Integer> b = Arrays.stream(a).boxed().sorted(Comparator.reverseOrder()).collect(Collectors.toList());
        for (int i = 0; i < n; i++) {
            if (a[i] == b.get(0)) {
                System.out.println(b.get(1));
            } else {
                System.out.println(b.get(0));
            }
        }
    }

} Main
import java.util.Arrays;
import java.util.Comparator;
import java.util.List;
import java.util.Scanner;
import java.util.stream.Collectors;

public class Main {
    public static void main(String[] args) {
        Scanner stdin = new Scanner(System.in);
        int n = Integer.parseInt(stdin.nextLine());
        int[] a = new int[n];
        for (int i = 0; i < n; i++) a[i] = Integer.parseInt(stdin.nextLine());
        
        List<Integer> b = Arrays.stream(a).boxed().sorted(Comparator.reverseOrder()).collect(Collectors.toList());
        for (int i = 0; i < n; i++) {
            if (a[i] == b.get(0)) {
                System.out.println(b.get(1));
            } else {
                System.out.println(b.get(0));
            }
        }
    }

}