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

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

		int a;

		Scanner sc = new Scanner(System.in);

		a = sc.nextInt();
		Long[] aArray = new Long[a];

		for (int i = 0; i < a; i++) {
			aArray[i] = sc.nextLong();
		}

		List<Long> list = new ArrayList<Long>(Arrays.asList(aArray));
		Collections.sort(list,Comparator.reverseOrder());

		long max = list.get(0);
		long maxNext = list.get(1);

		for (int i = 0; i < a; i++) {
			if (max == aArray[i]) {
				System.out.println(maxNext);
			} else {
				System.out.println(max);
			}
		}
	}
} import java.util.ArrayList; ArrayList java.util import java.util.Arrays; Arrays java.util import java.util.Collections; Collections java.util import java.util.Comparator; Comparator 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) {

		int a;

		Scanner sc = new Scanner(System.in);

		a = sc.nextInt();
		Long[] aArray = new Long[a];

		for (int i = 0; i < a; i++) {
			aArray[i] = sc.nextLong();
		}

		List<Long> list = new ArrayList<Long>(Arrays.asList(aArray));
		Collections.sort(list,Comparator.reverseOrder());

		long max = list.get(0);
		long maxNext = list.get(1);

		for (int i = 0; i < a; i++) {
			if (max == aArray[i]) {
				System.out.println(maxNext);
			} else {
				System.out.println(max);
			}
		}
	}
} Main public static void main(String[] args) {

		int a;

		Scanner sc = new Scanner(System.in);

		a = sc.nextInt();
		Long[] aArray = new Long[a];

		for (int i = 0; i < a; i++) {
			aArray[i] = sc.nextLong();
		}

		List<Long> list = new ArrayList<Long>(Arrays.asList(aArray));
		Collections.sort(list,Comparator.reverseOrder());

		long max = list.get(0);
		long maxNext = list.get(1);

		for (int i = 0; i < a; i++) {
			if (max == aArray[i]) {
				System.out.println(maxNext);
			} else {
				System.out.println(max);
			}
		}
	} main {

		int a;

		Scanner sc = new Scanner(System.in);

		a = sc.nextInt();
		Long[] aArray = new Long[a];

		for (int i = 0; i < a; i++) {
			aArray[i] = sc.nextLong();
		}

		List<Long> list = new ArrayList<Long>(Arrays.asList(aArray));
		Collections.sort(list,Comparator.reverseOrder());

		long max = list.get(0);
		long maxNext = list.get(1);

		for (int i = 0; i < a; i++) {
			if (max == aArray[i]) {
				System.out.println(maxNext);
			} else {
				System.out.println(max);
			}
		}
	} int a; a Scanner sc = new Scanner(System.in); sc new Scanner(System.in) a = sc.nextInt() a sc.nextInt() sc.nextInt sc Long[] aArray = new Long[a]; aArray new Long[a] a for (int i = 0; i < a; i++) {
			aArray[i] = sc.nextLong();
		} int i = 0; int i = 0; i 0 i < a i a i++ i++ i {
			aArray[i] = sc.nextLong();
		} {
			aArray[i] = sc.nextLong();
		} aArray[i] = sc.nextLong() aArray[i] aArray i sc.nextLong() sc.nextLong sc List<Long> list = new ArrayList<Long>(Arrays.asList(aArray)); list new ArrayList<Long>(Arrays.asList(aArray)) Collections.sort(list,Comparator.reverseOrder()) Collections.sort Collections list Comparator.reverseOrder() Comparator.reverseOrder Comparator long max = list.get(0); max list.get(0) list.get list 0 long maxNext = list.get(1); maxNext list.get(1) list.get list 1 for (int i = 0; i < a; i++) {
			if (max == aArray[i]) {
				System.out.println(maxNext);
			} else {
				System.out.println(max);
			}
		} int i = 0; int i = 0; i 0 i < a i a i++ i++ i {
			if (max == aArray[i]) {
				System.out.println(maxNext);
			} else {
				System.out.println(max);
			}
		} {
			if (max == aArray[i]) {
				System.out.println(maxNext);
			} else {
				System.out.println(max);
			}
		} if (max == aArray[i]) {
				System.out.println(maxNext);
			} else {
				System.out.println(max);
			} max == aArray[i] max aArray[i] aArray i {
				System.out.println(maxNext);
			} System.out.println(maxNext) System.out.println System.out System System.out maxNext {
				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) {

		int a;

		Scanner sc = new Scanner(System.in);

		a = sc.nextInt();
		Long[] aArray = new Long[a];

		for (int i = 0; i < a; i++) {
			aArray[i] = sc.nextLong();
		}

		List<Long> list = new ArrayList<Long>(Arrays.asList(aArray));
		Collections.sort(list,Comparator.reverseOrder());

		long max = list.get(0);
		long maxNext = list.get(1);

		for (int i = 0; i < a; i++) {
			if (max == aArray[i]) {
				System.out.println(maxNext);
			} else {
				System.out.println(max);
			}
		}
	}
} public class Main {
	public static void main(String[] args) {

		int a;

		Scanner sc = new Scanner(System.in);

		a = sc.nextInt();
		Long[] aArray = new Long[a];

		for (int i = 0; i < a; i++) {
			aArray[i] = sc.nextLong();
		}

		List<Long> list = new ArrayList<Long>(Arrays.asList(aArray));
		Collections.sort(list,Comparator.reverseOrder());

		long max = list.get(0);
		long maxNext = list.get(1);

		for (int i = 0; i < a; i++) {
			if (max == aArray[i]) {
				System.out.println(maxNext);
			} else {
				System.out.println(max);
			}
		}
	}
} Main
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import java.util.Scanner;

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

		int a;

		Scanner sc = new Scanner(System.in);

		a = sc.nextInt();
		Long[] aArray = new Long[a];

		for (int i = 0; i < a; i++) {
			aArray[i] = sc.nextLong();
		}

		List<Long> list = new ArrayList<Long>(Arrays.asList(aArray));
		Collections.sort(list,Comparator.reverseOrder());

		long max = list.get(0);
		long maxNext = list.get(1);

		for (int i = 0; i < a; i++) {
			if (max == aArray[i]) {
				System.out.println(maxNext);
			} else {
				System.out.println(max);
			}
		}
	}
}
