import java.util.Arrays;
import java.util.Scanner;

public class Main {
  public static void main(String[] args) {
    Scanner scan = new Scanner(System.in);
    int N = scan.nextInt();

    int[] array = new int[N];
    int[] array2 = new int[N];
    int max = 0;
    int tmp;

    for (int i = 0; i < N; i++) {
      tmp = scan.nextInt();
      array[i] = tmp;
      array2[i] = tmp;
      if (max < tmp) {
        max = tmp;
      }
    }
    Arrays.sort(array2);

    for (int i = 0; i < N; i++) {
      if (array[i] < max) {
        System.out.println(max);
        continue;
      }
      System.out.println(array2[N - 2]);
    }
  }
} import java.util.Arrays; Arrays java.util import java.util.Scanner; Scanner java.util public class Main {
  public static void main(String[] args) {
    Scanner scan = new Scanner(System.in);
    int N = scan.nextInt();

    int[] array = new int[N];
    int[] array2 = new int[N];
    int max = 0;
    int tmp;

    for (int i = 0; i < N; i++) {
      tmp = scan.nextInt();
      array[i] = tmp;
      array2[i] = tmp;
      if (max < tmp) {
        max = tmp;
      }
    }
    Arrays.sort(array2);

    for (int i = 0; i < N; i++) {
      if (array[i] < max) {
        System.out.println(max);
        continue;
      }
      System.out.println(array2[N - 2]);
    }
  }
} Main public static void main(String[] args) {
    Scanner scan = new Scanner(System.in);
    int N = scan.nextInt();

    int[] array = new int[N];
    int[] array2 = new int[N];
    int max = 0;
    int tmp;

    for (int i = 0; i < N; i++) {
      tmp = scan.nextInt();
      array[i] = tmp;
      array2[i] = tmp;
      if (max < tmp) {
        max = tmp;
      }
    }
    Arrays.sort(array2);

    for (int i = 0; i < N; i++) {
      if (array[i] < max) {
        System.out.println(max);
        continue;
      }
      System.out.println(array2[N - 2]);
    }
  } main {
    Scanner scan = new Scanner(System.in);
    int N = scan.nextInt();

    int[] array = new int[N];
    int[] array2 = new int[N];
    int max = 0;
    int tmp;

    for (int i = 0; i < N; i++) {
      tmp = scan.nextInt();
      array[i] = tmp;
      array2[i] = tmp;
      if (max < tmp) {
        max = tmp;
      }
    }
    Arrays.sort(array2);

    for (int i = 0; i < N; i++) {
      if (array[i] < max) {
        System.out.println(max);
        continue;
      }
      System.out.println(array2[N - 2]);
    }
  } Scanner scan = new Scanner(System.in); scan new Scanner(System.in) int N = scan.nextInt(); N scan.nextInt() scan.nextInt scan int[] array = new int[N]; array new int[N] N int[] array2 = new int[N]; array2 new int[N] N int max = 0; max 0 int tmp; tmp for (int i = 0; i < N; i++) {
      tmp = scan.nextInt();
      array[i] = tmp;
      array2[i] = tmp;
      if (max < tmp) {
        max = tmp;
      }
    } int i = 0; int i = 0; i 0 i < N i N i++ i++ i {
      tmp = scan.nextInt();
      array[i] = tmp;
      array2[i] = tmp;
      if (max < tmp) {
        max = tmp;
      }
    } {
      tmp = scan.nextInt();
      array[i] = tmp;
      array2[i] = tmp;
      if (max < tmp) {
        max = tmp;
      }
    } tmp = scan.nextInt() tmp scan.nextInt() scan.nextInt scan array[i] = tmp array[i] array i tmp array2[i] = tmp array2[i] array2 i tmp if (max < tmp) {
        max = tmp;
      } max < tmp max tmp {
        max = tmp;
      } max = tmp max tmp Arrays.sort(array2) Arrays.sort Arrays array2 for (int i = 0; i < N; i++) {
      if (array[i] < max) {
        System.out.println(max);
        continue;
      }
      System.out.println(array2[N - 2]);
    } int i = 0; int i = 0; i 0 i < N i N i++ i++ i {
      if (array[i] < max) {
        System.out.println(max);
        continue;
      }
      System.out.println(array2[N - 2]);
    } {
      if (array[i] < max) {
        System.out.println(max);
        continue;
      }
      System.out.println(array2[N - 2]);
    } if (array[i] < max) {
        System.out.println(max);
        continue;
      } array[i] < max array[i] array i max {
        System.out.println(max);
        continue;
      } System.out.println(max) System.out.println System.out System System.out max continue; System.out.println(array2[N - 2]) System.out.println System.out System System.out array2[N - 2] array2 N - 2 N 2 String[] args args public class Main {
  public static void main(String[] args) {
    Scanner scan = new Scanner(System.in);
    int N = scan.nextInt();

    int[] array = new int[N];
    int[] array2 = new int[N];
    int max = 0;
    int tmp;

    for (int i = 0; i < N; i++) {
      tmp = scan.nextInt();
      array[i] = tmp;
      array2[i] = tmp;
      if (max < tmp) {
        max = tmp;
      }
    }
    Arrays.sort(array2);

    for (int i = 0; i < N; i++) {
      if (array[i] < max) {
        System.out.println(max);
        continue;
      }
      System.out.println(array2[N - 2]);
    }
  }
} public class Main {
  public static void main(String[] args) {
    Scanner scan = new Scanner(System.in);
    int N = scan.nextInt();

    int[] array = new int[N];
    int[] array2 = new int[N];
    int max = 0;
    int tmp;

    for (int i = 0; i < N; i++) {
      tmp = scan.nextInt();
      array[i] = tmp;
      array2[i] = tmp;
      if (max < tmp) {
        max = tmp;
      }
    }
    Arrays.sort(array2);

    for (int i = 0; i < N; i++) {
      if (array[i] < max) {
        System.out.println(max);
        continue;
      }
      System.out.println(array2[N - 2]);
    }
  }
} Main
import java.util.Arrays;
import java.util.Scanner;

public class Main {
  public static void main(String[] args) {
    Scanner scan = new Scanner(System.in);
    int N = scan.nextInt();

    int[] array = new int[N];
    int[] array2 = new int[N];
    int max = 0;
    int tmp;

    for (int i = 0; i < N; i++) {
      tmp = scan.nextInt();
      array[i] = tmp;
      array2[i] = tmp;
      if (max < tmp) {
        max = tmp;
      }
    }
    Arrays.sort(array2);

    for (int i = 0; i < N; i++) {
      if (array[i] < max) {
        System.out.println(max);
        continue;
      }
      System.out.println(array2[N - 2]);
    }
  }
}
