import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        solve();
    }

    private static void solve() {
        Scanner input = new Scanner(System.in);

        int n = input.nextInt();
        int[] nums = new int[n];

        int first = 0;
        int second = 0;

        for (int i = 0; i < n; i++) {
        	nums[i]  = input.nextInt();
        	if (nums[i] >= first) {
        		second = first;
        		first = nums[i];
        	} else if (nums[i] >= second) {
        		second = nums[i];
        	}
        }

        for (int i = 0; i < n; i++) {
        	if (nums[i] == first) {
                System.out.println(second);
        	} else {
                System.out.println(first);
        	}
        }
    }
} import java.util.Scanner; Scanner java.util public class Main {

    public static void main(String[] args) {
        solve();
    }

    private static void solve() {
        Scanner input = new Scanner(System.in);

        int n = input.nextInt();
        int[] nums = new int[n];

        int first = 0;
        int second = 0;

        for (int i = 0; i < n; i++) {
        	nums[i]  = input.nextInt();
        	if (nums[i] >= first) {
        		second = first;
        		first = nums[i];
        	} else if (nums[i] >= second) {
        		second = nums[i];
        	}
        }

        for (int i = 0; i < n; i++) {
        	if (nums[i] == first) {
                System.out.println(second);
        	} else {
                System.out.println(first);
        	}
        }
    }
} Main public static void main(String[] args) {
        solve();
    } main {
        solve();
    } solve() solve String[] args args private static void solve() {
        Scanner input = new Scanner(System.in);

        int n = input.nextInt();
        int[] nums = new int[n];

        int first = 0;
        int second = 0;

        for (int i = 0; i < n; i++) {
        	nums[i]  = input.nextInt();
        	if (nums[i] >= first) {
        		second = first;
        		first = nums[i];
        	} else if (nums[i] >= second) {
        		second = nums[i];
        	}
        }

        for (int i = 0; i < n; i++) {
        	if (nums[i] == first) {
                System.out.println(second);
        	} else {
                System.out.println(first);
        	}
        }
    } solve {
        Scanner input = new Scanner(System.in);

        int n = input.nextInt();
        int[] nums = new int[n];

        int first = 0;
        int second = 0;

        for (int i = 0; i < n; i++) {
        	nums[i]  = input.nextInt();
        	if (nums[i] >= first) {
        		second = first;
        		first = nums[i];
        	} else if (nums[i] >= second) {
        		second = nums[i];
        	}
        }

        for (int i = 0; i < n; i++) {
        	if (nums[i] == first) {
                System.out.println(second);
        	} else {
                System.out.println(first);
        	}
        }
    } Scanner input = new Scanner(System.in); input new Scanner(System.in) int n = input.nextInt(); n input.nextInt() input.nextInt input int[] nums = new int[n]; nums new int[n] n int first = 0; first 0 int second = 0; second 0 for (int i = 0; i < n; i++) {
        	nums[i]  = input.nextInt();
        	if (nums[i] >= first) {
        		second = first;
        		first = nums[i];
        	} else if (nums[i] >= second) {
        		second = nums[i];
        	}
        } int i = 0; int i = 0; i 0 i < n i n i++ i++ i {
        	nums[i]  = input.nextInt();
        	if (nums[i] >= first) {
        		second = first;
        		first = nums[i];
        	} else if (nums[i] >= second) {
        		second = nums[i];
        	}
        } {
        	nums[i]  = input.nextInt();
        	if (nums[i] >= first) {
        		second = first;
        		first = nums[i];
        	} else if (nums[i] >= second) {
        		second = nums[i];
        	}
        } nums[i]  = input.nextInt() nums[i] nums i input.nextInt() input.nextInt input if (nums[i] >= first) {
        		second = first;
        		first = nums[i];
        	} else if (nums[i] >= second) {
        		second = nums[i];
        	} nums[i] >= first nums[i] nums i first {
        		second = first;
        		first = nums[i];
        	} second = first second first first = nums[i] first nums[i] nums i if (nums[i] >= second) {
        		second = nums[i];
        	} nums[i] >= second nums[i] nums i second {
        		second = nums[i];
        	} second = nums[i] second nums[i] nums i for (int i = 0; i < n; i++) {
        	if (nums[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 (nums[i] == first) {
                System.out.println(second);
        	} else {
                System.out.println(first);
        	}
        } {
        	if (nums[i] == first) {
                System.out.println(second);
        	} else {
                System.out.println(first);
        	}
        } if (nums[i] == first) {
                System.out.println(second);
        	} else {
                System.out.println(first);
        	} nums[i] == first nums[i] nums 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 public class Main {

    public static void main(String[] args) {
        solve();
    }

    private static void solve() {
        Scanner input = new Scanner(System.in);

        int n = input.nextInt();
        int[] nums = new int[n];

        int first = 0;
        int second = 0;

        for (int i = 0; i < n; i++) {
        	nums[i]  = input.nextInt();
        	if (nums[i] >= first) {
        		second = first;
        		first = nums[i];
        	} else if (nums[i] >= second) {
        		second = nums[i];
        	}
        }

        for (int i = 0; i < n; i++) {
        	if (nums[i] == first) {
                System.out.println(second);
        	} else {
                System.out.println(first);
        	}
        }
    }
} public class Main {

    public static void main(String[] args) {
        solve();
    }

    private static void solve() {
        Scanner input = new Scanner(System.in);

        int n = input.nextInt();
        int[] nums = new int[n];

        int first = 0;
        int second = 0;

        for (int i = 0; i < n; i++) {
        	nums[i]  = input.nextInt();
        	if (nums[i] >= first) {
        		second = first;
        		first = nums[i];
        	} else if (nums[i] >= second) {
        		second = nums[i];
        	}
        }

        for (int i = 0; i < n; i++) {
        	if (nums[i] == first) {
                System.out.println(second);
        	} else {
                System.out.println(first);
        	}
        }
    }
} Main
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        solve();
    }

    private static void solve() {
        Scanner input = new Scanner(System.in);

        int n = input.nextInt();
        int[] nums = new int[n];

        int first = 0;
        int second = 0;

        for (int i = 0; i < n; i++) {
        	nums[i]  = input.nextInt();
        	if (nums[i] >= first) {
        		second = first;
        		first = nums[i];
        	} else if (nums[i] >= second) {
        		second = nums[i];
        	}
        }

        for (int i = 0; i < n; i++) {
        	if (nums[i] == first) {
                System.out.println(second);
        	} else {
                System.out.println(first);
        	}
        }
    }
}
