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