import java.util.ArrayList;
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 l = sc.nextInt();

		List<Integer> d = new ArrayList<>();
		for(int i = 0;i < l;i++) {
			d.add(sc.nextInt());
		}

		List<Integer> workD = new ArrayList<>(d);
		Collections.sort(workD, Collections.reverseOrder());
		int max = workD.get(0);
		int nextMax = workD.get(1);

		if(max == nextMax) {
			for(int i = 0;i < l;i++) {
				System.out.println(max);
			}
		}else {
			for(int i = 0;i < l;i++) {
				System.out.println(max == d.get(i) ? nextMax : max);
			}
		}
	}
} import java.util.ArrayList; ArrayList 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 l = sc.nextInt();

		List<Integer> d = new ArrayList<>();
		for(int i = 0;i < l;i++) {
			d.add(sc.nextInt());
		}

		List<Integer> workD = new ArrayList<>(d);
		Collections.sort(workD, Collections.reverseOrder());
		int max = workD.get(0);
		int nextMax = workD.get(1);

		if(max == nextMax) {
			for(int i = 0;i < l;i++) {
				System.out.println(max);
			}
		}else {
			for(int i = 0;i < l;i++) {
				System.out.println(max == d.get(i) ? nextMax : max);
			}
		}
	}
} Main public static void main(String args[]){

		Scanner sc = new Scanner(System.in);
		int l = sc.nextInt();

		List<Integer> d = new ArrayList<>();
		for(int i = 0;i < l;i++) {
			d.add(sc.nextInt());
		}

		List<Integer> workD = new ArrayList<>(d);
		Collections.sort(workD, Collections.reverseOrder());
		int max = workD.get(0);
		int nextMax = workD.get(1);

		if(max == nextMax) {
			for(int i = 0;i < l;i++) {
				System.out.println(max);
			}
		}else {
			for(int i = 0;i < l;i++) {
				System.out.println(max == d.get(i) ? nextMax : max);
			}
		}
	} main {

		Scanner sc = new Scanner(System.in);
		int l = sc.nextInt();

		List<Integer> d = new ArrayList<>();
		for(int i = 0;i < l;i++) {
			d.add(sc.nextInt());
		}

		List<Integer> workD = new ArrayList<>(d);
		Collections.sort(workD, Collections.reverseOrder());
		int max = workD.get(0);
		int nextMax = workD.get(1);

		if(max == nextMax) {
			for(int i = 0;i < l;i++) {
				System.out.println(max);
			}
		}else {
			for(int i = 0;i < l;i++) {
				System.out.println(max == d.get(i) ? nextMax : max);
			}
		}
	} Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int l = sc.nextInt(); l sc.nextInt() sc.nextInt sc List<Integer> d = new ArrayList<>(); d new ArrayList<>() for(int i = 0;i < l;i++) {
			d.add(sc.nextInt());
		} int i = 0; int i = 0; i 0 i < l i l i++ i++ i {
			d.add(sc.nextInt());
		} {
			d.add(sc.nextInt());
		} d.add(sc.nextInt()) d.add d sc.nextInt() sc.nextInt sc List<Integer> workD = new ArrayList<>(d); workD new ArrayList<>(d) Collections.sort(workD, Collections.reverseOrder()) Collections.sort Collections workD Collections.reverseOrder() Collections.reverseOrder Collections int max = workD.get(0); max workD.get(0) workD.get workD 0 int nextMax = workD.get(1); nextMax workD.get(1) workD.get workD 1 if(max == nextMax) {
			for(int i = 0;i < l;i++) {
				System.out.println(max);
			}
		}else {
			for(int i = 0;i < l;i++) {
				System.out.println(max == d.get(i) ? nextMax : max);
			}
		} max == nextMax max nextMax {
			for(int i = 0;i < l;i++) {
				System.out.println(max);
			}
		} for(int i = 0;i < l;i++) {
				System.out.println(max);
			} int i = 0; int i = 0; i 0 i < l i l i++ i++ i {
				System.out.println(max);
			} {
				System.out.println(max);
			} System.out.println(max) System.out.println System.out System System.out max {
			for(int i = 0;i < l;i++) {
				System.out.println(max == d.get(i) ? nextMax : max);
			}
		} for(int i = 0;i < l;i++) {
				System.out.println(max == d.get(i) ? nextMax : max);
			} int i = 0; int i = 0; i 0 i < l i l i++ i++ i {
				System.out.println(max == d.get(i) ? nextMax : max);
			} {
				System.out.println(max == d.get(i) ? nextMax : max);
			} System.out.println(max == d.get(i) ? nextMax : max) System.out.println System.out System System.out max == d.get(i) ? nextMax : max max == d.get(i) max d.get(i) d.get d i nextMax max String args[] args public class Main {
	public static void main(String args[]){

		Scanner sc = new Scanner(System.in);
		int l = sc.nextInt();

		List<Integer> d = new ArrayList<>();
		for(int i = 0;i < l;i++) {
			d.add(sc.nextInt());
		}

		List<Integer> workD = new ArrayList<>(d);
		Collections.sort(workD, Collections.reverseOrder());
		int max = workD.get(0);
		int nextMax = workD.get(1);

		if(max == nextMax) {
			for(int i = 0;i < l;i++) {
				System.out.println(max);
			}
		}else {
			for(int i = 0;i < l;i++) {
				System.out.println(max == d.get(i) ? nextMax : max);
			}
		}
	}
} public class Main {
	public static void main(String args[]){

		Scanner sc = new Scanner(System.in);
		int l = sc.nextInt();

		List<Integer> d = new ArrayList<>();
		for(int i = 0;i < l;i++) {
			d.add(sc.nextInt());
		}

		List<Integer> workD = new ArrayList<>(d);
		Collections.sort(workD, Collections.reverseOrder());
		int max = workD.get(0);
		int nextMax = workD.get(1);

		if(max == nextMax) {
			for(int i = 0;i < l;i++) {
				System.out.println(max);
			}
		}else {
			for(int i = 0;i < l;i++) {
				System.out.println(max == d.get(i) ? nextMax : max);
			}
		}
	}
} Main
import java.util.ArrayList;
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 l = sc.nextInt();

		List<Integer> d = new ArrayList<>();
		for(int i = 0;i < l;i++) {
			d.add(sc.nextInt());
		}

		List<Integer> workD = new ArrayList<>(d);
		Collections.sort(workD, Collections.reverseOrder());
		int max = workD.get(0);
		int nextMax = workD.get(1);

		if(max == nextMax) {
			for(int i = 0;i < l;i++) {
				System.out.println(max);
			}
		}else {
			for(int i = 0;i < l;i++) {
				System.out.println(max == d.get(i) ? nextMax : max);
			}
		}
	}
}
