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

public class Main {

	Scanner scan = new Scanner(System.in);
	
	void compute() {
		int n = scan.nextInt();
		
		ArrayList<Integer> list = new ArrayList<>();
		ArrayList<Integer> sorted = new ArrayList<>();
		for (int i=0;i<n;i++) {
			int buf = scan.nextInt();
			list.add(buf);
			sorted.add(buf);
		}
		
		Collections.sort(sorted);
		
		int max = sorted.get(sorted.size()-1);
		int max2 = sorted.get(sorted.size()-2);
		for (int i=0;i<n;i++) {
			System.out.println(list.get(i) != max ? max : max2);
		}
	}
	
	
	public static void main(String...arg) {
		new Main().compute();
	}
} import java.util.ArrayList; ArrayList java.util import java.util.Collections; Collections java.util import java.util.Scanner; Scanner java.util public class Main {

	Scanner scan = new Scanner(System.in);
	
	void compute() {
		int n = scan.nextInt();
		
		ArrayList<Integer> list = new ArrayList<>();
		ArrayList<Integer> sorted = new ArrayList<>();
		for (int i=0;i<n;i++) {
			int buf = scan.nextInt();
			list.add(buf);
			sorted.add(buf);
		}
		
		Collections.sort(sorted);
		
		int max = sorted.get(sorted.size()-1);
		int max2 = sorted.get(sorted.size()-2);
		for (int i=0;i<n;i++) {
			System.out.println(list.get(i) != max ? max : max2);
		}
	}
	
	
	public static void main(String...arg) {
		new Main().compute();
	}
} Main Scanner scan = new Scanner(System.in); scan new Scanner(System.in) void compute() {
		int n = scan.nextInt();
		
		ArrayList<Integer> list = new ArrayList<>();
		ArrayList<Integer> sorted = new ArrayList<>();
		for (int i=0;i<n;i++) {
			int buf = scan.nextInt();
			list.add(buf);
			sorted.add(buf);
		}
		
		Collections.sort(sorted);
		
		int max = sorted.get(sorted.size()-1);
		int max2 = sorted.get(sorted.size()-2);
		for (int i=0;i<n;i++) {
			System.out.println(list.get(i) != max ? max : max2);
		}
	} compute {
		int n = scan.nextInt();
		
		ArrayList<Integer> list = new ArrayList<>();
		ArrayList<Integer> sorted = new ArrayList<>();
		for (int i=0;i<n;i++) {
			int buf = scan.nextInt();
			list.add(buf);
			sorted.add(buf);
		}
		
		Collections.sort(sorted);
		
		int max = sorted.get(sorted.size()-1);
		int max2 = sorted.get(sorted.size()-2);
		for (int i=0;i<n;i++) {
			System.out.println(list.get(i) != max ? max : max2);
		}
	} int n = scan.nextInt(); n scan.nextInt() scan.nextInt scan ArrayList<Integer> list = new ArrayList<>(); list new ArrayList<>() ArrayList<Integer> sorted = new ArrayList<>(); sorted new ArrayList<>() for (int i=0;i<n;i++) {
			int buf = scan.nextInt();
			list.add(buf);
			sorted.add(buf);
		} int i=0; int i=0; i 0 i<n i n i++ i++ i {
			int buf = scan.nextInt();
			list.add(buf);
			sorted.add(buf);
		} {
			int buf = scan.nextInt();
			list.add(buf);
			sorted.add(buf);
		} int buf = scan.nextInt(); buf scan.nextInt() scan.nextInt scan list.add(buf) list.add list buf sorted.add(buf) sorted.add sorted buf Collections.sort(sorted) Collections.sort Collections sorted int max = sorted.get(sorted.size()-1); max sorted.get(sorted.size()-1) sorted.get sorted sorted.size()-1 sorted.size() sorted.size sorted 1 int max2 = sorted.get(sorted.size()-2); max2 sorted.get(sorted.size()-2) sorted.get sorted sorted.size()-2 sorted.size() sorted.size sorted 2 for (int i=0;i<n;i++) {
			System.out.println(list.get(i) != max ? max : max2);
		} int i=0; int i=0; i 0 i<n i n i++ i++ i {
			System.out.println(list.get(i) != max ? max : max2);
		} {
			System.out.println(list.get(i) != max ? max : max2);
		} System.out.println(list.get(i) != max ? max : max2) System.out.println System.out System System.out list.get(i) != max ? max : max2 list.get(i) != max list.get(i) list.get list i max max max2 public static void main(String...arg) {
		new Main().compute();
	} main {
		new Main().compute();
	} new Main().compute() new Main().compute new Main() String...arg arg public class Main {

	Scanner scan = new Scanner(System.in);
	
	void compute() {
		int n = scan.nextInt();
		
		ArrayList<Integer> list = new ArrayList<>();
		ArrayList<Integer> sorted = new ArrayList<>();
		for (int i=0;i<n;i++) {
			int buf = scan.nextInt();
			list.add(buf);
			sorted.add(buf);
		}
		
		Collections.sort(sorted);
		
		int max = sorted.get(sorted.size()-1);
		int max2 = sorted.get(sorted.size()-2);
		for (int i=0;i<n;i++) {
			System.out.println(list.get(i) != max ? max : max2);
		}
	}
	
	
	public static void main(String...arg) {
		new Main().compute();
	}
} public class Main {

	Scanner scan = new Scanner(System.in);
	
	void compute() {
		int n = scan.nextInt();
		
		ArrayList<Integer> list = new ArrayList<>();
		ArrayList<Integer> sorted = new ArrayList<>();
		for (int i=0;i<n;i++) {
			int buf = scan.nextInt();
			list.add(buf);
			sorted.add(buf);
		}
		
		Collections.sort(sorted);
		
		int max = sorted.get(sorted.size()-1);
		int max2 = sorted.get(sorted.size()-2);
		for (int i=0;i<n;i++) {
			System.out.println(list.get(i) != max ? max : max2);
		}
	}
	
	
	public static void main(String...arg) {
		new Main().compute();
	}
} Main

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

public class Main {

	Scanner scan = new Scanner(System.in);
	
	void compute() {
		int n = scan.nextInt();
		
		ArrayList<Integer> list = new ArrayList<>();
		ArrayList<Integer> sorted = new ArrayList<>();
		for (int i=0;i<n;i++) {
			int buf = scan.nextInt();
			list.add(buf);
			sorted.add(buf);
		}
		
		Collections.sort(sorted);
		
		int max = sorted.get(sorted.size()-1);
		int max2 = sorted.get(sorted.size()-2);
		for (int i=0;i<n;i++) {
			System.out.println(list.get(i) != max ? max : max2);
		}
	}
	
	
	public static void main(String...arg) {
		new Main().compute();
	}
}
