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