import java.util.Comparator;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Scanner;
import java.util.TreeMap;

public class Main {

    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);

        int n = sc.nextInt();
        int[] a = new int[n];
        Map<Integer, Integer> count = new TreeMap<>(Comparator.reverseOrder());
        int max = 0;
        for (int i = 0; i < n; i++) {
            a[i] = sc.nextInt();
            count.put(a[i], count.getOrDefault(a[i], 0) + 1);
            max = Math.max(a[i], max);
        }

        for (int i = 0; i < n; i++) {
            if (a[i] == max) {
                System.out.println(getNext(count));
            } else {
                System.out.println(max);
            }
        }
    }

    static int getNext(Map<Integer, Integer> count) {
        int loop = 1;
        for (Entry<Integer, Integer> e : count.entrySet()) {
            if (e.getValue() > 1) {
                return e.getKey();
            }

            if (loop > 1) {
                return e.getKey();
            }
            loop++;
        }
        return 0;
    }
} import java.util.Comparator; Comparator java.util import java.util.Map; Map java.util import java.util.Map.Entry; Entry java.util.Map import java.util.Scanner; Scanner java.util 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();
        int[] a = new int[n];
        Map<Integer, Integer> count = new TreeMap<>(Comparator.reverseOrder());
        int max = 0;
        for (int i = 0; i < n; i++) {
            a[i] = sc.nextInt();
            count.put(a[i], count.getOrDefault(a[i], 0) + 1);
            max = Math.max(a[i], max);
        }

        for (int i = 0; i < n; i++) {
            if (a[i] == max) {
                System.out.println(getNext(count));
            } else {
                System.out.println(max);
            }
        }
    }

    static int getNext(Map<Integer, Integer> count) {
        int loop = 1;
        for (Entry<Integer, Integer> e : count.entrySet()) {
            if (e.getValue() > 1) {
                return e.getKey();
            }

            if (loop > 1) {
                return e.getKey();
            }
            loop++;
        }
        return 0;
    }
} Main public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);

        int n = sc.nextInt();
        int[] a = new int[n];
        Map<Integer, Integer> count = new TreeMap<>(Comparator.reverseOrder());
        int max = 0;
        for (int i = 0; i < n; i++) {
            a[i] = sc.nextInt();
            count.put(a[i], count.getOrDefault(a[i], 0) + 1);
            max = Math.max(a[i], max);
        }

        for (int i = 0; i < n; i++) {
            if (a[i] == max) {
                System.out.println(getNext(count));
            } else {
                System.out.println(max);
            }
        }
    } main {

        Scanner sc = new Scanner(System.in);

        int n = sc.nextInt();
        int[] a = new int[n];
        Map<Integer, Integer> count = new TreeMap<>(Comparator.reverseOrder());
        int max = 0;
        for (int i = 0; i < n; i++) {
            a[i] = sc.nextInt();
            count.put(a[i], count.getOrDefault(a[i], 0) + 1);
            max = Math.max(a[i], max);
        }

        for (int i = 0; i < n; i++) {
            if (a[i] == max) {
                System.out.println(getNext(count));
            } else {
                System.out.println(max);
            }
        }
    } 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 Map<Integer, Integer> count = new TreeMap<>(Comparator.reverseOrder()); count new TreeMap<>(Comparator.reverseOrder()) int max = 0; max 0 for (int i = 0; i < n; i++) {
            a[i] = sc.nextInt();
            count.put(a[i], count.getOrDefault(a[i], 0) + 1);
            max = Math.max(a[i], max);
        } int i = 0; int i = 0; i 0 i < n i n i++ i++ i {
            a[i] = sc.nextInt();
            count.put(a[i], count.getOrDefault(a[i], 0) + 1);
            max = Math.max(a[i], max);
        } {
            a[i] = sc.nextInt();
            count.put(a[i], count.getOrDefault(a[i], 0) + 1);
            max = Math.max(a[i], max);
        } a[i] = sc.nextInt() a[i] a i sc.nextInt() sc.nextInt sc count.put(a[i], count.getOrDefault(a[i], 0) + 1) count.put count a[i] a i count.getOrDefault(a[i], 0) + 1 count.getOrDefault(a[i], 0) count.getOrDefault count a[i] a i 0 1 max = Math.max(a[i], max) max Math.max(a[i], max) Math.max Math a[i] a i max for (int i = 0; i < n; i++) {
            if (a[i] == max) {
                System.out.println(getNext(count));
            } else {
                System.out.println(max);
            }
        } int i = 0; int i = 0; i 0 i < n i n i++ i++ i {
            if (a[i] == max) {
                System.out.println(getNext(count));
            } else {
                System.out.println(max);
            }
        } {
            if (a[i] == max) {
                System.out.println(getNext(count));
            } else {
                System.out.println(max);
            }
        } if (a[i] == max) {
                System.out.println(getNext(count));
            } else {
                System.out.println(max);
            } a[i] == max a[i] a i max {
                System.out.println(getNext(count));
            } System.out.println(getNext(count)) System.out.println System.out System System.out getNext(count) getNext count {
                System.out.println(max);
            } System.out.println(max) System.out.println System.out System System.out max String[] args args static int getNext(Map<Integer, Integer> count) {
        int loop = 1;
        for (Entry<Integer, Integer> e : count.entrySet()) {
            if (e.getValue() > 1) {
                return e.getKey();
            }

            if (loop > 1) {
                return e.getKey();
            }
            loop++;
        }
        return 0;
    } getNext {
        int loop = 1;
        for (Entry<Integer, Integer> e : count.entrySet()) {
            if (e.getValue() > 1) {
                return e.getKey();
            }

            if (loop > 1) {
                return e.getKey();
            }
            loop++;
        }
        return 0;
    } int loop = 1; loop 1 for (Entry<Integer, Integer> e : count.entrySet()) {
            if (e.getValue() > 1) {
                return e.getKey();
            }

            if (loop > 1) {
                return e.getKey();
            }
            loop++;
        } Entry<Integer, Integer> e count.entrySet() count.entrySet count {
            if (e.getValue() > 1) {
                return e.getKey();
            }

            if (loop > 1) {
                return e.getKey();
            }
            loop++;
        } {
            if (e.getValue() > 1) {
                return e.getKey();
            }

            if (loop > 1) {
                return e.getKey();
            }
            loop++;
        } if (e.getValue() > 1) {
                return e.getKey();
            } e.getValue() > 1 e.getValue() e.getValue e 1 {
                return e.getKey();
            } return e.getKey(); e.getKey() e.getKey e if (loop > 1) {
                return e.getKey();
            } loop > 1 loop 1 {
                return e.getKey();
            } return e.getKey(); e.getKey() e.getKey e loop++ loop return 0; 0 Map<Integer, Integer> count count public class Main {

    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);

        int n = sc.nextInt();
        int[] a = new int[n];
        Map<Integer, Integer> count = new TreeMap<>(Comparator.reverseOrder());
        int max = 0;
        for (int i = 0; i < n; i++) {
            a[i] = sc.nextInt();
            count.put(a[i], count.getOrDefault(a[i], 0) + 1);
            max = Math.max(a[i], max);
        }

        for (int i = 0; i < n; i++) {
            if (a[i] == max) {
                System.out.println(getNext(count));
            } else {
                System.out.println(max);
            }
        }
    }

    static int getNext(Map<Integer, Integer> count) {
        int loop = 1;
        for (Entry<Integer, Integer> e : count.entrySet()) {
            if (e.getValue() > 1) {
                return e.getKey();
            }

            if (loop > 1) {
                return e.getKey();
            }
            loop++;
        }
        return 0;
    }
} public class Main {

    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);

        int n = sc.nextInt();
        int[] a = new int[n];
        Map<Integer, Integer> count = new TreeMap<>(Comparator.reverseOrder());
        int max = 0;
        for (int i = 0; i < n; i++) {
            a[i] = sc.nextInt();
            count.put(a[i], count.getOrDefault(a[i], 0) + 1);
            max = Math.max(a[i], max);
        }

        for (int i = 0; i < n; i++) {
            if (a[i] == max) {
                System.out.println(getNext(count));
            } else {
                System.out.println(max);
            }
        }
    }

    static int getNext(Map<Integer, Integer> count) {
        int loop = 1;
        for (Entry<Integer, Integer> e : count.entrySet()) {
            if (e.getValue() > 1) {
                return e.getKey();
            }

            if (loop > 1) {
                return e.getKey();
            }
            loop++;
        }
        return 0;
    }
} Main
import java.util.Comparator;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Scanner;
import java.util.TreeMap;

public class Main {

    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);

        int n = sc.nextInt();
        int[] a = new int[n];
        Map<Integer, Integer> count = new TreeMap<>(Comparator.reverseOrder());
        int max = 0;
        for (int i = 0; i < n; i++) {
            a[i] = sc.nextInt();
            count.put(a[i], count.getOrDefault(a[i], 0) + 1);
            max = Math.max(a[i], max);
        }

        for (int i = 0; i < n; i++) {
            if (a[i] == max) {
                System.out.println(getNext(count));
            } else {
                System.out.println(max);
            }
        }
    }

    static int getNext(Map<Integer, Integer> count) {
        int loop = 1;
        for (Entry<Integer, Integer> e : count.entrySet()) {
            if (e.getValue() > 1) {
                return e.getKey();
            }

            if (loop > 1) {
                return e.getKey();
            }
            loop++;
        }
        return 0;
    }
}
