import java.io.*;
import java.util.*;
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        PrintWriter out = new PrintWriter(System.out);
        
        final int N = Integer.parseInt(sc.next());
        int[] ar = new int[N];
        int[] br = new int[N];
        for (int i = 0; i < N; i++) {
            ar[i] = Integer.parseInt(sc.next());
            br[i] = ar[i];
        }
        
        Arrays.sort(br);

        for (int i = 0; i < N; i++) {
            out.println(ar[i] == br[N-1] ? br[N-2] : br[N-1]);
        }
        
        out.flush();
    }
} import java.io.*; io.* java import java.util.*; util.* java public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        PrintWriter out = new PrintWriter(System.out);
        
        final int N = Integer.parseInt(sc.next());
        int[] ar = new int[N];
        int[] br = new int[N];
        for (int i = 0; i < N; i++) {
            ar[i] = Integer.parseInt(sc.next());
            br[i] = ar[i];
        }
        
        Arrays.sort(br);

        for (int i = 0; i < N; i++) {
            out.println(ar[i] == br[N-1] ? br[N-2] : br[N-1]);
        }
        
        out.flush();
    }
} Main public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        PrintWriter out = new PrintWriter(System.out);
        
        final int N = Integer.parseInt(sc.next());
        int[] ar = new int[N];
        int[] br = new int[N];
        for (int i = 0; i < N; i++) {
            ar[i] = Integer.parseInt(sc.next());
            br[i] = ar[i];
        }
        
        Arrays.sort(br);

        for (int i = 0; i < N; i++) {
            out.println(ar[i] == br[N-1] ? br[N-2] : br[N-1]);
        }
        
        out.flush();
    } main {
        Scanner sc = new Scanner(System.in);
        PrintWriter out = new PrintWriter(System.out);
        
        final int N = Integer.parseInt(sc.next());
        int[] ar = new int[N];
        int[] br = new int[N];
        for (int i = 0; i < N; i++) {
            ar[i] = Integer.parseInt(sc.next());
            br[i] = ar[i];
        }
        
        Arrays.sort(br);

        for (int i = 0; i < N; i++) {
            out.println(ar[i] == br[N-1] ? br[N-2] : br[N-1]);
        }
        
        out.flush();
    } Scanner sc = new Scanner(System.in); sc new Scanner(System.in) PrintWriter out = new PrintWriter(System.out); out new PrintWriter(System.out) final int N = Integer.parseInt(sc.next()); N Integer.parseInt(sc.next()) Integer.parseInt Integer sc.next() sc.next sc int[] ar = new int[N]; ar new int[N] N int[] br = new int[N]; br new int[N] N for (int i = 0; i < N; i++) {
            ar[i] = Integer.parseInt(sc.next());
            br[i] = ar[i];
        } int i = 0; int i = 0; i 0 i < N i N i++ i++ i {
            ar[i] = Integer.parseInt(sc.next());
            br[i] = ar[i];
        } {
            ar[i] = Integer.parseInt(sc.next());
            br[i] = ar[i];
        } ar[i] = Integer.parseInt(sc.next()) ar[i] ar i Integer.parseInt(sc.next()) Integer.parseInt Integer sc.next() sc.next sc br[i] = ar[i] br[i] br i ar[i] ar i Arrays.sort(br) Arrays.sort Arrays br for (int i = 0; i < N; i++) {
            out.println(ar[i] == br[N-1] ? br[N-2] : br[N-1]);
        } int i = 0; int i = 0; i 0 i < N i N i++ i++ i {
            out.println(ar[i] == br[N-1] ? br[N-2] : br[N-1]);
        } {
            out.println(ar[i] == br[N-1] ? br[N-2] : br[N-1]);
        } out.println(ar[i] == br[N-1] ? br[N-2] : br[N-1]) out.println out ar[i] == br[N-1] ? br[N-2] : br[N-1] ar[i] == br[N-1] ar[i] ar i br[N-1] br N-1 N 1 br[N-2] br N-2 N 2 br[N-1] br N-1 N 1 out.flush() out.flush out String[] args args public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        PrintWriter out = new PrintWriter(System.out);
        
        final int N = Integer.parseInt(sc.next());
        int[] ar = new int[N];
        int[] br = new int[N];
        for (int i = 0; i < N; i++) {
            ar[i] = Integer.parseInt(sc.next());
            br[i] = ar[i];
        }
        
        Arrays.sort(br);

        for (int i = 0; i < N; i++) {
            out.println(ar[i] == br[N-1] ? br[N-2] : br[N-1]);
        }
        
        out.flush();
    }
} public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        PrintWriter out = new PrintWriter(System.out);
        
        final int N = Integer.parseInt(sc.next());
        int[] ar = new int[N];
        int[] br = new int[N];
        for (int i = 0; i < N; i++) {
            ar[i] = Integer.parseInt(sc.next());
            br[i] = ar[i];
        }
        
        Arrays.sort(br);

        for (int i = 0; i < N; i++) {
            out.println(ar[i] == br[N-1] ? br[N-2] : br[N-1]);
        }
        
        out.flush();
    }
} Main
import java.io.*;
import java.util.*;
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        PrintWriter out = new PrintWriter(System.out);
        
        final int N = Integer.parseInt(sc.next());
        int[] ar = new int[N];
        int[] br = new int[N];
        for (int i = 0; i < N; i++) {
            ar[i] = Integer.parseInt(sc.next());
            br[i] = ar[i];
        }
        
        Arrays.sort(br);

        for (int i = 0; i < N; i++) {
            out.println(ar[i] == br[N-1] ? br[N-2] : br[N-1]);
        }
        
        out.flush();
    }
}