import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner scan = new Scanner(System.in);

		int N = scan.nextInt();

		List<Integer> list = new ArrayList<>();
		List<Integer> subList = new ArrayList<>();

		for(int i = 0; i < N; i++) {
			list.add(scan.nextInt());
			subList.add(list.get(i));
		}

		Collections.sort(subList);

		for(int i = 0; i < N; i++) {

			// A1がAmaxと等しい
			if(subList.get(N -1) == list.get(i)) {
				// 2番目に大きい値
				System.out.println(subList.get(N -2));
			}else {
				System.out.println(subList.get(N - 1));
			}

		}
	}
} import java.util.ArrayList; ArrayList java.util import java.util.Collections; Collections java.util import java.util.List; List java.util import java.util.Scanner; Scanner java.util public class Main {

	public static void main(String[] args) {

		Scanner scan = new Scanner(System.in);

		int N = scan.nextInt();

		List<Integer> list = new ArrayList<>();
		List<Integer> subList = new ArrayList<>();

		for(int i = 0; i < N; i++) {
			list.add(scan.nextInt());
			subList.add(list.get(i));
		}

		Collections.sort(subList);

		for(int i = 0; i < N; i++) {

			// A1がAmaxと等しい
			if(subList.get(N -1) == list.get(i)) {
				// 2番目に大きい値
				System.out.println(subList.get(N -2));
			}else {
				System.out.println(subList.get(N - 1));
			}

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

		Scanner scan = new Scanner(System.in);

		int N = scan.nextInt();

		List<Integer> list = new ArrayList<>();
		List<Integer> subList = new ArrayList<>();

		for(int i = 0; i < N; i++) {
			list.add(scan.nextInt());
			subList.add(list.get(i));
		}

		Collections.sort(subList);

		for(int i = 0; i < N; i++) {

			// A1がAmaxと等しい
			if(subList.get(N -1) == list.get(i)) {
				// 2番目に大きい値
				System.out.println(subList.get(N -2));
			}else {
				System.out.println(subList.get(N - 1));
			}

		}
	} main {

		Scanner scan = new Scanner(System.in);

		int N = scan.nextInt();

		List<Integer> list = new ArrayList<>();
		List<Integer> subList = new ArrayList<>();

		for(int i = 0; i < N; i++) {
			list.add(scan.nextInt());
			subList.add(list.get(i));
		}

		Collections.sort(subList);

		for(int i = 0; i < N; i++) {

			// A1がAmaxと等しい
			if(subList.get(N -1) == list.get(i)) {
				// 2番目に大きい値
				System.out.println(subList.get(N -2));
			}else {
				System.out.println(subList.get(N - 1));
			}

		}
	} Scanner scan = new Scanner(System.in); scan new Scanner(System.in) int N = scan.nextInt(); N scan.nextInt() scan.nextInt scan List<Integer> list = new ArrayList<>(); list new ArrayList<>() List<Integer> subList = new ArrayList<>(); subList new ArrayList<>() for(int i = 0; i < N; i++) {
			list.add(scan.nextInt());
			subList.add(list.get(i));
		} int i = 0; int i = 0; i 0 i < N i N i++ i++ i {
			list.add(scan.nextInt());
			subList.add(list.get(i));
		} {
			list.add(scan.nextInt());
			subList.add(list.get(i));
		} list.add(scan.nextInt()) list.add list scan.nextInt() scan.nextInt scan subList.add(list.get(i)) subList.add subList list.get(i) list.get list i Collections.sort(subList) Collections.sort Collections subList for(int i = 0; i < N; i++) {

			// A1がAmaxと等しい
			if(subList.get(N -1) == list.get(i)) {
				// 2番目に大きい値
				System.out.println(subList.get(N -2));
			}else {
				System.out.println(subList.get(N - 1));
			}

		} int i = 0; int i = 0; i 0 i < N i N i++ i++ i {

			// A1がAmaxと等しい
			if(subList.get(N -1) == list.get(i)) {
				// 2番目に大きい値
				System.out.println(subList.get(N -2));
			}else {
				System.out.println(subList.get(N - 1));
			}

		} {

			// A1がAmaxと等しい
			if(subList.get(N -1) == list.get(i)) {
				// 2番目に大きい値
				System.out.println(subList.get(N -2));
			}else {
				System.out.println(subList.get(N - 1));
			}

		} if(subList.get(N -1) == list.get(i)) {
				// 2番目に大きい値
				System.out.println(subList.get(N -2));
			}else {
				System.out.println(subList.get(N - 1));
			} subList.get(N -1) == list.get(i) subList.get(N -1) subList.get subList N -1 N 1 list.get(i) list.get list i {
				// 2番目に大きい値
				System.out.println(subList.get(N -2));
			} System.out.println(subList.get(N -2)) System.out.println System.out System System.out subList.get(N -2) subList.get subList N -2 N 2 {
				System.out.println(subList.get(N - 1));
			} System.out.println(subList.get(N - 1)) System.out.println System.out System System.out subList.get(N - 1) subList.get subList N - 1 N 1 String[] args args public class Main {

	public static void main(String[] args) {

		Scanner scan = new Scanner(System.in);

		int N = scan.nextInt();

		List<Integer> list = new ArrayList<>();
		List<Integer> subList = new ArrayList<>();

		for(int i = 0; i < N; i++) {
			list.add(scan.nextInt());
			subList.add(list.get(i));
		}

		Collections.sort(subList);

		for(int i = 0; i < N; i++) {

			// A1がAmaxと等しい
			if(subList.get(N -1) == list.get(i)) {
				// 2番目に大きい値
				System.out.println(subList.get(N -2));
			}else {
				System.out.println(subList.get(N - 1));
			}

		}
	}
} public class Main {

	public static void main(String[] args) {

		Scanner scan = new Scanner(System.in);

		int N = scan.nextInt();

		List<Integer> list = new ArrayList<>();
		List<Integer> subList = new ArrayList<>();

		for(int i = 0; i < N; i++) {
			list.add(scan.nextInt());
			subList.add(list.get(i));
		}

		Collections.sort(subList);

		for(int i = 0; i < N; i++) {

			// A1がAmaxと等しい
			if(subList.get(N -1) == list.get(i)) {
				// 2番目に大きい値
				System.out.println(subList.get(N -2));
			}else {
				System.out.println(subList.get(N - 1));
			}

		}
	}
} Main
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner scan = new Scanner(System.in);

		int N = scan.nextInt();

		List<Integer> list = new ArrayList<>();
		List<Integer> subList = new ArrayList<>();

		for(int i = 0; i < N; i++) {
			list.add(scan.nextInt());
			subList.add(list.get(i));
		}

		Collections.sort(subList);

		for(int i = 0; i < N; i++) {

			// A1がAmaxと等しい
			if(subList.get(N -1) == list.get(i)) {
				// 2番目に大きい値
				System.out.println(subList.get(N -2));
			}else {
				System.out.println(subList.get(N - 1));
			}

		}
	}
}