import java.util.*;

class Main {
  public static void main(String[] args) {
    Scanner stdIn = new Scanner(System.in);
    int n = stdIn.nextInt();
    int[] a = new int[n];
    for(int i = 0;i<n;i++) {
      a[i] = stdIn.nextInt();
    }
    int[] clone = new int[n-1];
    int ma = max(a);
    int k = 0;
    for(int i = 0;i<a.length;i++) {
      if(a[i]==ma) {
        k = i;
        break;
      }
    }
    un(a,clone,k);
    int ma2 = max(clone);
    for(int i = 0;i<a.length;i++) {
      if(i!=k) System.out.println(ma);
      else System.out.println(ma2);
    }
  }
  public static void un(int[] a,int[] clone,int j) {
    int k = 0;
    //System.out.println(j);
    for(int i = 0;i<a.length;i++) {
      if(i!=j)  {clone[k] = a[i];k++;}
    }
    //System.out.println("hei");
      }
  public static int max(int[] a) {
    int b = a[0];
    for(int i = 1;i<a.length;i++) {
      b = Math.max(b,a[i]);
    }
    return b;
  }
} import java.util.*; util.* java class Main {
  public static void main(String[] args) {
    Scanner stdIn = new Scanner(System.in);
    int n = stdIn.nextInt();
    int[] a = new int[n];
    for(int i = 0;i<n;i++) {
      a[i] = stdIn.nextInt();
    }
    int[] clone = new int[n-1];
    int ma = max(a);
    int k = 0;
    for(int i = 0;i<a.length;i++) {
      if(a[i]==ma) {
        k = i;
        break;
      }
    }
    un(a,clone,k);
    int ma2 = max(clone);
    for(int i = 0;i<a.length;i++) {
      if(i!=k) System.out.println(ma);
      else System.out.println(ma2);
    }
  }
  public static void un(int[] a,int[] clone,int j) {
    int k = 0;
    //System.out.println(j);
    for(int i = 0;i<a.length;i++) {
      if(i!=j)  {clone[k] = a[i];k++;}
    }
    //System.out.println("hei");
      }
  public static int max(int[] a) {
    int b = a[0];
    for(int i = 1;i<a.length;i++) {
      b = Math.max(b,a[i]);
    }
    return b;
  }
} Main public static void main(String[] args) {
    Scanner stdIn = new Scanner(System.in);
    int n = stdIn.nextInt();
    int[] a = new int[n];
    for(int i = 0;i<n;i++) {
      a[i] = stdIn.nextInt();
    }
    int[] clone = new int[n-1];
    int ma = max(a);
    int k = 0;
    for(int i = 0;i<a.length;i++) {
      if(a[i]==ma) {
        k = i;
        break;
      }
    }
    un(a,clone,k);
    int ma2 = max(clone);
    for(int i = 0;i<a.length;i++) {
      if(i!=k) System.out.println(ma);
      else System.out.println(ma2);
    }
  } main {
    Scanner stdIn = new Scanner(System.in);
    int n = stdIn.nextInt();
    int[] a = new int[n];
    for(int i = 0;i<n;i++) {
      a[i] = stdIn.nextInt();
    }
    int[] clone = new int[n-1];
    int ma = max(a);
    int k = 0;
    for(int i = 0;i<a.length;i++) {
      if(a[i]==ma) {
        k = i;
        break;
      }
    }
    un(a,clone,k);
    int ma2 = max(clone);
    for(int i = 0;i<a.length;i++) {
      if(i!=k) System.out.println(ma);
      else System.out.println(ma2);
    }
  } Scanner stdIn = new Scanner(System.in); stdIn new Scanner(System.in) int n = stdIn.nextInt(); n stdIn.nextInt() stdIn.nextInt stdIn int[] a = new int[n]; a new int[n] n for(int i = 0;i<n;i++) {
      a[i] = stdIn.nextInt();
    } int i = 0; int i = 0; i 0 i<n i n i++ i++ i {
      a[i] = stdIn.nextInt();
    } {
      a[i] = stdIn.nextInt();
    } a[i] = stdIn.nextInt() a[i] a i stdIn.nextInt() stdIn.nextInt stdIn int[] clone = new int[n-1]; clone new int[n-1] n-1 n 1 int ma = max(a); ma max(a) max a int k = 0; k 0 for(int i = 0;i<a.length;i++) {
      if(a[i]==ma) {
        k = i;
        break;
      }
    } int i = 0; int i = 0; i 0 i<a.length i a.length a a.length i++ i++ i {
      if(a[i]==ma) {
        k = i;
        break;
      }
    } {
      if(a[i]==ma) {
        k = i;
        break;
      }
    } if(a[i]==ma) {
        k = i;
        break;
      } a[i]==ma a[i] a i ma {
        k = i;
        break;
      } k = i k i break; un(a,clone,k) un a clone k int ma2 = max(clone); ma2 max(clone) max clone for(int i = 0;i<a.length;i++) {
      if(i!=k) System.out.println(ma);
      else System.out.println(ma2);
    } int i = 0; int i = 0; i 0 i<a.length i a.length a a.length i++ i++ i {
      if(i!=k) System.out.println(ma);
      else System.out.println(ma2);
    } {
      if(i!=k) System.out.println(ma);
      else System.out.println(ma2);
    } if(i!=k) System.out.println(ma);
      else System.out.println(ma2); i!=k i k System.out.println(ma) System.out.println System.out System System.out ma System.out.println(ma2) System.out.println System.out System System.out ma2 String[] args args public static void un(int[] a,int[] clone,int j) {
    int k = 0;
    //System.out.println(j);
    for(int i = 0;i<a.length;i++) {
      if(i!=j)  {clone[k] = a[i];k++;}
    }
    //System.out.println("hei");
      } un {
    int k = 0;
    //System.out.println(j);
    for(int i = 0;i<a.length;i++) {
      if(i!=j)  {clone[k] = a[i];k++;}
    }
    //System.out.println("hei");
      } int k = 0; k 0 for(int i = 0;i<a.length;i++) {
      if(i!=j)  {clone[k] = a[i];k++;}
    } int i = 0; int i = 0; i 0 i<a.length i a.length a a.length i++ i++ i {
      if(i!=j)  {clone[k] = a[i];k++;}
    } {
      if(i!=j)  {clone[k] = a[i];k++;}
    } if(i!=j)  {clone[k] = a[i];k++;} i!=j i j {clone[k] = a[i];k++;} clone[k] = a[i] clone[k] clone k a[i] a i k++ k int[] a a int[] clone clone int j j public static int max(int[] a) {
    int b = a[0];
    for(int i = 1;i<a.length;i++) {
      b = Math.max(b,a[i]);
    }
    return b;
  } max {
    int b = a[0];
    for(int i = 1;i<a.length;i++) {
      b = Math.max(b,a[i]);
    }
    return b;
  } int b = a[0]; b a[0] a 0 for(int i = 1;i<a.length;i++) {
      b = Math.max(b,a[i]);
    } int i = 1; int i = 1; i 1 i<a.length i a.length a a.length i++ i++ i {
      b = Math.max(b,a[i]);
    } {
      b = Math.max(b,a[i]);
    } b = Math.max(b,a[i]) b Math.max(b,a[i]) Math.max Math b a[i] a i return b; b int[] a a
import java.util.*;

class Main {
  public static void main(String[] args) {
    Scanner stdIn = new Scanner(System.in);
    int n = stdIn.nextInt();
    int[] a = new int[n];
    for(int i = 0;i<n;i++) {
      a[i] = stdIn.nextInt();
    }
    int[] clone = new int[n-1];
    int ma = max(a);
    int k = 0;
    for(int i = 0;i<a.length;i++) {
      if(a[i]==ma) {
        k = i;
        break;
      }
    }
    un(a,clone,k);
    int ma2 = max(clone);
    for(int i = 0;i<a.length;i++) {
      if(i!=k) System.out.println(ma);
      else System.out.println(ma2);
    }
  }
  public static void un(int[] a,int[] clone,int j) {
    int k = 0;
    //System.out.println(j);
    for(int i = 0;i<a.length;i++) {
      if(i!=j)  {clone[k] = a[i];k++;}
    }
    //System.out.println("hei");
      }
  public static int max(int[] a) {
    int b = a[0];
    for(int i = 1;i<a.length;i++) {
      b = Math.max(b,a[i]);
    }
    return b;
  }
}
