import java.util.Scanner;

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

		Scanner sc = new Scanner(System.in);

		int N = sc.nextInt();
		int A[] = new int[N];
		int maxA = 0;
		int maxAIndex = -1;
		int max = 0;

		for (int i = 0; i < N; i++) {
			A[i] = sc.nextInt();

			if (maxA <= A[i]) {
				maxA = A[i];
				maxAIndex = i;
			}
		}

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

			max = 0;

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

				if (i == j) {
					continue;
				}

				if (!(j == maxAIndex)) {
					break;
				}

				if (max <= A[i]) {
					max = A[i];
				}
			}

			if (max == 0) {
				System.out.println(maxA);
			} else {
				System.out.println(max);
			}

		}
	}
} 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();
		int A[] = new int[N];
		int maxA = 0;
		int maxAIndex = -1;
		int max = 0;

		for (int i = 0; i < N; i++) {
			A[i] = sc.nextInt();

			if (maxA <= A[i]) {
				maxA = A[i];
				maxAIndex = i;
			}
		}

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

			max = 0;

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

				if (i == j) {
					continue;
				}

				if (!(j == maxAIndex)) {
					break;
				}

				if (max <= A[i]) {
					max = A[i];
				}
			}

			if (max == 0) {
				System.out.println(maxA);
			} else {
				System.out.println(max);
			}

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

		Scanner sc = new Scanner(System.in);

		int N = sc.nextInt();
		int A[] = new int[N];
		int maxA = 0;
		int maxAIndex = -1;
		int max = 0;

		for (int i = 0; i < N; i++) {
			A[i] = sc.nextInt();

			if (maxA <= A[i]) {
				maxA = A[i];
				maxAIndex = i;
			}
		}

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

			max = 0;

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

				if (i == j) {
					continue;
				}

				if (!(j == maxAIndex)) {
					break;
				}

				if (max <= A[i]) {
					max = A[i];
				}
			}

			if (max == 0) {
				System.out.println(maxA);
			} else {
				System.out.println(max);
			}

		}
	} main {

		Scanner sc = new Scanner(System.in);

		int N = sc.nextInt();
		int A[] = new int[N];
		int maxA = 0;
		int maxAIndex = -1;
		int max = 0;

		for (int i = 0; i < N; i++) {
			A[i] = sc.nextInt();

			if (maxA <= A[i]) {
				maxA = A[i];
				maxAIndex = i;
			}
		}

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

			max = 0;

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

				if (i == j) {
					continue;
				}

				if (!(j == maxAIndex)) {
					break;
				}

				if (max <= A[i]) {
					max = A[i];
				}
			}

			if (max == 0) {
				System.out.println(maxA);
			} else {
				System.out.println(max);
			}

		}
	} Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int N = sc.nextInt(); N sc.nextInt() sc.nextInt sc int A[] = new int[N]; A new int[N] N int maxA = 0; maxA 0 int maxAIndex = -1; maxAIndex -1 1 int max = 0; max 0 for (int i = 0; i < N; i++) {
			A[i] = sc.nextInt();

			if (maxA <= A[i]) {
				maxA = A[i];
				maxAIndex = i;
			}
		} int i = 0; int i = 0; i 0 i < N i N i++ i++ i {
			A[i] = sc.nextInt();

			if (maxA <= A[i]) {
				maxA = A[i];
				maxAIndex = i;
			}
		} {
			A[i] = sc.nextInt();

			if (maxA <= A[i]) {
				maxA = A[i];
				maxAIndex = i;
			}
		} A[i] = sc.nextInt() A[i] A i sc.nextInt() sc.nextInt sc if (maxA <= A[i]) {
				maxA = A[i];
				maxAIndex = i;
			} maxA <= A[i] maxA A[i] A i {
				maxA = A[i];
				maxAIndex = i;
			} maxA = A[i] maxA A[i] A i maxAIndex = i maxAIndex i for (int j = 0; j < N; j++) {

			max = 0;

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

				if (i == j) {
					continue;
				}

				if (!(j == maxAIndex)) {
					break;
				}

				if (max <= A[i]) {
					max = A[i];
				}
			}

			if (max == 0) {
				System.out.println(maxA);
			} else {
				System.out.println(max);
			}

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

			max = 0;

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

				if (i == j) {
					continue;
				}

				if (!(j == maxAIndex)) {
					break;
				}

				if (max <= A[i]) {
					max = A[i];
				}
			}

			if (max == 0) {
				System.out.println(maxA);
			} else {
				System.out.println(max);
			}

		} {

			max = 0;

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

				if (i == j) {
					continue;
				}

				if (!(j == maxAIndex)) {
					break;
				}

				if (max <= A[i]) {
					max = A[i];
				}
			}

			if (max == 0) {
				System.out.println(maxA);
			} else {
				System.out.println(max);
			}

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

				if (i == j) {
					continue;
				}

				if (!(j == maxAIndex)) {
					break;
				}

				if (max <= A[i]) {
					max = A[i];
				}
			} int i = 0; int i = 0; i 0 i < N i N i++ i++ i {

				if (i == j) {
					continue;
				}

				if (!(j == maxAIndex)) {
					break;
				}

				if (max <= A[i]) {
					max = A[i];
				}
			} {

				if (i == j) {
					continue;
				}

				if (!(j == maxAIndex)) {
					break;
				}

				if (max <= A[i]) {
					max = A[i];
				}
			} if (i == j) {
					continue;
				} i == j i j {
					continue;
				} continue; if (!(j == maxAIndex)) {
					break;
				} !(j == maxAIndex) (j == maxAIndex) j maxAIndex {
					break;
				} break; if (max <= A[i]) {
					max = A[i];
				} max <= A[i] max A[i] A i {
					max = A[i];
				} max = A[i] max A[i] A i if (max == 0) {
				System.out.println(maxA);
			} else {
				System.out.println(max);
			} max == 0 max 0 {
				System.out.println(maxA);
			} System.out.println(maxA) System.out.println System.out System System.out maxA {
				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) {

		Scanner sc = new Scanner(System.in);

		int N = sc.nextInt();
		int A[] = new int[N];
		int maxA = 0;
		int maxAIndex = -1;
		int max = 0;

		for (int i = 0; i < N; i++) {
			A[i] = sc.nextInt();

			if (maxA <= A[i]) {
				maxA = A[i];
				maxAIndex = i;
			}
		}

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

			max = 0;

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

				if (i == j) {
					continue;
				}

				if (!(j == maxAIndex)) {
					break;
				}

				if (max <= A[i]) {
					max = A[i];
				}
			}

			if (max == 0) {
				System.out.println(maxA);
			} else {
				System.out.println(max);
			}

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

		Scanner sc = new Scanner(System.in);

		int N = sc.nextInt();
		int A[] = new int[N];
		int maxA = 0;
		int maxAIndex = -1;
		int max = 0;

		for (int i = 0; i < N; i++) {
			A[i] = sc.nextInt();

			if (maxA <= A[i]) {
				maxA = A[i];
				maxAIndex = i;
			}
		}

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

			max = 0;

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

				if (i == j) {
					continue;
				}

				if (!(j == maxAIndex)) {
					break;
				}

				if (max <= A[i]) {
					max = A[i];
				}
			}

			if (max == 0) {
				System.out.println(maxA);
			} else {
				System.out.println(max);
			}

		}
	}
} Main
import java.util.Scanner;

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

		Scanner sc = new Scanner(System.in);

		int N = sc.nextInt();
		int A[] = new int[N];
		int maxA = 0;
		int maxAIndex = -1;
		int max = 0;

		for (int i = 0; i < N; i++) {
			A[i] = sc.nextInt();

			if (maxA <= A[i]) {
				maxA = A[i];
				maxAIndex = i;
			}
		}

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

			max = 0;

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

				if (i == j) {
					continue;
				}

				if (!(j == maxAIndex)) {
					break;
				}

				if (max <= A[i]) {
					max = A[i];
				}
			}

			if (max == 0) {
				System.out.println(maxA);
			} else {
				System.out.println(max);
			}

		}
	}
}
