import java.util.ArrayList;
import java.util.Collections;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        ArrayList<Integer> a = new ArrayList<>();
        for (int i = 0; i < n; i++) {
            a.add(sc.nextInt());
        }
        ArrayList<Integer> b = new ArrayList<>();
        b.addAll(a);
        Collections.sort(b);
        int max = b.get(b.size() - 1);
        int max2 = b.get(b.size() - 2);
        for (int i = 0; i < n; i++) {
            int tmp = a.get(i);
            if(max == tmp) {
                System.out.println(max2);
            } else {
                System.out.println(max);
            }
        }
    }
} import java.util.ArrayList; ArrayList java.util import java.util.Collections; Collections java.util import java.util.Scanner; Scanner java.util public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        ArrayList<Integer> a = new ArrayList<>();
        for (int i = 0; i < n; i++) {
            a.add(sc.nextInt());
        }
        ArrayList<Integer> b = new ArrayList<>();
        b.addAll(a);
        Collections.sort(b);
        int max = b.get(b.size() - 1);
        int max2 = b.get(b.size() - 2);
        for (int i = 0; i < n; i++) {
            int tmp = a.get(i);
            if(max == tmp) {
                System.out.println(max2);
            } else {
                System.out.println(max);
            }
        }
    }
} Main public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        ArrayList<Integer> a = new ArrayList<>();
        for (int i = 0; i < n; i++) {
            a.add(sc.nextInt());
        }
        ArrayList<Integer> b = new ArrayList<>();
        b.addAll(a);
        Collections.sort(b);
        int max = b.get(b.size() - 1);
        int max2 = b.get(b.size() - 2);
        for (int i = 0; i < n; i++) {
            int tmp = a.get(i);
            if(max == tmp) {
                System.out.println(max2);
            } else {
                System.out.println(max);
            }
        }
    } main {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        ArrayList<Integer> a = new ArrayList<>();
        for (int i = 0; i < n; i++) {
            a.add(sc.nextInt());
        }
        ArrayList<Integer> b = new ArrayList<>();
        b.addAll(a);
        Collections.sort(b);
        int max = b.get(b.size() - 1);
        int max2 = b.get(b.size() - 2);
        for (int i = 0; i < n; i++) {
            int tmp = a.get(i);
            if(max == tmp) {
                System.out.println(max2);
            } 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 ArrayList<Integer> a = new ArrayList<>(); a new ArrayList<>() for (int i = 0; i < n; i++) {
            a.add(sc.nextInt());
        } int i = 0; int i = 0; i 0 i < n i n i++ i++ i {
            a.add(sc.nextInt());
        } {
            a.add(sc.nextInt());
        } a.add(sc.nextInt()) a.add a sc.nextInt() sc.nextInt sc ArrayList<Integer> b = new ArrayList<>(); b new ArrayList<>() b.addAll(a) b.addAll b a Collections.sort(b) Collections.sort Collections b int max = b.get(b.size() - 1); max b.get(b.size() - 1) b.get b b.size() - 1 b.size() b.size b 1 int max2 = b.get(b.size() - 2); max2 b.get(b.size() - 2) b.get b b.size() - 2 b.size() b.size b 2 for (int i = 0; i < n; i++) {
            int tmp = a.get(i);
            if(max == tmp) {
                System.out.println(max2);
            } else {
                System.out.println(max);
            }
        } int i = 0; int i = 0; i 0 i < n i n i++ i++ i {
            int tmp = a.get(i);
            if(max == tmp) {
                System.out.println(max2);
            } else {
                System.out.println(max);
            }
        } {
            int tmp = a.get(i);
            if(max == tmp) {
                System.out.println(max2);
            } else {
                System.out.println(max);
            }
        } int tmp = a.get(i); tmp a.get(i) a.get a i if(max == tmp) {
                System.out.println(max2);
            } else {
                System.out.println(max);
            } max == tmp max tmp {
                System.out.println(max2);
            } System.out.println(max2) System.out.println System.out System System.out max2 {
                System.out.println(max);
            } System.out.println(max) System.out.println System.out System System.out max String[] args args public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        ArrayList<Integer> a = new ArrayList<>();
        for (int i = 0; i < n; i++) {
            a.add(sc.nextInt());
        }
        ArrayList<Integer> b = new ArrayList<>();
        b.addAll(a);
        Collections.sort(b);
        int max = b.get(b.size() - 1);
        int max2 = b.get(b.size() - 2);
        for (int i = 0; i < n; i++) {
            int tmp = a.get(i);
            if(max == tmp) {
                System.out.println(max2);
            } else {
                System.out.println(max);
            }
        }
    }
} public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        ArrayList<Integer> a = new ArrayList<>();
        for (int i = 0; i < n; i++) {
            a.add(sc.nextInt());
        }
        ArrayList<Integer> b = new ArrayList<>();
        b.addAll(a);
        Collections.sort(b);
        int max = b.get(b.size() - 1);
        int max2 = b.get(b.size() - 2);
        for (int i = 0; i < n; i++) {
            int tmp = a.get(i);
            if(max == tmp) {
                System.out.println(max2);
            } else {
                System.out.println(max);
            }
        }
    }
} Main
import java.util.ArrayList;
import java.util.Collections;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        ArrayList<Integer> a = new ArrayList<>();
        for (int i = 0; i < n; i++) {
            a.add(sc.nextInt());
        }
        ArrayList<Integer> b = new ArrayList<>();
        b.addAll(a);
        Collections.sort(b);
        int max = b.get(b.size() - 1);
        int max2 = b.get(b.size() - 2);
        for (int i = 0; i < n; i++) {
            int tmp = a.get(i);
            if(max == tmp) {
                System.out.println(max2);
            } else {
                System.out.println(max);
            }
        }
    }
}