import java.util.Arrays;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int[] arr = new int[N];
        int[] arr2 = new int[N];
        for(int i = 0; i < N; i++) {
            arr[i] = sc.nextInt();
            arr2[i] = arr[i];
        }
        Arrays.sort(arr);
        int res = 0;
        int max = arr[N-1];
        for(int i = 0; i < N; i++) {
            if(arr2[i] == max) {
                System.out.println(arr[N-2]);
            } else {
                System.out.println(max);
            }
        }
    }
} import java.util.Arrays; Arrays java.util import java.util.Scanner; Scanner java.util public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int[] arr = new int[N];
        int[] arr2 = new int[N];
        for(int i = 0; i < N; i++) {
            arr[i] = sc.nextInt();
            arr2[i] = arr[i];
        }
        Arrays.sort(arr);
        int res = 0;
        int max = arr[N-1];
        for(int i = 0; i < N; i++) {
            if(arr2[i] == max) {
                System.out.println(arr[N-2]);
            } else {
                System.out.println(max);
            }
        }
    }
} Main public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int[] arr = new int[N];
        int[] arr2 = new int[N];
        for(int i = 0; i < N; i++) {
            arr[i] = sc.nextInt();
            arr2[i] = arr[i];
        }
        Arrays.sort(arr);
        int res = 0;
        int max = arr[N-1];
        for(int i = 0; i < N; i++) {
            if(arr2[i] == max) {
                System.out.println(arr[N-2]);
            } else {
                System.out.println(max);
            }
        }
    } main {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int[] arr = new int[N];
        int[] arr2 = new int[N];
        for(int i = 0; i < N; i++) {
            arr[i] = sc.nextInt();
            arr2[i] = arr[i];
        }
        Arrays.sort(arr);
        int res = 0;
        int max = arr[N-1];
        for(int i = 0; i < N; i++) {
            if(arr2[i] == max) {
                System.out.println(arr[N-2]);
            } else {
                System.out.println(max);
            }
        }
    } Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int N = sc.nextInt(); N sc.nextInt() sc.nextInt sc int[] arr = new int[N]; arr new int[N] N int[] arr2 = new int[N]; arr2 new int[N] N for(int i = 0; i < N; i++) {
            arr[i] = sc.nextInt();
            arr2[i] = arr[i];
        } int i = 0; int i = 0; i 0 i < N i N i++ i++ i {
            arr[i] = sc.nextInt();
            arr2[i] = arr[i];
        } {
            arr[i] = sc.nextInt();
            arr2[i] = arr[i];
        } arr[i] = sc.nextInt() arr[i] arr i sc.nextInt() sc.nextInt sc arr2[i] = arr[i] arr2[i] arr2 i arr[i] arr i Arrays.sort(arr) Arrays.sort Arrays arr int res = 0; res 0 int max = arr[N-1]; max arr[N-1] arr N-1 N 1 for(int i = 0; i < N; i++) {
            if(arr2[i] == max) {
                System.out.println(arr[N-2]);
            } else {
                System.out.println(max);
            }
        } int i = 0; int i = 0; i 0 i < N i N i++ i++ i {
            if(arr2[i] == max) {
                System.out.println(arr[N-2]);
            } else {
                System.out.println(max);
            }
        } {
            if(arr2[i] == max) {
                System.out.println(arr[N-2]);
            } else {
                System.out.println(max);
            }
        } if(arr2[i] == max) {
                System.out.println(arr[N-2]);
            } else {
                System.out.println(max);
            } arr2[i] == max arr2[i] arr2 i max {
                System.out.println(arr[N-2]);
            } System.out.println(arr[N-2]) System.out.println System.out System System.out arr[N-2] arr N-2 N 2 {
                System.out.println(max);
            } System.out.println(max) System.out.println System.out System System.out max String[] args args public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int[] arr = new int[N];
        int[] arr2 = new int[N];
        for(int i = 0; i < N; i++) {
            arr[i] = sc.nextInt();
            arr2[i] = arr[i];
        }
        Arrays.sort(arr);
        int res = 0;
        int max = arr[N-1];
        for(int i = 0; i < N; i++) {
            if(arr2[i] == max) {
                System.out.println(arr[N-2]);
            } else {
                System.out.println(max);
            }
        }
    }
} public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int[] arr = new int[N];
        int[] arr2 = new int[N];
        for(int i = 0; i < N; i++) {
            arr[i] = sc.nextInt();
            arr2[i] = arr[i];
        }
        Arrays.sort(arr);
        int res = 0;
        int max = arr[N-1];
        for(int i = 0; i < N; i++) {
            if(arr2[i] == max) {
                System.out.println(arr[N-2]);
            } else {
                System.out.println(max);
            }
        }
    }
} Main
import java.util.Arrays;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int[] arr = new int[N];
        int[] arr2 = new int[N];
        for(int i = 0; i < N; i++) {
            arr[i] = sc.nextInt();
            arr2[i] = arr[i];
        }
        Arrays.sort(arr);
        int res = 0;
        int max = arr[N-1];
        for(int i = 0; i < N; i++) {
            if(arr2[i] == max) {
                System.out.println(arr[N-2]);
            } else {
                System.out.println(max);
            }
        }
    }
}
