import java.util.*;
 
public class Main {
	
    public static void main(String[] args) {
    	Scanner sc = new Scanner(System.in);
    	int N = sc.nextInt();
    	List<Integer> list = new LinkedList<>();
    	int max = 0;
    	int order = 0;
    	for (int i = 0; i < N; i++) {
    		int num = sc.nextInt();
    		if (max < num) {
    			max = num;
    			order = i;
    		}
    		list.add(num);
    	}
    	Collections.sort(list);
    	int submax = list.get(list.size() - 2);
    	StringBuilder sb = new StringBuilder();
    	for (int i = 0; i < N; i++) {
    		if (i == order) {
    			sb.append(submax).append("\n");
    		} else {
    			sb.append(max).append("\n");
    		}
    	}
    	System.out.println(sb);
    }
} import java.util.*; util.* java public class Main {
	
    public static void main(String[] args) {
    	Scanner sc = new Scanner(System.in);
    	int N = sc.nextInt();
    	List<Integer> list = new LinkedList<>();
    	int max = 0;
    	int order = 0;
    	for (int i = 0; i < N; i++) {
    		int num = sc.nextInt();
    		if (max < num) {
    			max = num;
    			order = i;
    		}
    		list.add(num);
    	}
    	Collections.sort(list);
    	int submax = list.get(list.size() - 2);
    	StringBuilder sb = new StringBuilder();
    	for (int i = 0; i < N; i++) {
    		if (i == order) {
    			sb.append(submax).append("\n");
    		} else {
    			sb.append(max).append("\n");
    		}
    	}
    	System.out.println(sb);
    }
} Main public static void main(String[] args) {
    	Scanner sc = new Scanner(System.in);
    	int N = sc.nextInt();
    	List<Integer> list = new LinkedList<>();
    	int max = 0;
    	int order = 0;
    	for (int i = 0; i < N; i++) {
    		int num = sc.nextInt();
    		if (max < num) {
    			max = num;
    			order = i;
    		}
    		list.add(num);
    	}
    	Collections.sort(list);
    	int submax = list.get(list.size() - 2);
    	StringBuilder sb = new StringBuilder();
    	for (int i = 0; i < N; i++) {
    		if (i == order) {
    			sb.append(submax).append("\n");
    		} else {
    			sb.append(max).append("\n");
    		}
    	}
    	System.out.println(sb);
    } main {
    	Scanner sc = new Scanner(System.in);
    	int N = sc.nextInt();
    	List<Integer> list = new LinkedList<>();
    	int max = 0;
    	int order = 0;
    	for (int i = 0; i < N; i++) {
    		int num = sc.nextInt();
    		if (max < num) {
    			max = num;
    			order = i;
    		}
    		list.add(num);
    	}
    	Collections.sort(list);
    	int submax = list.get(list.size() - 2);
    	StringBuilder sb = new StringBuilder();
    	for (int i = 0; i < N; i++) {
    		if (i == order) {
    			sb.append(submax).append("\n");
    		} else {
    			sb.append(max).append("\n");
    		}
    	}
    	System.out.println(sb);
    } Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int N = sc.nextInt(); N sc.nextInt() sc.nextInt sc List<Integer> list = new LinkedList<>(); list new LinkedList<>() int max = 0; max 0 int order = 0; order 0 for (int i = 0; i < N; i++) {
    		int num = sc.nextInt();
    		if (max < num) {
    			max = num;
    			order = i;
    		}
    		list.add(num);
    	} int i = 0; int i = 0; i 0 i < N i N i++ i++ i {
    		int num = sc.nextInt();
    		if (max < num) {
    			max = num;
    			order = i;
    		}
    		list.add(num);
    	} {
    		int num = sc.nextInt();
    		if (max < num) {
    			max = num;
    			order = i;
    		}
    		list.add(num);
    	} int num = sc.nextInt(); num sc.nextInt() sc.nextInt sc if (max < num) {
    			max = num;
    			order = i;
    		} max < num max num {
    			max = num;
    			order = i;
    		} max = num max num order = i order i list.add(num) list.add list num Collections.sort(list) Collections.sort Collections list int submax = list.get(list.size() - 2); submax list.get(list.size() - 2) list.get list list.size() - 2 list.size() list.size list 2 StringBuilder sb = new StringBuilder(); sb new StringBuilder() for (int i = 0; i < N; i++) {
    		if (i == order) {
    			sb.append(submax).append("\n");
    		} else {
    			sb.append(max).append("\n");
    		}
    	} int i = 0; int i = 0; i 0 i < N i N i++ i++ i {
    		if (i == order) {
    			sb.append(submax).append("\n");
    		} else {
    			sb.append(max).append("\n");
    		}
    	} {
    		if (i == order) {
    			sb.append(submax).append("\n");
    		} else {
    			sb.append(max).append("\n");
    		}
    	} if (i == order) {
    			sb.append(submax).append("\n");
    		} else {
    			sb.append(max).append("\n");
    		} i == order i order {
    			sb.append(submax).append("\n");
    		} sb.append(submax).append("\n") sb.append(submax).append sb.append(submax) sb.append sb submax "\n" {
    			sb.append(max).append("\n");
    		} sb.append(max).append("\n") sb.append(max).append sb.append(max) sb.append sb max "\n" System.out.println(sb) System.out.println System.out System System.out sb String[] args args public class Main {
	
    public static void main(String[] args) {
    	Scanner sc = new Scanner(System.in);
    	int N = sc.nextInt();
    	List<Integer> list = new LinkedList<>();
    	int max = 0;
    	int order = 0;
    	for (int i = 0; i < N; i++) {
    		int num = sc.nextInt();
    		if (max < num) {
    			max = num;
    			order = i;
    		}
    		list.add(num);
    	}
    	Collections.sort(list);
    	int submax = list.get(list.size() - 2);
    	StringBuilder sb = new StringBuilder();
    	for (int i = 0; i < N; i++) {
    		if (i == order) {
    			sb.append(submax).append("\n");
    		} else {
    			sb.append(max).append("\n");
    		}
    	}
    	System.out.println(sb);
    }
} public class Main {
	
    public static void main(String[] args) {
    	Scanner sc = new Scanner(System.in);
    	int N = sc.nextInt();
    	List<Integer> list = new LinkedList<>();
    	int max = 0;
    	int order = 0;
    	for (int i = 0; i < N; i++) {
    		int num = sc.nextInt();
    		if (max < num) {
    			max = num;
    			order = i;
    		}
    		list.add(num);
    	}
    	Collections.sort(list);
    	int submax = list.get(list.size() - 2);
    	StringBuilder sb = new StringBuilder();
    	for (int i = 0; i < N; i++) {
    		if (i == order) {
    			sb.append(submax).append("\n");
    		} else {
    			sb.append(max).append("\n");
    		}
    	}
    	System.out.println(sb);
    }
} Main
import java.util.*;
 
public class Main {
	
    public static void main(String[] args) {
    	Scanner sc = new Scanner(System.in);
    	int N = sc.nextInt();
    	List<Integer> list = new LinkedList<>();
    	int max = 0;
    	int order = 0;
    	for (int i = 0; i < N; i++) {
    		int num = sc.nextInt();
    		if (max < num) {
    			max = num;
    			order = i;
    		}
    		list.add(num);
    	}
    	Collections.sort(list);
    	int submax = list.get(list.size() - 2);
    	StringBuilder sb = new StringBuilder();
    	for (int i = 0; i < N; i++) {
    		if (i == order) {
    			sb.append(submax).append("\n");
    		} else {
    			sb.append(max).append("\n");
    		}
    	}
    	System.out.println(sb);
    }
}