import java.util.*; 

class Main{
public static void main(String[] args){
	Scanner sc=new Scanner(System.in);
        int n=sc.nextInt();

  		int[] a=new int[n];
		for(int c=0;c<n;c++){
    		a[c]=sc.nextInt();
    	}
  		int[] b=a.clone();
  		Arrays.sort(b);
  		int max1=b[n-1];
  		int max2=b[n-2];
  		
  		
    for(int e=0;e<n;e++){
 	if(a[e]==max1){
    		System.out.println(max2);
    	}else{
     		System.out.println(max1);
   	 }
    }
    }
}
 import java.util.*; util.* java class Main{
public static void main(String[] args){
	Scanner sc=new Scanner(System.in);
        int n=sc.nextInt();

  		int[] a=new int[n];
		for(int c=0;c<n;c++){
    		a[c]=sc.nextInt();
    	}
  		int[] b=a.clone();
  		Arrays.sort(b);
  		int max1=b[n-1];
  		int max2=b[n-2];
  		
  		
    for(int e=0;e<n;e++){
 	if(a[e]==max1){
    		System.out.println(max2);
    	}else{
     		System.out.println(max1);
   	 }
    }
    }
} Main public static void main(String[] args){
	Scanner sc=new Scanner(System.in);
        int n=sc.nextInt();

  		int[] a=new int[n];
		for(int c=0;c<n;c++){
    		a[c]=sc.nextInt();
    	}
  		int[] b=a.clone();
  		Arrays.sort(b);
  		int max1=b[n-1];
  		int max2=b[n-2];
  		
  		
    for(int e=0;e<n;e++){
 	if(a[e]==max1){
    		System.out.println(max2);
    	}else{
     		System.out.println(max1);
   	 }
    }
    } main {
	Scanner sc=new Scanner(System.in);
        int n=sc.nextInt();

  		int[] a=new int[n];
		for(int c=0;c<n;c++){
    		a[c]=sc.nextInt();
    	}
  		int[] b=a.clone();
  		Arrays.sort(b);
  		int max1=b[n-1];
  		int max2=b[n-2];
  		
  		
    for(int e=0;e<n;e++){
 	if(a[e]==max1){
    		System.out.println(max2);
    	}else{
     		System.out.println(max1);
   	 }
    }
    } Scanner sc=new Scanner(System.in); sc new Scanner(System.in) int n=sc.nextInt(); n sc.nextInt() sc.nextInt sc int[] a=new int[n]; a new int[n] n for(int c=0;c<n;c++){
    		a[c]=sc.nextInt();
    	} int c=0; int c=0; c 0 c<n c n c++ c++ c {
    		a[c]=sc.nextInt();
    	} {
    		a[c]=sc.nextInt();
    	} a[c]=sc.nextInt() a[c] a c sc.nextInt() sc.nextInt sc int[] b=a.clone(); b a.clone() a.clone a Arrays.sort(b) Arrays.sort Arrays b int max1=b[n-1]; max1 b[n-1] b n-1 n 1 int max2=b[n-2]; max2 b[n-2] b n-2 n 2 for(int e=0;e<n;e++){
 	if(a[e]==max1){
    		System.out.println(max2);
    	}else{
     		System.out.println(max1);
   	 }
    } int e=0; int e=0; e 0 e<n e n e++ e++ e {
 	if(a[e]==max1){
    		System.out.println(max2);
    	}else{
     		System.out.println(max1);
   	 }
    } {
 	if(a[e]==max1){
    		System.out.println(max2);
    	}else{
     		System.out.println(max1);
   	 }
    } if(a[e]==max1){
    		System.out.println(max2);
    	}else{
     		System.out.println(max1);
   	 } a[e]==max1 a[e] a e max1 {
    		System.out.println(max2);
    	} System.out.println(max2) System.out.println System.out System System.out max2 {
     		System.out.println(max1);
   	 } System.out.println(max1) System.out.println System.out System System.out max1 String[] args args
import java.util.*; 

class Main{
public static void main(String[] args){
	Scanner sc=new Scanner(System.in);
        int n=sc.nextInt();

  		int[] a=new int[n];
		for(int c=0;c<n;c++){
    		a[c]=sc.nextInt();
    	}
  		int[] b=a.clone();
  		Arrays.sort(b);
  		int max1=b[n-1];
  		int max2=b[n-2];
  		
  		
    for(int e=0;e<n;e++){
 	if(a[e]==max1){
    		System.out.println(max2);
    	}else{
     		System.out.println(max1);
   	 }
    }
    }
}

