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

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String num = sc.nextLine();
        String[] nums = new String[Integer.parseInt(num)];
        for(int i=0;i<Integer.parseInt(num); i++) {
            nums[i] = sc.nextLine();
        }
        check(num, nums);
    }

    public static void check(String num, String[] nums) {

        int[] vals = new int[nums.length];
        for(int i=0; i<vals.length; i++) {
            vals[i] = Integer.parseInt(nums[i]);
        }
        int max =0;
        int maxi = 0;
        for (int i=0;i<vals.length; i++){
            if(max < vals[i]) {
                max = vals[i];
                maxi = i;
            }
        }
        int max2 = 0;
        for (int i=0;i<vals.length; i++) {
            if(i == maxi) {
                continue;
            }
            if (max2 < vals[i] && max > max2) {
                max2 = vals[i];
            }
        }
        for(int i=0;i<Integer.parseInt(num);i++) {
            if(vals[i] == max) {
                System.out.println(max2);
            } 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);
        String num = sc.nextLine();
        String[] nums = new String[Integer.parseInt(num)];
        for(int i=0;i<Integer.parseInt(num); i++) {
            nums[i] = sc.nextLine();
        }
        check(num, nums);
    }

    public static void check(String num, String[] nums) {

        int[] vals = new int[nums.length];
        for(int i=0; i<vals.length; i++) {
            vals[i] = Integer.parseInt(nums[i]);
        }
        int max =0;
        int maxi = 0;
        for (int i=0;i<vals.length; i++){
            if(max < vals[i]) {
                max = vals[i];
                maxi = i;
            }
        }
        int max2 = 0;
        for (int i=0;i<vals.length; i++) {
            if(i == maxi) {
                continue;
            }
            if (max2 < vals[i] && max > max2) {
                max2 = vals[i];
            }
        }
        for(int i=0;i<Integer.parseInt(num);i++) {
            if(vals[i] == max) {
                System.out.println(max2);
            } else {
                System.out.println(max);
            }
        }
    }
} Main public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String num = sc.nextLine();
        String[] nums = new String[Integer.parseInt(num)];
        for(int i=0;i<Integer.parseInt(num); i++) {
            nums[i] = sc.nextLine();
        }
        check(num, nums);
    } main {
        Scanner sc = new Scanner(System.in);
        String num = sc.nextLine();
        String[] nums = new String[Integer.parseInt(num)];
        for(int i=0;i<Integer.parseInt(num); i++) {
            nums[i] = sc.nextLine();
        }
        check(num, nums);
    } Scanner sc = new Scanner(System.in); sc new Scanner(System.in) String num = sc.nextLine(); num sc.nextLine() sc.nextLine sc String[] nums = new String[Integer.parseInt(num)]; nums new String[Integer.parseInt(num)] Integer.parseInt(num) Integer.parseInt Integer num for(int i=0;i<Integer.parseInt(num); i++) {
            nums[i] = sc.nextLine();
        } int i=0; int i=0; i 0 i<Integer.parseInt(num) i Integer.parseInt(num) Integer.parseInt Integer num i++ i++ i {
            nums[i] = sc.nextLine();
        } {
            nums[i] = sc.nextLine();
        } nums[i] = sc.nextLine() nums[i] nums i sc.nextLine() sc.nextLine sc check(num, nums) check num nums String[] args args public static void check(String num, String[] nums) {

        int[] vals = new int[nums.length];
        for(int i=0; i<vals.length; i++) {
            vals[i] = Integer.parseInt(nums[i]);
        }
        int max =0;
        int maxi = 0;
        for (int i=0;i<vals.length; i++){
            if(max < vals[i]) {
                max = vals[i];
                maxi = i;
            }
        }
        int max2 = 0;
        for (int i=0;i<vals.length; i++) {
            if(i == maxi) {
                continue;
            }
            if (max2 < vals[i] && max > max2) {
                max2 = vals[i];
            }
        }
        for(int i=0;i<Integer.parseInt(num);i++) {
            if(vals[i] == max) {
                System.out.println(max2);
            } else {
                System.out.println(max);
            }
        }
    } check {

        int[] vals = new int[nums.length];
        for(int i=0; i<vals.length; i++) {
            vals[i] = Integer.parseInt(nums[i]);
        }
        int max =0;
        int maxi = 0;
        for (int i=0;i<vals.length; i++){
            if(max < vals[i]) {
                max = vals[i];
                maxi = i;
            }
        }
        int max2 = 0;
        for (int i=0;i<vals.length; i++) {
            if(i == maxi) {
                continue;
            }
            if (max2 < vals[i] && max > max2) {
                max2 = vals[i];
            }
        }
        for(int i=0;i<Integer.parseInt(num);i++) {
            if(vals[i] == max) {
                System.out.println(max2);
            } else {
                System.out.println(max);
            }
        }
    } int[] vals = new int[nums.length]; vals new int[nums.length] nums.length nums nums.length for(int i=0; i<vals.length; i++) {
            vals[i] = Integer.parseInt(nums[i]);
        } int i=0; int i=0; i 0 i<vals.length i vals.length vals vals.length i++ i++ i {
            vals[i] = Integer.parseInt(nums[i]);
        } {
            vals[i] = Integer.parseInt(nums[i]);
        } vals[i] = Integer.parseInt(nums[i]) vals[i] vals i Integer.parseInt(nums[i]) Integer.parseInt Integer nums[i] nums i int max =0; max 0 int maxi = 0; maxi 0 for (int i=0;i<vals.length; i++){
            if(max < vals[i]) {
                max = vals[i];
                maxi = i;
            }
        } int i=0; int i=0; i 0 i<vals.length i vals.length vals vals.length i++ i++ i {
            if(max < vals[i]) {
                max = vals[i];
                maxi = i;
            }
        } {
            if(max < vals[i]) {
                max = vals[i];
                maxi = i;
            }
        } if(max < vals[i]) {
                max = vals[i];
                maxi = i;
            } max < vals[i] max vals[i] vals i {
                max = vals[i];
                maxi = i;
            } max = vals[i] max vals[i] vals i maxi = i maxi i int max2 = 0; max2 0 for (int i=0;i<vals.length; i++) {
            if(i == maxi) {
                continue;
            }
            if (max2 < vals[i] && max > max2) {
                max2 = vals[i];
            }
        } int i=0; int i=0; i 0 i<vals.length i vals.length vals vals.length i++ i++ i {
            if(i == maxi) {
                continue;
            }
            if (max2 < vals[i] && max > max2) {
                max2 = vals[i];
            }
        } {
            if(i == maxi) {
                continue;
            }
            if (max2 < vals[i] && max > max2) {
                max2 = vals[i];
            }
        } if(i == maxi) {
                continue;
            } i == maxi i maxi {
                continue;
            } continue; if (max2 < vals[i] && max > max2) {
                max2 = vals[i];
            } max2 < vals[i] && max > max2 max2 < vals[i] max2 vals[i] vals i max > max2 max max2 {
                max2 = vals[i];
            } max2 = vals[i] max2 vals[i] vals i for(int i=0;i<Integer.parseInt(num);i++) {
            if(vals[i] == max) {
                System.out.println(max2);
            } else {
                System.out.println(max);
            }
        } int i=0; int i=0; i 0 i<Integer.parseInt(num) i Integer.parseInt(num) Integer.parseInt Integer num i++ i++ i {
            if(vals[i] == max) {
                System.out.println(max2);
            } else {
                System.out.println(max);
            }
        } {
            if(vals[i] == max) {
                System.out.println(max2);
            } else {
                System.out.println(max);
            }
        } if(vals[i] == max) {
                System.out.println(max2);
            } else {
                System.out.println(max);
            } vals[i] == max vals[i] vals i max {
                System.out.println(max2);
            } System.out.println(max2) System.out.println System.out System System.out max2 {
                System.out.println(max);
            } System.out.println(max) System.out.println System.out System System.out max String num num String[] nums nums public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String num = sc.nextLine();
        String[] nums = new String[Integer.parseInt(num)];
        for(int i=0;i<Integer.parseInt(num); i++) {
            nums[i] = sc.nextLine();
        }
        check(num, nums);
    }

    public static void check(String num, String[] nums) {

        int[] vals = new int[nums.length];
        for(int i=0; i<vals.length; i++) {
            vals[i] = Integer.parseInt(nums[i]);
        }
        int max =0;
        int maxi = 0;
        for (int i=0;i<vals.length; i++){
            if(max < vals[i]) {
                max = vals[i];
                maxi = i;
            }
        }
        int max2 = 0;
        for (int i=0;i<vals.length; i++) {
            if(i == maxi) {
                continue;
            }
            if (max2 < vals[i] && max > max2) {
                max2 = vals[i];
            }
        }
        for(int i=0;i<Integer.parseInt(num);i++) {
            if(vals[i] == max) {
                System.out.println(max2);
            } else {
                System.out.println(max);
            }
        }
    }
} public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String num = sc.nextLine();
        String[] nums = new String[Integer.parseInt(num)];
        for(int i=0;i<Integer.parseInt(num); i++) {
            nums[i] = sc.nextLine();
        }
        check(num, nums);
    }

    public static void check(String num, String[] nums) {

        int[] vals = new int[nums.length];
        for(int i=0; i<vals.length; i++) {
            vals[i] = Integer.parseInt(nums[i]);
        }
        int max =0;
        int maxi = 0;
        for (int i=0;i<vals.length; i++){
            if(max < vals[i]) {
                max = vals[i];
                maxi = i;
            }
        }
        int max2 = 0;
        for (int i=0;i<vals.length; i++) {
            if(i == maxi) {
                continue;
            }
            if (max2 < vals[i] && max > max2) {
                max2 = vals[i];
            }
        }
        for(int i=0;i<Integer.parseInt(num);i++) {
            if(vals[i] == max) {
                System.out.println(max2);
            } 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);
        String num = sc.nextLine();
        String[] nums = new String[Integer.parseInt(num)];
        for(int i=0;i<Integer.parseInt(num); i++) {
            nums[i] = sc.nextLine();
        }
        check(num, nums);
    }

    public static void check(String num, String[] nums) {

        int[] vals = new int[nums.length];
        for(int i=0; i<vals.length; i++) {
            vals[i] = Integer.parseInt(nums[i]);
        }
        int max =0;
        int maxi = 0;
        for (int i=0;i<vals.length; i++){
            if(max < vals[i]) {
                max = vals[i];
                maxi = i;
            }
        }
        int max2 = 0;
        for (int i=0;i<vals.length; i++) {
            if(i == maxi) {
                continue;
            }
            if (max2 < vals[i] && max > max2) {
                max2 = vals[i];
            }
        }
        for(int i=0;i<Integer.parseInt(num);i++) {
            if(vals[i] == max) {
                System.out.println(max2);
            } else {
                System.out.println(max);
            }
        }
    }
}