import java.util.*;

public class Main{
  public static void main(String[] args){
  	Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int largest = Integer.MIN_VALUE;
    int second =  Integer.MIN_VALUE;
    int[] arr = new int[n];
    int val;
    for (int i=0; i<n;i++){
      val = sc.nextInt();
      arr[i] = val;
      if (val > largest){
        second = largest;
        largest = val;
        
      } else if (second < val) {
        second = val;
      }
      
    }
    for (int num:arr){
      if (num == largest){
        System.out.println(second);
    } else{ System.out.println(largest);}
                           }
  }
} import java.util.*; util.* java public class Main{
  public static void main(String[] args){
  	Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int largest = Integer.MIN_VALUE;
    int second =  Integer.MIN_VALUE;
    int[] arr = new int[n];
    int val;
    for (int i=0; i<n;i++){
      val = sc.nextInt();
      arr[i] = val;
      if (val > largest){
        second = largest;
        largest = val;
        
      } else if (second < val) {
        second = val;
      }
      
    }
    for (int num:arr){
      if (num == largest){
        System.out.println(second);
    } else{ System.out.println(largest);}
                           }
  }
} Main public static void main(String[] args){
  	Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int largest = Integer.MIN_VALUE;
    int second =  Integer.MIN_VALUE;
    int[] arr = new int[n];
    int val;
    for (int i=0; i<n;i++){
      val = sc.nextInt();
      arr[i] = val;
      if (val > largest){
        second = largest;
        largest = val;
        
      } else if (second < val) {
        second = val;
      }
      
    }
    for (int num:arr){
      if (num == largest){
        System.out.println(second);
    } else{ System.out.println(largest);}
                           }
  } main {
  	Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int largest = Integer.MIN_VALUE;
    int second =  Integer.MIN_VALUE;
    int[] arr = new int[n];
    int val;
    for (int i=0; i<n;i++){
      val = sc.nextInt();
      arr[i] = val;
      if (val > largest){
        second = largest;
        largest = val;
        
      } else if (second < val) {
        second = val;
      }
      
    }
    for (int num:arr){
      if (num == largest){
        System.out.println(second);
    } else{ System.out.println(largest);}
                           }
  } Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int n = sc.nextInt(); n sc.nextInt() sc.nextInt sc int largest = Integer.MIN_VALUE; largest Integer.MIN_VALUE Integer Integer.MIN_VALUE int second =  Integer.MIN_VALUE; second Integer.MIN_VALUE Integer Integer.MIN_VALUE int[] arr = new int[n]; arr new int[n] n int val; val for (int i=0; i<n;i++){
      val = sc.nextInt();
      arr[i] = val;
      if (val > largest){
        second = largest;
        largest = val;
        
      } else if (second < val) {
        second = val;
      }
      
    } int i=0; int i=0; i 0 i<n i n i++ i++ i {
      val = sc.nextInt();
      arr[i] = val;
      if (val > largest){
        second = largest;
        largest = val;
        
      } else if (second < val) {
        second = val;
      }
      
    } {
      val = sc.nextInt();
      arr[i] = val;
      if (val > largest){
        second = largest;
        largest = val;
        
      } else if (second < val) {
        second = val;
      }
      
    } val = sc.nextInt() val sc.nextInt() sc.nextInt sc arr[i] = val arr[i] arr i val if (val > largest){
        second = largest;
        largest = val;
        
      } else if (second < val) {
        second = val;
      } val > largest val largest {
        second = largest;
        largest = val;
        
      } second = largest second largest largest = val largest val if (second < val) {
        second = val;
      } second < val second val {
        second = val;
      } second = val second val for (int num:arr){
      if (num == largest){
        System.out.println(second);
    } else{ System.out.println(largest);}
                           } int num arr {
      if (num == largest){
        System.out.println(second);
    } else{ System.out.println(largest);}
                           } {
      if (num == largest){
        System.out.println(second);
    } else{ System.out.println(largest);}
                           } if (num == largest){
        System.out.println(second);
    } else{ System.out.println(largest);} num == largest num largest {
        System.out.println(second);
    } System.out.println(second) System.out.println System.out System System.out second { System.out.println(largest);} System.out.println(largest) System.out.println System.out System System.out largest String[] args args public class Main{
  public static void main(String[] args){
  	Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int largest = Integer.MIN_VALUE;
    int second =  Integer.MIN_VALUE;
    int[] arr = new int[n];
    int val;
    for (int i=0; i<n;i++){
      val = sc.nextInt();
      arr[i] = val;
      if (val > largest){
        second = largest;
        largest = val;
        
      } else if (second < val) {
        second = val;
      }
      
    }
    for (int num:arr){
      if (num == largest){
        System.out.println(second);
    } else{ System.out.println(largest);}
                           }
  }
} public class Main{
  public static void main(String[] args){
  	Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int largest = Integer.MIN_VALUE;
    int second =  Integer.MIN_VALUE;
    int[] arr = new int[n];
    int val;
    for (int i=0; i<n;i++){
      val = sc.nextInt();
      arr[i] = val;
      if (val > largest){
        second = largest;
        largest = val;
        
      } else if (second < val) {
        second = val;
      }
      
    }
    for (int num:arr){
      if (num == largest){
        System.out.println(second);
    } else{ System.out.println(largest);}
                           }
  }
} Main
import java.util.*;

public class Main{
  public static void main(String[] args){
  	Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int largest = Integer.MIN_VALUE;
    int second =  Integer.MIN_VALUE;
    int[] arr = new int[n];
    int val;
    for (int i=0; i<n;i++){
      val = sc.nextInt();
      arr[i] = val;
      if (val > largest){
        second = largest;
        largest = val;
        
      } else if (second < val) {
        second = val;
      }
      
    }
    for (int num:arr){
      if (num == largest){
        System.out.println(second);
    } else{ System.out.println(largest);}
                           }
  }
}