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 max=1;
    int index=0;
    for(int i=0;i<N;i++){
      A[i] = sc.nextInt();
      if(A[i]>max) {
        max=A[i];
        index=i;
      }
    }
    
    int second=1;
    for(int j=0;j<N;j++){
      if(j!=index && A[j]>second){
        second=A[j]; 
      }
    }
    
    for(int k=0;k<N;k++){
      if(k!=index){
        System.out.println(max);
    } else{
        System.out.println(second);
    }
    }

  }
} 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 max=1;
    int index=0;
    for(int i=0;i<N;i++){
      A[i] = sc.nextInt();
      if(A[i]>max) {
        max=A[i];
        index=i;
      }
    }
    
    int second=1;
    for(int j=0;j<N;j++){
      if(j!=index && A[j]>second){
        second=A[j]; 
      }
    }
    
    for(int k=0;k<N;k++){
      if(k!=index){
        System.out.println(max);
    } else{
        System.out.println(second);
    }
    }

  }
} Main public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    
    int[] A = new int[N];
    int max=1;
    int index=0;
    for(int i=0;i<N;i++){
      A[i] = sc.nextInt();
      if(A[i]>max) {
        max=A[i];
        index=i;
      }
    }
    
    int second=1;
    for(int j=0;j<N;j++){
      if(j!=index && A[j]>second){
        second=A[j]; 
      }
    }
    
    for(int k=0;k<N;k++){
      if(k!=index){
        System.out.println(max);
    } else{
        System.out.println(second);
    }
    }

  } main {
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    
    int[] A = new int[N];
    int max=1;
    int index=0;
    for(int i=0;i<N;i++){
      A[i] = sc.nextInt();
      if(A[i]>max) {
        max=A[i];
        index=i;
      }
    }
    
    int second=1;
    for(int j=0;j<N;j++){
      if(j!=index && A[j]>second){
        second=A[j]; 
      }
    }
    
    for(int k=0;k<N;k++){
      if(k!=index){
        System.out.println(max);
    } else{
        System.out.println(second);
    }
    }

  } 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 max=1; max 1 int index=0; index 0 for(int i=0;i<N;i++){
      A[i] = sc.nextInt();
      if(A[i]>max) {
        max=A[i];
        index=i;
      }
    } int i=0; int i=0; i 0 i<N i N i++ i++ i {
      A[i] = sc.nextInt();
      if(A[i]>max) {
        max=A[i];
        index=i;
      }
    } {
      A[i] = sc.nextInt();
      if(A[i]>max) {
        max=A[i];
        index=i;
      }
    } A[i] = sc.nextInt() A[i] A i sc.nextInt() sc.nextInt sc if(A[i]>max) {
        max=A[i];
        index=i;
      } A[i]>max A[i] A i max {
        max=A[i];
        index=i;
      } max=A[i] max A[i] A i index=i index i int second=1; second 1 for(int j=0;j<N;j++){
      if(j!=index && A[j]>second){
        second=A[j]; 
      }
    } int j=0; int j=0; j 0 j<N j N j++ j++ j {
      if(j!=index && A[j]>second){
        second=A[j]; 
      }
    } {
      if(j!=index && A[j]>second){
        second=A[j]; 
      }
    } if(j!=index && A[j]>second){
        second=A[j]; 
      } j!=index && A[j]>second j!=index j index A[j]>second A[j] A j second {
        second=A[j]; 
      } second=A[j] second A[j] A j for(int k=0;k<N;k++){
      if(k!=index){
        System.out.println(max);
    } else{
        System.out.println(second);
    }
    } int k=0; int k=0; k 0 k<N k N k++ k++ k {
      if(k!=index){
        System.out.println(max);
    } else{
        System.out.println(second);
    }
    } {
      if(k!=index){
        System.out.println(max);
    } else{
        System.out.println(second);
    }
    } if(k!=index){
        System.out.println(max);
    } else{
        System.out.println(second);
    } k!=index k index {
        System.out.println(max);
    } System.out.println(max) System.out.println System.out System System.out max {
        System.out.println(second);
    } System.out.println(second) System.out.println System.out System System.out second 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 max=1;
    int index=0;
    for(int i=0;i<N;i++){
      A[i] = sc.nextInt();
      if(A[i]>max) {
        max=A[i];
        index=i;
      }
    }
    
    int second=1;
    for(int j=0;j<N;j++){
      if(j!=index && A[j]>second){
        second=A[j]; 
      }
    }
    
    for(int k=0;k<N;k++){
      if(k!=index){
        System.out.println(max);
    } else{
        System.out.println(second);
    }
    }

  }
} 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 max=1;
    int index=0;
    for(int i=0;i<N;i++){
      A[i] = sc.nextInt();
      if(A[i]>max) {
        max=A[i];
        index=i;
      }
    }
    
    int second=1;
    for(int j=0;j<N;j++){
      if(j!=index && A[j]>second){
        second=A[j]; 
      }
    }
    
    for(int k=0;k<N;k++){
      if(k!=index){
        System.out.println(max);
    } else{
        System.out.println(second);
    }
    }

  }
} 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 max=1;
    int index=0;
    for(int i=0;i<N;i++){
      A[i] = sc.nextInt();
      if(A[i]>max) {
        max=A[i];
        index=i;
      }
    }
    
    int second=1;
    for(int j=0;j<N;j++){
      if(j!=index && A[j]>second){
        second=A[j]; 
      }
    }
    
    for(int k=0;k<N;k++){
      if(k!=index){
        System.out.println(max);
    } else{
        System.out.println(second);
    }
    }

  }
}