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


public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		ArrayList<Integer> originalList = new ArrayList();
		for(int i = 0; i < n; i++) {
			int number = sc.nextInt();
			originalList.add(number);
		}
		ArrayList<Integer> sortedList = (ArrayList<Integer>) originalList.clone();
		Collections.sort(sortedList);
		int maxNumber = sortedList.get(n - 1);
		int secondNumber = sortedList.get(n - 2);
		
		for(int i = 0; i < n; i++) {
			int t = originalList.get(i);
			if(originalList.get(i).equals(maxNumber)) {
				System.out.println(secondNumber);
			}else {
				System.out.println(maxNumber);
			}

		}
		

		
		

		
		
	}	

}
 import java.util.ArrayList; ArrayList java.util import java.util.Collection; Collection java.util import java.util.Collections; Collections java.util import java.util.List; List 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();
		ArrayList<Integer> originalList = new ArrayList();
		for(int i = 0; i < n; i++) {
			int number = sc.nextInt();
			originalList.add(number);
		}
		ArrayList<Integer> sortedList = (ArrayList<Integer>) originalList.clone();
		Collections.sort(sortedList);
		int maxNumber = sortedList.get(n - 1);
		int secondNumber = sortedList.get(n - 2);
		
		for(int i = 0; i < n; i++) {
			int t = originalList.get(i);
			if(originalList.get(i).equals(maxNumber)) {
				System.out.println(secondNumber);
			}else {
				System.out.println(maxNumber);
			}

		}
		

		
		

		
		
	}	

} Main public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		ArrayList<Integer> originalList = new ArrayList();
		for(int i = 0; i < n; i++) {
			int number = sc.nextInt();
			originalList.add(number);
		}
		ArrayList<Integer> sortedList = (ArrayList<Integer>) originalList.clone();
		Collections.sort(sortedList);
		int maxNumber = sortedList.get(n - 1);
		int secondNumber = sortedList.get(n - 2);
		
		for(int i = 0; i < n; i++) {
			int t = originalList.get(i);
			if(originalList.get(i).equals(maxNumber)) {
				System.out.println(secondNumber);
			}else {
				System.out.println(maxNumber);
			}

		}
		

		
		

		
		
	} main {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		ArrayList<Integer> originalList = new ArrayList();
		for(int i = 0; i < n; i++) {
			int number = sc.nextInt();
			originalList.add(number);
		}
		ArrayList<Integer> sortedList = (ArrayList<Integer>) originalList.clone();
		Collections.sort(sortedList);
		int maxNumber = sortedList.get(n - 1);
		int secondNumber = sortedList.get(n - 2);
		
		for(int i = 0; i < n; i++) {
			int t = originalList.get(i);
			if(originalList.get(i).equals(maxNumber)) {
				System.out.println(secondNumber);
			}else {
				System.out.println(maxNumber);
			}

		}
		

		
		

		
		
	} Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int n = sc.nextInt(); n sc.nextInt() sc.nextInt sc ArrayList<Integer> originalList = new ArrayList(); originalList new ArrayList() for(int i = 0; i < n; i++) {
			int number = sc.nextInt();
			originalList.add(number);
		} int i = 0; int i = 0; i 0 i < n i n i++ i++ i {
			int number = sc.nextInt();
			originalList.add(number);
		} {
			int number = sc.nextInt();
			originalList.add(number);
		} int number = sc.nextInt(); number sc.nextInt() sc.nextInt sc originalList.add(number) originalList.add originalList number ArrayList<Integer> sortedList = (ArrayList<Integer>) originalList.clone(); sortedList (ArrayList<Integer>) originalList.clone() originalList.clone originalList Collections.sort(sortedList) Collections.sort Collections sortedList int maxNumber = sortedList.get(n - 1); maxNumber sortedList.get(n - 1) sortedList.get sortedList n - 1 n 1 int secondNumber = sortedList.get(n - 2); secondNumber sortedList.get(n - 2) sortedList.get sortedList n - 2 n 2 for(int i = 0; i < n; i++) {
			int t = originalList.get(i);
			if(originalList.get(i).equals(maxNumber)) {
				System.out.println(secondNumber);
			}else {
				System.out.println(maxNumber);
			}

		} int i = 0; int i = 0; i 0 i < n i n i++ i++ i {
			int t = originalList.get(i);
			if(originalList.get(i).equals(maxNumber)) {
				System.out.println(secondNumber);
			}else {
				System.out.println(maxNumber);
			}

		} {
			int t = originalList.get(i);
			if(originalList.get(i).equals(maxNumber)) {
				System.out.println(secondNumber);
			}else {
				System.out.println(maxNumber);
			}

		} int t = originalList.get(i); t originalList.get(i) originalList.get originalList i if(originalList.get(i).equals(maxNumber)) {
				System.out.println(secondNumber);
			}else {
				System.out.println(maxNumber);
			} originalList.get(i).equals(maxNumber) originalList.get(i).equals originalList.get(i) originalList.get originalList i maxNumber {
				System.out.println(secondNumber);
			} System.out.println(secondNumber) System.out.println System.out System System.out secondNumber {
				System.out.println(maxNumber);
			} System.out.println(maxNumber) System.out.println System.out System System.out maxNumber String[] args args public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		ArrayList<Integer> originalList = new ArrayList();
		for(int i = 0; i < n; i++) {
			int number = sc.nextInt();
			originalList.add(number);
		}
		ArrayList<Integer> sortedList = (ArrayList<Integer>) originalList.clone();
		Collections.sort(sortedList);
		int maxNumber = sortedList.get(n - 1);
		int secondNumber = sortedList.get(n - 2);
		
		for(int i = 0; i < n; i++) {
			int t = originalList.get(i);
			if(originalList.get(i).equals(maxNumber)) {
				System.out.println(secondNumber);
			}else {
				System.out.println(maxNumber);
			}

		}
		

		
		

		
		
	}	

} public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		ArrayList<Integer> originalList = new ArrayList();
		for(int i = 0; i < n; i++) {
			int number = sc.nextInt();
			originalList.add(number);
		}
		ArrayList<Integer> sortedList = (ArrayList<Integer>) originalList.clone();
		Collections.sort(sortedList);
		int maxNumber = sortedList.get(n - 1);
		int secondNumber = sortedList.get(n - 2);
		
		for(int i = 0; i < n; i++) {
			int t = originalList.get(i);
			if(originalList.get(i).equals(maxNumber)) {
				System.out.println(secondNumber);
			}else {
				System.out.println(maxNumber);
			}

		}
		

		
		

		
		
	}	

} Main

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


public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		ArrayList<Integer> originalList = new ArrayList();
		for(int i = 0; i < n; i++) {
			int number = sc.nextInt();
			originalList.add(number);
		}
		ArrayList<Integer> sortedList = (ArrayList<Integer>) originalList.clone();
		Collections.sort(sortedList);
		int maxNumber = sortedList.get(n - 1);
		int secondNumber = sortedList.get(n - 2);
		
		for(int i = 0; i < n; i++) {
			int t = originalList.get(i);
			if(originalList.get(i).equals(maxNumber)) {
				System.out.println(secondNumber);
			}else {
				System.out.println(maxNumber);
			}

		}
		

		
		

		
		
	}	

}

