import java.util.*;
import java.lang.*;

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 max = 0;
		int semi = 0;
		for (int i = 0; i < n; i++) {
			a[i] = sc.nextInt();
			if (a[i] >= max) {
				semi = max;
				max = a[i];
			} else if (a[i] >= semi) {
				semi = a[i];
			}
		}
		for (int i = 0; i < n; i++) {
			if (a[i] == max) {
				System.out.println(semi);
			} else {
				System.out.println(max);
			}
		}
	}
} import java.util.*; util.* java import java.lang.*; lang.* java 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 max = 0;
		int semi = 0;
		for (int i = 0; i < n; i++) {
			a[i] = sc.nextInt();
			if (a[i] >= max) {
				semi = max;
				max = a[i];
			} else if (a[i] >= semi) {
				semi = a[i];
			}
		}
		for (int i = 0; i < n; i++) {
			if (a[i] == max) {
				System.out.println(semi);
			} 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 max = 0;
		int semi = 0;
		for (int i = 0; i < n; i++) {
			a[i] = sc.nextInt();
			if (a[i] >= max) {
				semi = max;
				max = a[i];
			} else if (a[i] >= semi) {
				semi = a[i];
			}
		}
		for (int i = 0; i < n; i++) {
			if (a[i] == max) {
				System.out.println(semi);
			} else {
				System.out.println(max);
			}
		}
	} main {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[] a = new int[n];
		int max = 0;
		int semi = 0;
		for (int i = 0; i < n; i++) {
			a[i] = sc.nextInt();
			if (a[i] >= max) {
				semi = max;
				max = a[i];
			} else if (a[i] >= semi) {
				semi = a[i];
			}
		}
		for (int i = 0; i < n; i++) {
			if (a[i] == max) {
				System.out.println(semi);
			} 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 max = 0; max 0 int semi = 0; semi 0 for (int i = 0; i < n; i++) {
			a[i] = sc.nextInt();
			if (a[i] >= max) {
				semi = max;
				max = a[i];
			} else if (a[i] >= semi) {
				semi = a[i];
			}
		} int i = 0; int i = 0; i 0 i < n i n i++ i++ i {
			a[i] = sc.nextInt();
			if (a[i] >= max) {
				semi = max;
				max = a[i];
			} else if (a[i] >= semi) {
				semi = a[i];
			}
		} {
			a[i] = sc.nextInt();
			if (a[i] >= max) {
				semi = max;
				max = a[i];
			} else if (a[i] >= semi) {
				semi = a[i];
			}
		} a[i] = sc.nextInt() a[i] a i sc.nextInt() sc.nextInt sc if (a[i] >= max) {
				semi = max;
				max = a[i];
			} else if (a[i] >= semi) {
				semi = a[i];
			} a[i] >= max a[i] a i max {
				semi = max;
				max = a[i];
			} semi = max semi max max = a[i] max a[i] a i if (a[i] >= semi) {
				semi = a[i];
			} a[i] >= semi a[i] a i semi {
				semi = a[i];
			} semi = a[i] semi a[i] a i for (int i = 0; i < n; i++) {
			if (a[i] == max) {
				System.out.println(semi);
			} else {
				System.out.println(max);
			}
		} int i = 0; int i = 0; i 0 i < n i n i++ i++ i {
			if (a[i] == max) {
				System.out.println(semi);
			} else {
				System.out.println(max);
			}
		} {
			if (a[i] == max) {
				System.out.println(semi);
			} else {
				System.out.println(max);
			}
		} if (a[i] == max) {
				System.out.println(semi);
			} else {
				System.out.println(max);
			} a[i] == max a[i] a i max {
				System.out.println(semi);
			} System.out.println(semi) System.out.println System.out System System.out semi {
				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 max = 0;
		int semi = 0;
		for (int i = 0; i < n; i++) {
			a[i] = sc.nextInt();
			if (a[i] >= max) {
				semi = max;
				max = a[i];
			} else if (a[i] >= semi) {
				semi = a[i];
			}
		}
		for (int i = 0; i < n; i++) {
			if (a[i] == max) {
				System.out.println(semi);
			} 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 max = 0;
		int semi = 0;
		for (int i = 0; i < n; i++) {
			a[i] = sc.nextInt();
			if (a[i] >= max) {
				semi = max;
				max = a[i];
			} else if (a[i] >= semi) {
				semi = a[i];
			}
		}
		for (int i = 0; i < n; i++) {
			if (a[i] == max) {
				System.out.println(semi);
			} else {
				System.out.println(max);
			}
		}
	}
} Main
import java.util.*;
import java.lang.*;

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 max = 0;
		int semi = 0;
		for (int i = 0; i < n; i++) {
			a[i] = sc.nextInt();
			if (a[i] >= max) {
				semi = max;
				max = a[i];
			} else if (a[i] >= semi) {
				semi = a[i];
			}
		}
		for (int i = 0; i < n; i++) {
			if (a[i] == max) {
				System.out.println(semi);
			} else {
				System.out.println(max);
			}
		}
	}
}