import java.util.*;
import java.math.*;

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[] data = new int[n];
    int max = 0;

    for (int i = 0; i < n; i++) {
      a[i] = sc.nextInt();
      data[i] = a[i];
      max = Math.max(max,a[i]);
    }

    Arrays.sort(data);

    for (int i = 0; i < n; i++) {
      if (a[i] != max) {
        System.out.println(max);
      } else {
        System.out.println(data[n-2]);
      }
    }

  }

} import java.util.*; util.* java import java.math.*; math.* 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[] data = new int[n];
    int max = 0;

    for (int i = 0; i < n; i++) {
      a[i] = sc.nextInt();
      data[i] = a[i];
      max = Math.max(max,a[i]);
    }

    Arrays.sort(data);

    for (int i = 0; i < n; i++) {
      if (a[i] != max) {
        System.out.println(max);
      } else {
        System.out.println(data[n-2]);
      }
    }

  }

} Main public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int[] a = new int[n];
    int[] data = new int[n];
    int max = 0;

    for (int i = 0; i < n; i++) {
      a[i] = sc.nextInt();
      data[i] = a[i];
      max = Math.max(max,a[i]);
    }

    Arrays.sort(data);

    for (int i = 0; i < n; i++) {
      if (a[i] != max) {
        System.out.println(max);
      } else {
        System.out.println(data[n-2]);
      }
    }

  } main {
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int[] a = new int[n];
    int[] data = new int[n];
    int max = 0;

    for (int i = 0; i < n; i++) {
      a[i] = sc.nextInt();
      data[i] = a[i];
      max = Math.max(max,a[i]);
    }

    Arrays.sort(data);

    for (int i = 0; i < n; i++) {
      if (a[i] != max) {
        System.out.println(max);
      } else {
        System.out.println(data[n-2]);
      }
    }

  } 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[] data = new int[n]; data new int[n] n int max = 0; max 0 for (int i = 0; i < n; i++) {
      a[i] = sc.nextInt();
      data[i] = a[i];
      max = Math.max(max,a[i]);
    } int i = 0; int i = 0; i 0 i < n i n i++ i++ i {
      a[i] = sc.nextInt();
      data[i] = a[i];
      max = Math.max(max,a[i]);
    } {
      a[i] = sc.nextInt();
      data[i] = a[i];
      max = Math.max(max,a[i]);
    } a[i] = sc.nextInt() a[i] a i sc.nextInt() sc.nextInt sc data[i] = a[i] data[i] data i a[i] a i max = Math.max(max,a[i]) max Math.max(max,a[i]) Math.max Math max a[i] a i Arrays.sort(data) Arrays.sort Arrays data for (int i = 0; i < n; i++) {
      if (a[i] != max) {
        System.out.println(max);
      } else {
        System.out.println(data[n-2]);
      }
    } int i = 0; int i = 0; i 0 i < n i n i++ i++ i {
      if (a[i] != max) {
        System.out.println(max);
      } else {
        System.out.println(data[n-2]);
      }
    } {
      if (a[i] != max) {
        System.out.println(max);
      } else {
        System.out.println(data[n-2]);
      }
    } if (a[i] != max) {
        System.out.println(max);
      } else {
        System.out.println(data[n-2]);
      } a[i] != max a[i] a i max {
        System.out.println(max);
      } System.out.println(max) System.out.println System.out System System.out max {
        System.out.println(data[n-2]);
      } System.out.println(data[n-2]) System.out.println System.out System System.out data[n-2] data n-2 n 2 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[] data = new int[n];
    int max = 0;

    for (int i = 0; i < n; i++) {
      a[i] = sc.nextInt();
      data[i] = a[i];
      max = Math.max(max,a[i]);
    }

    Arrays.sort(data);

    for (int i = 0; i < n; i++) {
      if (a[i] != max) {
        System.out.println(max);
      } else {
        System.out.println(data[n-2]);
      }
    }

  }

} 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[] data = new int[n];
    int max = 0;

    for (int i = 0; i < n; i++) {
      a[i] = sc.nextInt();
      data[i] = a[i];
      max = Math.max(max,a[i]);
    }

    Arrays.sort(data);

    for (int i = 0; i < n; i++) {
      if (a[i] != max) {
        System.out.println(max);
      } else {
        System.out.println(data[n-2]);
      }
    }

  }

} Main
import java.util.*;
import java.math.*;

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[] data = new int[n];
    int max = 0;

    for (int i = 0; i < n; i++) {
      a[i] = sc.nextInt();
      data[i] = a[i];
      max = Math.max(max,a[i]);
    }

    Arrays.sort(data);

    for (int i = 0; i < n; i++) {
      if (a[i] != max) {
        System.out.println(max);
      } else {
        System.out.println(data[n-2]);
      }
    }

  }

}
