import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int max = 0, pmax = 0;
		int n = sc.nextInt();
		int pos=0,flag=0;
		int a[] = new int[n];
		for (int i = 0; i < n; i++) {
			a[i] = sc.nextInt();
			max = Math.max(max, a[i]);
		}
		for (int i = 0; i < n; i++) {
			if(a[i]==max&&flag==0) {
			pos=i;
			flag=1;
			break;
			}
		}
		for (int i = 0; i < n; i++)if (i!=pos)pmax = Math.max(pmax, a[i]);
		int i;
		for (i = 0; i < n; i++) {
			if(pmax==max){
				System.out.println(max);
			}else  {
				if (max == a[i])System.out.println(pmax);
				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 max = 0, pmax = 0;
		int n = sc.nextInt();
		int pos=0,flag=0;
		int a[] = new int[n];
		for (int i = 0; i < n; i++) {
			a[i] = sc.nextInt();
			max = Math.max(max, a[i]);
		}
		for (int i = 0; i < n; i++) {
			if(a[i]==max&&flag==0) {
			pos=i;
			flag=1;
			break;
			}
		}
		for (int i = 0; i < n; i++)if (i!=pos)pmax = Math.max(pmax, a[i]);
		int i;
		for (i = 0; i < n; i++) {
			if(pmax==max){
				System.out.println(max);
			}else  {
				if (max == a[i])System.out.println(pmax);
				else System.out.println(max);
			}  
		}
	}
} Main public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int max = 0, pmax = 0;
		int n = sc.nextInt();
		int pos=0,flag=0;
		int a[] = new int[n];
		for (int i = 0; i < n; i++) {
			a[i] = sc.nextInt();
			max = Math.max(max, a[i]);
		}
		for (int i = 0; i < n; i++) {
			if(a[i]==max&&flag==0) {
			pos=i;
			flag=1;
			break;
			}
		}
		for (int i = 0; i < n; i++)if (i!=pos)pmax = Math.max(pmax, a[i]);
		int i;
		for (i = 0; i < n; i++) {
			if(pmax==max){
				System.out.println(max);
			}else  {
				if (max == a[i])System.out.println(pmax);
				else System.out.println(max);
			}  
		}
	} main {
		Scanner sc = new Scanner(System.in);
		int max = 0, pmax = 0;
		int n = sc.nextInt();
		int pos=0,flag=0;
		int a[] = new int[n];
		for (int i = 0; i < n; i++) {
			a[i] = sc.nextInt();
			max = Math.max(max, a[i]);
		}
		for (int i = 0; i < n; i++) {
			if(a[i]==max&&flag==0) {
			pos=i;
			flag=1;
			break;
			}
		}
		for (int i = 0; i < n; i++)if (i!=pos)pmax = Math.max(pmax, a[i]);
		int i;
		for (i = 0; i < n; i++) {
			if(pmax==max){
				System.out.println(max);
			}else  {
				if (max == a[i])System.out.println(pmax);
				else System.out.println(max);
			}  
		}
	} Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int max = 0 max 0 pmax = 0; pmax 0 int n = sc.nextInt(); n sc.nextInt() sc.nextInt sc int pos=0 pos 0 flag=0; flag 0 int a[] = new int[n]; a new int[n] n for (int i = 0; i < n; i++) {
			a[i] = sc.nextInt();
			max = Math.max(max, a[i]);
		} int i = 0; int i = 0; i 0 i < n i n i++ i++ i {
			a[i] = sc.nextInt();
			max = Math.max(max, a[i]);
		} {
			a[i] = sc.nextInt();
			max = Math.max(max, a[i]);
		} a[i] = sc.nextInt() a[i] a i sc.nextInt() sc.nextInt sc max = Math.max(max, a[i]) max Math.max(max, a[i]) Math.max Math max a[i] a i for (int i = 0; i < n; i++) {
			if(a[i]==max&&flag==0) {
			pos=i;
			flag=1;
			break;
			}
		} int i = 0; int i = 0; i 0 i < n i n i++ i++ i {
			if(a[i]==max&&flag==0) {
			pos=i;
			flag=1;
			break;
			}
		} {
			if(a[i]==max&&flag==0) {
			pos=i;
			flag=1;
			break;
			}
		} if(a[i]==max&&flag==0) {
			pos=i;
			flag=1;
			break;
			} a[i]==max&&flag==0 a[i]==max a[i] a i max flag==0 flag 0 {
			pos=i;
			flag=1;
			break;
			} pos=i pos i flag=1 flag 1 break; for (int i = 0; i < n; i++)if (i!=pos)pmax = Math.max(pmax, a[i]); int i = 0; int i = 0; i 0 i < n i n i++ i++ i if (i!=pos)pmax = Math.max(pmax, a[i]); if (i!=pos)pmax = Math.max(pmax, a[i]); i!=pos i pos pmax = Math.max(pmax, a[i]) pmax Math.max(pmax, a[i]) Math.max Math pmax a[i] a i int i; i for (i = 0; i < n; i++) {
			if(pmax==max){
				System.out.println(max);
			}else  {
				if (max == a[i])System.out.println(pmax);
				else System.out.println(max);
			}  
		} i = 0; i = 0 i 0 i < n i n i++ i++ i {
			if(pmax==max){
				System.out.println(max);
			}else  {
				if (max == a[i])System.out.println(pmax);
				else System.out.println(max);
			}  
		} {
			if(pmax==max){
				System.out.println(max);
			}else  {
				if (max == a[i])System.out.println(pmax);
				else System.out.println(max);
			}  
		} if(pmax==max){
				System.out.println(max);
			}else  {
				if (max == a[i])System.out.println(pmax);
				else System.out.println(max);
			} pmax==max pmax max {
				System.out.println(max);
			} System.out.println(max) System.out.println System.out System System.out max {
				if (max == a[i])System.out.println(pmax);
				else System.out.println(max);
			} if (max == a[i])System.out.println(pmax);
				else System.out.println(max); max == a[i] max a[i] a i System.out.println(pmax) System.out.println System.out System System.out pmax 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 max = 0, pmax = 0;
		int n = sc.nextInt();
		int pos=0,flag=0;
		int a[] = new int[n];
		for (int i = 0; i < n; i++) {
			a[i] = sc.nextInt();
			max = Math.max(max, a[i]);
		}
		for (int i = 0; i < n; i++) {
			if(a[i]==max&&flag==0) {
			pos=i;
			flag=1;
			break;
			}
		}
		for (int i = 0; i < n; i++)if (i!=pos)pmax = Math.max(pmax, a[i]);
		int i;
		for (i = 0; i < n; i++) {
			if(pmax==max){
				System.out.println(max);
			}else  {
				if (max == a[i])System.out.println(pmax);
				else System.out.println(max);
			}  
		}
	}
} public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int max = 0, pmax = 0;
		int n = sc.nextInt();
		int pos=0,flag=0;
		int a[] = new int[n];
		for (int i = 0; i < n; i++) {
			a[i] = sc.nextInt();
			max = Math.max(max, a[i]);
		}
		for (int i = 0; i < n; i++) {
			if(a[i]==max&&flag==0) {
			pos=i;
			flag=1;
			break;
			}
		}
		for (int i = 0; i < n; i++)if (i!=pos)pmax = Math.max(pmax, a[i]);
		int i;
		for (i = 0; i < n; i++) {
			if(pmax==max){
				System.out.println(max);
			}else  {
				if (max == a[i])System.out.println(pmax);
				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 max = 0, pmax = 0;
		int n = sc.nextInt();
		int pos=0,flag=0;
		int a[] = new int[n];
		for (int i = 0; i < n; i++) {
			a[i] = sc.nextInt();
			max = Math.max(max, a[i]);
		}
		for (int i = 0; i < n; i++) {
			if(a[i]==max&&flag==0) {
			pos=i;
			flag=1;
			break;
			}
		}
		for (int i = 0; i < n; i++)if (i!=pos)pmax = Math.max(pmax, a[i]);
		int i;
		for (i = 0; i < n; i++) {
			if(pmax==max){
				System.out.println(max);
			}else  {
				if (max == a[i])System.out.println(pmax);
				else System.out.println(max);
			}  
		}
	}
}