import java.util.*;
import java.util.TreeMap;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    ArrayList<Integer> list = new ArrayList<Integer>();
    for (int i = 0; i < N; i++) {
      list.add(sc.nextInt());
    }
    ArrayList<Integer> list1 = new ArrayList<>(list);
    Collections.sort(list1, Collections.reverseOrder());
    int first = list1.get(0);
    int second = list1.get(1);
    for (int i = 0; i < N; i++) {
      if (list.get(i) < first) {
        System.out.println(first);
      } else {
        System.out.println(second);
      }
    }
  }
} import java.util.*; util.* java import java.util.TreeMap; TreeMap java.util public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    ArrayList<Integer> list = new ArrayList<Integer>();
    for (int i = 0; i < N; i++) {
      list.add(sc.nextInt());
    }
    ArrayList<Integer> list1 = new ArrayList<>(list);
    Collections.sort(list1, Collections.reverseOrder());
    int first = list1.get(0);
    int second = list1.get(1);
    for (int i = 0; i < N; i++) {
      if (list.get(i) < first) {
        System.out.println(first);
      } else {
        System.out.println(second);
      }
    }
  }
} Main public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    ArrayList<Integer> list = new ArrayList<Integer>();
    for (int i = 0; i < N; i++) {
      list.add(sc.nextInt());
    }
    ArrayList<Integer> list1 = new ArrayList<>(list);
    Collections.sort(list1, Collections.reverseOrder());
    int first = list1.get(0);
    int second = list1.get(1);
    for (int i = 0; i < N; i++) {
      if (list.get(i) < first) {
        System.out.println(first);
      } else {
        System.out.println(second);
      }
    }
  } main {
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    ArrayList<Integer> list = new ArrayList<Integer>();
    for (int i = 0; i < N; i++) {
      list.add(sc.nextInt());
    }
    ArrayList<Integer> list1 = new ArrayList<>(list);
    Collections.sort(list1, Collections.reverseOrder());
    int first = list1.get(0);
    int second = list1.get(1);
    for (int i = 0; i < N; i++) {
      if (list.get(i) < first) {
        System.out.println(first);
      } 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 ArrayList<Integer> list = new ArrayList<Integer>(); list new ArrayList<Integer>() for (int i = 0; i < N; i++) {
      list.add(sc.nextInt());
    } int i = 0; int i = 0; i 0 i < N i N i++ i++ i {
      list.add(sc.nextInt());
    } {
      list.add(sc.nextInt());
    } list.add(sc.nextInt()) list.add list sc.nextInt() sc.nextInt sc ArrayList<Integer> list1 = new ArrayList<>(list); list1 new ArrayList<>(list) Collections.sort(list1, Collections.reverseOrder()) Collections.sort Collections list1 Collections.reverseOrder() Collections.reverseOrder Collections int first = list1.get(0); first list1.get(0) list1.get list1 0 int second = list1.get(1); second list1.get(1) list1.get list1 1 for (int i = 0; i < N; i++) {
      if (list.get(i) < first) {
        System.out.println(first);
      } else {
        System.out.println(second);
      }
    } int i = 0; int i = 0; i 0 i < N i N i++ i++ i {
      if (list.get(i) < first) {
        System.out.println(first);
      } else {
        System.out.println(second);
      }
    } {
      if (list.get(i) < first) {
        System.out.println(first);
      } else {
        System.out.println(second);
      }
    } if (list.get(i) < first) {
        System.out.println(first);
      } else {
        System.out.println(second);
      } list.get(i) < first list.get(i) list.get list i first {
        System.out.println(first);
      } System.out.println(first) System.out.println System.out System System.out first {
        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();
    ArrayList<Integer> list = new ArrayList<Integer>();
    for (int i = 0; i < N; i++) {
      list.add(sc.nextInt());
    }
    ArrayList<Integer> list1 = new ArrayList<>(list);
    Collections.sort(list1, Collections.reverseOrder());
    int first = list1.get(0);
    int second = list1.get(1);
    for (int i = 0; i < N; i++) {
      if (list.get(i) < first) {
        System.out.println(first);
      } else {
        System.out.println(second);
      }
    }
  }
} public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    ArrayList<Integer> list = new ArrayList<Integer>();
    for (int i = 0; i < N; i++) {
      list.add(sc.nextInt());
    }
    ArrayList<Integer> list1 = new ArrayList<>(list);
    Collections.sort(list1, Collections.reverseOrder());
    int first = list1.get(0);
    int second = list1.get(1);
    for (int i = 0; i < N; i++) {
      if (list.get(i) < first) {
        System.out.println(first);
      } else {
        System.out.println(second);
      }
    }
  }
} Main
import java.util.*;
import java.util.TreeMap;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    ArrayList<Integer> list = new ArrayList<Integer>();
    for (int i = 0; i < N; i++) {
      list.add(sc.nextInt());
    }
    ArrayList<Integer> list1 = new ArrayList<>(list);
    Collections.sort(list1, Collections.reverseOrder());
    int first = list1.get(0);
    int second = list1.get(1);
    for (int i = 0; i < N; i++) {
      if (list.get(i) < first) {
        System.out.println(first);
      } else {
        System.out.println(second);
      }
    }
  }
}
