import java.util.ArrayList;
import java.util.Collections;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int size= sc.nextInt();
		int largest = 1;
		int second  = 0;
		int[] arr = new int[size];
		for(int i = 0;i<size;i++) {
			arr[i]=sc.nextInt();
			if(arr[i]>largest)largest=arr[i];
			else if(arr[i]>second)second = arr[i];
		}
		for(int i = 0;i<size;i++) {
			if(arr[i]==largest)System.out.println(second);
			else System.out.println(largest);
		}
		
	}
} import java.util.ArrayList; ArrayList 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 size= sc.nextInt();
		int largest = 1;
		int second  = 0;
		int[] arr = new int[size];
		for(int i = 0;i<size;i++) {
			arr[i]=sc.nextInt();
			if(arr[i]>largest)largest=arr[i];
			else if(arr[i]>second)second = arr[i];
		}
		for(int i = 0;i<size;i++) {
			if(arr[i]==largest)System.out.println(second);
			else System.out.println(largest);
		}
		
	}
} Main public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int size= sc.nextInt();
		int largest = 1;
		int second  = 0;
		int[] arr = new int[size];
		for(int i = 0;i<size;i++) {
			arr[i]=sc.nextInt();
			if(arr[i]>largest)largest=arr[i];
			else if(arr[i]>second)second = arr[i];
		}
		for(int i = 0;i<size;i++) {
			if(arr[i]==largest)System.out.println(second);
			else System.out.println(largest);
		}
		
	} main {
		Scanner sc = new Scanner(System.in);
		int size= sc.nextInt();
		int largest = 1;
		int second  = 0;
		int[] arr = new int[size];
		for(int i = 0;i<size;i++) {
			arr[i]=sc.nextInt();
			if(arr[i]>largest)largest=arr[i];
			else if(arr[i]>second)second = arr[i];
		}
		for(int i = 0;i<size;i++) {
			if(arr[i]==largest)System.out.println(second);
			else System.out.println(largest);
		}
		
	} Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int size= sc.nextInt(); size sc.nextInt() sc.nextInt sc int largest = 1; largest 1 int second  = 0; second 0 int[] arr = new int[size]; arr new int[size] size for(int i = 0;i<size;i++) {
			arr[i]=sc.nextInt();
			if(arr[i]>largest)largest=arr[i];
			else if(arr[i]>second)second = arr[i];
		} int i = 0; int i = 0; i 0 i<size i size i++ i++ i {
			arr[i]=sc.nextInt();
			if(arr[i]>largest)largest=arr[i];
			else if(arr[i]>second)second = arr[i];
		} {
			arr[i]=sc.nextInt();
			if(arr[i]>largest)largest=arr[i];
			else if(arr[i]>second)second = arr[i];
		} arr[i]=sc.nextInt() arr[i] arr i sc.nextInt() sc.nextInt sc if(arr[i]>largest)largest=arr[i];
			else if(arr[i]>second)second = arr[i]; arr[i]>largest arr[i] arr i largest largest=arr[i] largest arr[i] arr i if(arr[i]>second)second = arr[i]; arr[i]>second arr[i] arr i second second = arr[i] second arr[i] arr i for(int i = 0;i<size;i++) {
			if(arr[i]==largest)System.out.println(second);
			else System.out.println(largest);
		} int i = 0; int i = 0; i 0 i<size i size i++ i++ i {
			if(arr[i]==largest)System.out.println(second);
			else System.out.println(largest);
		} {
			if(arr[i]==largest)System.out.println(second);
			else System.out.println(largest);
		} if(arr[i]==largest)System.out.println(second);
			else System.out.println(largest); arr[i]==largest arr[i] arr i largest System.out.println(second) System.out.println System.out System System.out second System.out.println(largest) System.out.println System.out System System.out largest String[] args args public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int size= sc.nextInt();
		int largest = 1;
		int second  = 0;
		int[] arr = new int[size];
		for(int i = 0;i<size;i++) {
			arr[i]=sc.nextInt();
			if(arr[i]>largest)largest=arr[i];
			else if(arr[i]>second)second = arr[i];
		}
		for(int i = 0;i<size;i++) {
			if(arr[i]==largest)System.out.println(second);
			else System.out.println(largest);
		}
		
	}
} public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int size= sc.nextInt();
		int largest = 1;
		int second  = 0;
		int[] arr = new int[size];
		for(int i = 0;i<size;i++) {
			arr[i]=sc.nextInt();
			if(arr[i]>largest)largest=arr[i];
			else if(arr[i]>second)second = arr[i];
		}
		for(int i = 0;i<size;i++) {
			if(arr[i]==largest)System.out.println(second);
			else System.out.println(largest);
		}
		
	}
} Main
import java.util.ArrayList;
import java.util.Collections;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int size= sc.nextInt();
		int largest = 1;
		int second  = 0;
		int[] arr = new int[size];
		for(int i = 0;i<size;i++) {
			arr[i]=sc.nextInt();
			if(arr[i]>largest)largest=arr[i];
			else if(arr[i]>second)second = arr[i];
		}
		for(int i = 0;i<size;i++) {
			if(arr[i]==largest)System.out.println(second);
			else System.out.println(largest);
		}
		
	}
}
