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

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		Integer[] a = new Integer[n];
		Integer[] tmpA = new Integer[n];

		for (int i=0; i<n; i++) {
			a[i] = sc.nextInt();
			tmpA[i] = a[i];
		}

		Arrays.sort(tmpA, Collections.reverseOrder());

		int first = tmpA[0];
		int second = tmpA[1];

		for (int i=0; i<n; i++) {
			if (a[i] == first) {
				System.out.println(second);
			} else {
				System.out.println(first);
			}
		}
		sc.close();
	}
} import java.util.Arrays; Arrays java.util import java.util.Collections; Collections 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();
		Integer[] a = new Integer[n];
		Integer[] tmpA = new Integer[n];

		for (int i=0; i<n; i++) {
			a[i] = sc.nextInt();
			tmpA[i] = a[i];
		}

		Arrays.sort(tmpA, Collections.reverseOrder());

		int first = tmpA[0];
		int second = tmpA[1];

		for (int i=0; i<n; i++) {
			if (a[i] == first) {
				System.out.println(second);
			} else {
				System.out.println(first);
			}
		}
		sc.close();
	}
} Main public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		Integer[] a = new Integer[n];
		Integer[] tmpA = new Integer[n];

		for (int i=0; i<n; i++) {
			a[i] = sc.nextInt();
			tmpA[i] = a[i];
		}

		Arrays.sort(tmpA, Collections.reverseOrder());

		int first = tmpA[0];
		int second = tmpA[1];

		for (int i=0; i<n; i++) {
			if (a[i] == first) {
				System.out.println(second);
			} else {
				System.out.println(first);
			}
		}
		sc.close();
	} main {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		Integer[] a = new Integer[n];
		Integer[] tmpA = new Integer[n];

		for (int i=0; i<n; i++) {
			a[i] = sc.nextInt();
			tmpA[i] = a[i];
		}

		Arrays.sort(tmpA, Collections.reverseOrder());

		int first = tmpA[0];
		int second = tmpA[1];

		for (int i=0; i<n; i++) {
			if (a[i] == first) {
				System.out.println(second);
			} else {
				System.out.println(first);
			}
		}
		sc.close();
	} Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int n = sc.nextInt(); n sc.nextInt() sc.nextInt sc Integer[] a = new Integer[n]; a new Integer[n] n Integer[] tmpA = new Integer[n]; tmpA new Integer[n] n for (int i=0; i<n; i++) {
			a[i] = sc.nextInt();
			tmpA[i] = a[i];
		} int i=0; int i=0; i 0 i<n i n i++ i++ i {
			a[i] = sc.nextInt();
			tmpA[i] = a[i];
		} {
			a[i] = sc.nextInt();
			tmpA[i] = a[i];
		} a[i] = sc.nextInt() a[i] a i sc.nextInt() sc.nextInt sc tmpA[i] = a[i] tmpA[i] tmpA i a[i] a i Arrays.sort(tmpA, Collections.reverseOrder()) Arrays.sort Arrays tmpA Collections.reverseOrder() Collections.reverseOrder Collections int first = tmpA[0]; first tmpA[0] tmpA 0 int second = tmpA[1]; second tmpA[1] tmpA 1 for (int i=0; i<n; i++) {
			if (a[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 (a[i] == first) {
				System.out.println(second);
			} else {
				System.out.println(first);
			}
		} {
			if (a[i] == first) {
				System.out.println(second);
			} else {
				System.out.println(first);
			}
		} if (a[i] == first) {
				System.out.println(second);
			} else {
				System.out.println(first);
			} a[i] == first a[i] a 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 sc.close() sc.close sc String[] args args public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		Integer[] a = new Integer[n];
		Integer[] tmpA = new Integer[n];

		for (int i=0; i<n; i++) {
			a[i] = sc.nextInt();
			tmpA[i] = a[i];
		}

		Arrays.sort(tmpA, Collections.reverseOrder());

		int first = tmpA[0];
		int second = tmpA[1];

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

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		Integer[] a = new Integer[n];
		Integer[] tmpA = new Integer[n];

		for (int i=0; i<n; i++) {
			a[i] = sc.nextInt();
			tmpA[i] = a[i];
		}

		Arrays.sort(tmpA, Collections.reverseOrder());

		int first = tmpA[0];
		int second = tmpA[1];

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

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		Integer[] a = new Integer[n];
		Integer[] tmpA = new Integer[n];

		for (int i=0; i<n; i++) {
			a[i] = sc.nextInt();
			tmpA[i] = a[i];
		}

		Arrays.sort(tmpA, Collections.reverseOrder());

		int first = tmpA[0];
		int second = tmpA[1];

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