import java.util.*;
public class Main{
  public static void main(String args[]){
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int[] a = new int[n];
    int cnt = 0;
    int max = 0;
    int next = 0;
    int maxi = 0;
    while(cnt<n){
      a[cnt] = sc.nextInt();
      if(a[cnt]>next){
        next = a[cnt];
        if(a[cnt]>max){
          next = max;
          max = a[cnt];
          maxi = cnt;
        }
      }
      cnt++;
    }
    cnt = 0;
    while(cnt<n){
      if(cnt!=maxi){
         System.out.println(max);
      }else{
         System.out.println(next);
      }
      cnt++;
    }
  } 
} 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[] a = new int[n];
    int cnt = 0;
    int max = 0;
    int next = 0;
    int maxi = 0;
    while(cnt<n){
      a[cnt] = sc.nextInt();
      if(a[cnt]>next){
        next = a[cnt];
        if(a[cnt]>max){
          next = max;
          max = a[cnt];
          maxi = cnt;
        }
      }
      cnt++;
    }
    cnt = 0;
    while(cnt<n){
      if(cnt!=maxi){
         System.out.println(max);
      }else{
         System.out.println(next);
      }
      cnt++;
    }
  } 
} Main public static void main(String args[]){
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int[] a = new int[n];
    int cnt = 0;
    int max = 0;
    int next = 0;
    int maxi = 0;
    while(cnt<n){
      a[cnt] = sc.nextInt();
      if(a[cnt]>next){
        next = a[cnt];
        if(a[cnt]>max){
          next = max;
          max = a[cnt];
          maxi = cnt;
        }
      }
      cnt++;
    }
    cnt = 0;
    while(cnt<n){
      if(cnt!=maxi){
         System.out.println(max);
      }else{
         System.out.println(next);
      }
      cnt++;
    }
  } main {
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int[] a = new int[n];
    int cnt = 0;
    int max = 0;
    int next = 0;
    int maxi = 0;
    while(cnt<n){
      a[cnt] = sc.nextInt();
      if(a[cnt]>next){
        next = a[cnt];
        if(a[cnt]>max){
          next = max;
          max = a[cnt];
          maxi = cnt;
        }
      }
      cnt++;
    }
    cnt = 0;
    while(cnt<n){
      if(cnt!=maxi){
         System.out.println(max);
      }else{
         System.out.println(next);
      }
      cnt++;
    }
  } 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 int cnt = 0; cnt 0 int max = 0; max 0 int next = 0; next 0 int maxi = 0; maxi 0 while(cnt<n){
      a[cnt] = sc.nextInt();
      if(a[cnt]>next){
        next = a[cnt];
        if(a[cnt]>max){
          next = max;
          max = a[cnt];
          maxi = cnt;
        }
      }
      cnt++;
    } cnt<n cnt n {
      a[cnt] = sc.nextInt();
      if(a[cnt]>next){
        next = a[cnt];
        if(a[cnt]>max){
          next = max;
          max = a[cnt];
          maxi = cnt;
        }
      }
      cnt++;
    } a[cnt] = sc.nextInt() a[cnt] a cnt sc.nextInt() sc.nextInt sc if(a[cnt]>next){
        next = a[cnt];
        if(a[cnt]>max){
          next = max;
          max = a[cnt];
          maxi = cnt;
        }
      } a[cnt]>next a[cnt] a cnt next {
        next = a[cnt];
        if(a[cnt]>max){
          next = max;
          max = a[cnt];
          maxi = cnt;
        }
      } next = a[cnt] next a[cnt] a cnt if(a[cnt]>max){
          next = max;
          max = a[cnt];
          maxi = cnt;
        } a[cnt]>max a[cnt] a cnt max {
          next = max;
          max = a[cnt];
          maxi = cnt;
        } next = max next max max = a[cnt] max a[cnt] a cnt maxi = cnt maxi cnt cnt++ cnt cnt = 0 cnt 0 while(cnt<n){
      if(cnt!=maxi){
         System.out.println(max);
      }else{
         System.out.println(next);
      }
      cnt++;
    } cnt<n cnt n {
      if(cnt!=maxi){
         System.out.println(max);
      }else{
         System.out.println(next);
      }
      cnt++;
    } if(cnt!=maxi){
         System.out.println(max);
      }else{
         System.out.println(next);
      } cnt!=maxi cnt maxi {
         System.out.println(max);
      } System.out.println(max) System.out.println System.out System System.out max {
         System.out.println(next);
      } System.out.println(next) System.out.println System.out System System.out next cnt++ cnt String args[] args public class Main{
  public static void main(String args[]){
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int[] a = new int[n];
    int cnt = 0;
    int max = 0;
    int next = 0;
    int maxi = 0;
    while(cnt<n){
      a[cnt] = sc.nextInt();
      if(a[cnt]>next){
        next = a[cnt];
        if(a[cnt]>max){
          next = max;
          max = a[cnt];
          maxi = cnt;
        }
      }
      cnt++;
    }
    cnt = 0;
    while(cnt<n){
      if(cnt!=maxi){
         System.out.println(max);
      }else{
         System.out.println(next);
      }
      cnt++;
    }
  } 
} public class Main{
  public static void main(String args[]){
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int[] a = new int[n];
    int cnt = 0;
    int max = 0;
    int next = 0;
    int maxi = 0;
    while(cnt<n){
      a[cnt] = sc.nextInt();
      if(a[cnt]>next){
        next = a[cnt];
        if(a[cnt]>max){
          next = max;
          max = a[cnt];
          maxi = cnt;
        }
      }
      cnt++;
    }
    cnt = 0;
    while(cnt<n){
      if(cnt!=maxi){
         System.out.println(max);
      }else{
         System.out.println(next);
      }
      cnt++;
    }
  } 
} Main
import java.util.*;
public class Main{
  public static void main(String args[]){
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int[] a = new int[n];
    int cnt = 0;
    int max = 0;
    int next = 0;
    int maxi = 0;
    while(cnt<n){
      a[cnt] = sc.nextInt();
      if(a[cnt]>next){
        next = a[cnt];
        if(a[cnt]>max){
          next = max;
          max = a[cnt];
          maxi = cnt;
        }
      }
      cnt++;
    }
    cnt = 0;
    while(cnt<n){
      if(cnt!=maxi){
         System.out.println(max);
      }else{
         System.out.println(next);
      }
      cnt++;
    }
  } 
}