
import java.util.Scanner;

public class Main {
    
	public static void main(String[] args) {
		
        Scanner s = new Scanner (System.in);
        int n = s.nextInt();
        int[] a = new int[n];
        
        int max = 0;
        int max2 = 0;
        
        for (int i = 0; i < n; i ++) {
        	a[i] = s.nextInt();
        	if (a[i] > max) {
        		max2 = max;
        		max = a[i];
        	} else if (a[i] > max2 && a[i] <= max)
        		max2 = a[i];
        }
        
        for (int i : a) {
        	if (i == max)
        		System.out.println(max2);
        	else
        		System.out.println(max);
        }
        
	}
} import java.util.Scanner; Scanner java.util public class Main {
    
	public static void main(String[] args) {
		
        Scanner s = new Scanner (System.in);
        int n = s.nextInt();
        int[] a = new int[n];
        
        int max = 0;
        int max2 = 0;
        
        for (int i = 0; i < n; i ++) {
        	a[i] = s.nextInt();
        	if (a[i] > max) {
        		max2 = max;
        		max = a[i];
        	} else if (a[i] > max2 && a[i] <= max)
        		max2 = a[i];
        }
        
        for (int i : a) {
        	if (i == max)
        		System.out.println(max2);
        	else
        		System.out.println(max);
        }
        
	}
} Main public static void main(String[] args) {
		
        Scanner s = new Scanner (System.in);
        int n = s.nextInt();
        int[] a = new int[n];
        
        int max = 0;
        int max2 = 0;
        
        for (int i = 0; i < n; i ++) {
        	a[i] = s.nextInt();
        	if (a[i] > max) {
        		max2 = max;
        		max = a[i];
        	} else if (a[i] > max2 && a[i] <= max)
        		max2 = a[i];
        }
        
        for (int i : a) {
        	if (i == max)
        		System.out.println(max2);
        	else
        		System.out.println(max);
        }
        
	} main {
		
        Scanner s = new Scanner (System.in);
        int n = s.nextInt();
        int[] a = new int[n];
        
        int max = 0;
        int max2 = 0;
        
        for (int i = 0; i < n; i ++) {
        	a[i] = s.nextInt();
        	if (a[i] > max) {
        		max2 = max;
        		max = a[i];
        	} else if (a[i] > max2 && a[i] <= max)
        		max2 = a[i];
        }
        
        for (int i : a) {
        	if (i == max)
        		System.out.println(max2);
        	else
        		System.out.println(max);
        }
        
	} Scanner s = new Scanner (System.in); s new Scanner (System.in) int n = s.nextInt(); n s.nextInt() s.nextInt s int[] a = new int[n]; a new int[n] n int max = 0; max 0 int max2 = 0; max2 0 for (int i = 0; i < n; i ++) {
        	a[i] = s.nextInt();
        	if (a[i] > max) {
        		max2 = max;
        		max = a[i];
        	} else if (a[i] > max2 && a[i] <= max)
        		max2 = a[i];
        } int i = 0; int i = 0; i 0 i < n i n i ++ i ++ i {
        	a[i] = s.nextInt();
        	if (a[i] > max) {
        		max2 = max;
        		max = a[i];
        	} else if (a[i] > max2 && a[i] <= max)
        		max2 = a[i];
        } {
        	a[i] = s.nextInt();
        	if (a[i] > max) {
        		max2 = max;
        		max = a[i];
        	} else if (a[i] > max2 && a[i] <= max)
        		max2 = a[i];
        } a[i] = s.nextInt() a[i] a i s.nextInt() s.nextInt s if (a[i] > max) {
        		max2 = max;
        		max = a[i];
        	} else if (a[i] > max2 && a[i] <= max)
        		max2 = a[i]; a[i] > max a[i] a i max {
        		max2 = max;
        		max = a[i];
        	} max2 = max max2 max max = a[i] max a[i] a i if (a[i] > max2 && a[i] <= max)
        		max2 = a[i]; a[i] > max2 && a[i] <= max a[i] > max2 a[i] a i max2 a[i] <= max a[i] a i max max2 = a[i] max2 a[i] a i for (int i : a) {
        	if (i == max)
        		System.out.println(max2);
        	else
        		System.out.println(max);
        } int i a {
        	if (i == max)
        		System.out.println(max2);
        	else
        		System.out.println(max);
        } {
        	if (i == max)
        		System.out.println(max2);
        	else
        		System.out.println(max);
        } if (i == max)
        		System.out.println(max2);
        	else
        		System.out.println(max); i == max i max System.out.println(max2) System.out.println System.out System System.out max2 System.out.println(max) System.out.println System.out System System.out max String[] args args public class Main {
    
	public static void main(String[] args) {
		
        Scanner s = new Scanner (System.in);
        int n = s.nextInt();
        int[] a = new int[n];
        
        int max = 0;
        int max2 = 0;
        
        for (int i = 0; i < n; i ++) {
        	a[i] = s.nextInt();
        	if (a[i] > max) {
        		max2 = max;
        		max = a[i];
        	} else if (a[i] > max2 && a[i] <= max)
        		max2 = a[i];
        }
        
        for (int i : a) {
        	if (i == max)
        		System.out.println(max2);
        	else
        		System.out.println(max);
        }
        
	}
} public class Main {
    
	public static void main(String[] args) {
		
        Scanner s = new Scanner (System.in);
        int n = s.nextInt();
        int[] a = new int[n];
        
        int max = 0;
        int max2 = 0;
        
        for (int i = 0; i < n; i ++) {
        	a[i] = s.nextInt();
        	if (a[i] > max) {
        		max2 = max;
        		max = a[i];
        	} else if (a[i] > max2 && a[i] <= max)
        		max2 = a[i];
        }
        
        for (int i : a) {
        	if (i == max)
        		System.out.println(max2);
        	else
        		System.out.println(max);
        }
        
	}
} Main

import java.util.Scanner;

public class Main {
    
	public static void main(String[] args) {
		
        Scanner s = new Scanner (System.in);
        int n = s.nextInt();
        int[] a = new int[n];
        
        int max = 0;
        int max2 = 0;
        
        for (int i = 0; i < n; i ++) {
        	a[i] = s.nextInt();
        	if (a[i] > max) {
        		max2 = max;
        		max = a[i];
        	} else if (a[i] > max2 && a[i] <= max)
        		max2 = a[i];
        }
        
        for (int i : a) {
        	if (i == max)
        		System.out.println(max2);
        	else
        		System.out.println(max);
        }
        
	}
}