import java.util.Scanner;
public class Main{
 public static void main(String[] args){
   Scanner sc = new Scanner(System.in);
   int N = sc.nextInt();
   int[] An = new int[N];
   for(int i =0;i<N;i++){
   An[i] = sc.nextInt();
   }
   int max = 0;
   int max2 = 0;
   if(An[0]<=An[1]){
   max = An[1];
   max2 = An[0];
   }else{
   max = An[0];
   max2 = An[1];
   }
     
   
   for(int i =2;i<N;i++){
    if(max<=An[i]){
      max2 = max;
      max = An[i];
    }else if(max2<=An[i]) max2 = An[i];
   }
   for(int i = 0;i <N; i++){
     if(An[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 sc = new Scanner(System.in);
   int N = sc.nextInt();
   int[] An = new int[N];
   for(int i =0;i<N;i++){
   An[i] = sc.nextInt();
   }
   int max = 0;
   int max2 = 0;
   if(An[0]<=An[1]){
   max = An[1];
   max2 = An[0];
   }else{
   max = An[0];
   max2 = An[1];
   }
     
   
   for(int i =2;i<N;i++){
    if(max<=An[i]){
      max2 = max;
      max = An[i];
    }else if(max2<=An[i]) max2 = An[i];
   }
   for(int i = 0;i <N; i++){
     if(An[i]==max) System.out.println(max2);
     else System.out.println(max);
   }

 }
} Main public static void main(String[] args){
   Scanner sc = new Scanner(System.in);
   int N = sc.nextInt();
   int[] An = new int[N];
   for(int i =0;i<N;i++){
   An[i] = sc.nextInt();
   }
   int max = 0;
   int max2 = 0;
   if(An[0]<=An[1]){
   max = An[1];
   max2 = An[0];
   }else{
   max = An[0];
   max2 = An[1];
   }
     
   
   for(int i =2;i<N;i++){
    if(max<=An[i]){
      max2 = max;
      max = An[i];
    }else if(max2<=An[i]) max2 = An[i];
   }
   for(int i = 0;i <N; i++){
     if(An[i]==max) System.out.println(max2);
     else System.out.println(max);
   }

 } main {
   Scanner sc = new Scanner(System.in);
   int N = sc.nextInt();
   int[] An = new int[N];
   for(int i =0;i<N;i++){
   An[i] = sc.nextInt();
   }
   int max = 0;
   int max2 = 0;
   if(An[0]<=An[1]){
   max = An[1];
   max2 = An[0];
   }else{
   max = An[0];
   max2 = An[1];
   }
     
   
   for(int i =2;i<N;i++){
    if(max<=An[i]){
      max2 = max;
      max = An[i];
    }else if(max2<=An[i]) max2 = An[i];
   }
   for(int i = 0;i <N; i++){
     if(An[i]==max) System.out.println(max2);
     else System.out.println(max);
   }

 } Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int N = sc.nextInt(); N sc.nextInt() sc.nextInt sc int[] An = new int[N]; An new int[N] N for(int i =0;i<N;i++){
   An[i] = sc.nextInt();
   } int i =0; int i =0; i 0 i<N i N i++ i++ i {
   An[i] = sc.nextInt();
   } {
   An[i] = sc.nextInt();
   } An[i] = sc.nextInt() An[i] An i sc.nextInt() sc.nextInt sc int max = 0; max 0 int max2 = 0; max2 0 if(An[0]<=An[1]){
   max = An[1];
   max2 = An[0];
   }else{
   max = An[0];
   max2 = An[1];
   } An[0]<=An[1] An[0] An 0 An[1] An 1 {
   max = An[1];
   max2 = An[0];
   } max = An[1] max An[1] An 1 max2 = An[0] max2 An[0] An 0 {
   max = An[0];
   max2 = An[1];
   } max = An[0] max An[0] An 0 max2 = An[1] max2 An[1] An 1 for(int i =2;i<N;i++){
    if(max<=An[i]){
      max2 = max;
      max = An[i];
    }else if(max2<=An[i]) max2 = An[i];
   } int i =2; int i =2; i 2 i<N i N i++ i++ i {
    if(max<=An[i]){
      max2 = max;
      max = An[i];
    }else if(max2<=An[i]) max2 = An[i];
   } {
    if(max<=An[i]){
      max2 = max;
      max = An[i];
    }else if(max2<=An[i]) max2 = An[i];
   } if(max<=An[i]){
      max2 = max;
      max = An[i];
    }else if(max2<=An[i]) max2 = An[i]; max<=An[i] max An[i] An i {
      max2 = max;
      max = An[i];
    } max2 = max max2 max max = An[i] max An[i] An i if(max2<=An[i]) max2 = An[i]; max2<=An[i] max2 An[i] An i max2 = An[i] max2 An[i] An i for(int i = 0;i <N; i++){
     if(An[i]==max) System.out.println(max2);
     else System.out.println(max);
   } int i = 0; int i = 0; i 0 i <N i N i++ i++ i {
     if(An[i]==max) System.out.println(max2);
     else System.out.println(max);
   } {
     if(An[i]==max) System.out.println(max2);
     else System.out.println(max);
   } if(An[i]==max) System.out.println(max2);
     else System.out.println(max); An[i]==max An[i] An 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 sc = new Scanner(System.in);
   int N = sc.nextInt();
   int[] An = new int[N];
   for(int i =0;i<N;i++){
   An[i] = sc.nextInt();
   }
   int max = 0;
   int max2 = 0;
   if(An[0]<=An[1]){
   max = An[1];
   max2 = An[0];
   }else{
   max = An[0];
   max2 = An[1];
   }
     
   
   for(int i =2;i<N;i++){
    if(max<=An[i]){
      max2 = max;
      max = An[i];
    }else if(max2<=An[i]) max2 = An[i];
   }
   for(int i = 0;i <N; i++){
     if(An[i]==max) System.out.println(max2);
     else System.out.println(max);
   }

 }
} public class Main{
 public static void main(String[] args){
   Scanner sc = new Scanner(System.in);
   int N = sc.nextInt();
   int[] An = new int[N];
   for(int i =0;i<N;i++){
   An[i] = sc.nextInt();
   }
   int max = 0;
   int max2 = 0;
   if(An[0]<=An[1]){
   max = An[1];
   max2 = An[0];
   }else{
   max = An[0];
   max2 = An[1];
   }
     
   
   for(int i =2;i<N;i++){
    if(max<=An[i]){
      max2 = max;
      max = An[i];
    }else if(max2<=An[i]) max2 = An[i];
   }
   for(int i = 0;i <N; i++){
     if(An[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 sc = new Scanner(System.in);
   int N = sc.nextInt();
   int[] An = new int[N];
   for(int i =0;i<N;i++){
   An[i] = sc.nextInt();
   }
   int max = 0;
   int max2 = 0;
   if(An[0]<=An[1]){
   max = An[1];
   max2 = An[0];
   }else{
   max = An[0];
   max2 = An[1];
   }
     
   
   for(int i =2;i<N;i++){
    if(max<=An[i]){
      max2 = max;
      max = An[i];
    }else if(max2<=An[i]) max2 = An[i];
   }
   for(int i = 0;i <N; i++){
     if(An[i]==max) System.out.println(max2);
     else System.out.println(max);
   }

 }
}