import java.util.Scanner;

class Main{
  public static void main(String[] args){
    Scanner scan=new Scanner(System.in);
    int num=scan.nextInt();
    int max=0, maxnum=0;
    int max2=0;
    for(int x=0; x<num; x++){
      int in=scan.nextInt();
      if(max<=in && max2<=in && max!=in){
        max=in;
        maxnum=x;
      }else if(max>=in && max2<=in){
        max2=in;
      }
    }
    for(int x=0; x<num; x++){
      if(maxnum!=x){
        System.out.println(max);
      }else{
        System.out.println(max2);
      }
    }
  }
} import java.util.Scanner; Scanner java.util class Main{
  public static void main(String[] args){
    Scanner scan=new Scanner(System.in);
    int num=scan.nextInt();
    int max=0, maxnum=0;
    int max2=0;
    for(int x=0; x<num; x++){
      int in=scan.nextInt();
      if(max<=in && max2<=in && max!=in){
        max=in;
        maxnum=x;
      }else if(max>=in && max2<=in){
        max2=in;
      }
    }
    for(int x=0; x<num; x++){
      if(maxnum!=x){
        System.out.println(max);
      }else{
        System.out.println(max2);
      }
    }
  }
} Main public static void main(String[] args){
    Scanner scan=new Scanner(System.in);
    int num=scan.nextInt();
    int max=0, maxnum=0;
    int max2=0;
    for(int x=0; x<num; x++){
      int in=scan.nextInt();
      if(max<=in && max2<=in && max!=in){
        max=in;
        maxnum=x;
      }else if(max>=in && max2<=in){
        max2=in;
      }
    }
    for(int x=0; x<num; x++){
      if(maxnum!=x){
        System.out.println(max);
      }else{
        System.out.println(max2);
      }
    }
  } main {
    Scanner scan=new Scanner(System.in);
    int num=scan.nextInt();
    int max=0, maxnum=0;
    int max2=0;
    for(int x=0; x<num; x++){
      int in=scan.nextInt();
      if(max<=in && max2<=in && max!=in){
        max=in;
        maxnum=x;
      }else if(max>=in && max2<=in){
        max2=in;
      }
    }
    for(int x=0; x<num; x++){
      if(maxnum!=x){
        System.out.println(max);
      }else{
        System.out.println(max2);
      }
    }
  } Scanner scan=new Scanner(System.in); scan new Scanner(System.in) int num=scan.nextInt(); num scan.nextInt() scan.nextInt scan int max=0 max 0 maxnum=0; maxnum 0 int max2=0; max2 0 for(int x=0; x<num; x++){
      int in=scan.nextInt();
      if(max<=in && max2<=in && max!=in){
        max=in;
        maxnum=x;
      }else if(max>=in && max2<=in){
        max2=in;
      }
    } int x=0; int x=0; x 0 x<num x num x++ x++ x {
      int in=scan.nextInt();
      if(max<=in && max2<=in && max!=in){
        max=in;
        maxnum=x;
      }else if(max>=in && max2<=in){
        max2=in;
      }
    } {
      int in=scan.nextInt();
      if(max<=in && max2<=in && max!=in){
        max=in;
        maxnum=x;
      }else if(max>=in && max2<=in){
        max2=in;
      }
    } int in=scan.nextInt(); in scan.nextInt() scan.nextInt scan if(max<=in && max2<=in && max!=in){
        max=in;
        maxnum=x;
      }else if(max>=in && max2<=in){
        max2=in;
      } max<=in && max2<=in && max!=in max<=in && max2<=in && max!=in max<=in max in max2<=in max2 in max!=in max in {
        max=in;
        maxnum=x;
      } max=in max in maxnum=x maxnum x if(max>=in && max2<=in){
        max2=in;
      } max>=in && max2<=in max>=in max in max2<=in max2 in {
        max2=in;
      } max2=in max2 in for(int x=0; x<num; x++){
      if(maxnum!=x){
        System.out.println(max);
      }else{
        System.out.println(max2);
      }
    } int x=0; int x=0; x 0 x<num x num x++ x++ x {
      if(maxnum!=x){
        System.out.println(max);
      }else{
        System.out.println(max2);
      }
    } {
      if(maxnum!=x){
        System.out.println(max);
      }else{
        System.out.println(max2);
      }
    } if(maxnum!=x){
        System.out.println(max);
      }else{
        System.out.println(max2);
      } maxnum!=x maxnum x {
        System.out.println(max);
      } System.out.println(max) System.out.println System.out System System.out max {
        System.out.println(max2);
      } System.out.println(max2) System.out.println System.out System System.out max2 String[] args args
import java.util.Scanner;

class Main{
  public static void main(String[] args){
    Scanner scan=new Scanner(System.in);
    int num=scan.nextInt();
    int max=0, maxnum=0;
    int max2=0;
    for(int x=0; x<num; x++){
      int in=scan.nextInt();
      if(max<=in && max2<=in && max!=in){
        max=in;
        maxnum=x;
      }else if(max>=in && max2<=in){
        max2=in;
      }
    }
    for(int x=0; x<num; x++){
      if(maxnum!=x){
        System.out.println(max);
      }else{
        System.out.println(max2);
      }
    }
  }
}