
import java.util.ArrayList;
import java.util.Random;
import java.util.Scanner;

public class Main {
    public static void main(String[] args){
        Scanner scanner = new Scanner(System.in);
        int N = scanner.nextInt();
        ArrayList<Integer> ary = new ArrayList<>();
        for(int i=0; i<N; i++){
            ary.add(scanner.nextInt());
        }
        ArrayList<Integer> cp = new ArrayList<>(ary);
        quickSort(cp);

        Integer max = cp.get(0);
        for(int i=0; i<N; i++){
            if(ary.get(i) == max){
                System.out.println(cp.get(1));
            }else{
                System.out.println(max);
            }
        }
    }

    public static void swap(ArrayList<Integer> ary, int i, int j){
        Integer tmp = ary.get(i);
        ary.set(i, ary.get(j));
        ary.set(j, tmp);
    }

    public static int selectPivotIndexRondomly(int left, int right){
        Random rand = new Random();
        return rand.nextInt(right-left+1)+left;
    }

    public static void _quickSort(ArrayList<Integer> ary, int left,int right){
        if(left>=right){return;}
        int pivotIndex = selectPivotIndexRondomly(left, right);
        Integer pivot = ary.get(pivotIndex);
        int l=left, r=right;
        while(l<=r){
            while(ary.get(l)>pivot){l++;}
            while(ary.get(r)<pivot){r--;}
            if(l<=r){
                swap(ary, l, r);
                l++; r--;
            }
        }
        _quickSort(ary, left, r);
        _quickSort(ary, l, right);
    }
    public static void quickSort(ArrayList<Integer> ary){
        int l = 0;
        int r = ary.size() - 1;
        _quickSort(ary, l, r);
    }
} import java.util.ArrayList; ArrayList java.util import java.util.Random; Random java.util import java.util.Scanner; Scanner java.util public class Main {
    public static void main(String[] args){
        Scanner scanner = new Scanner(System.in);
        int N = scanner.nextInt();
        ArrayList<Integer> ary = new ArrayList<>();
        for(int i=0; i<N; i++){
            ary.add(scanner.nextInt());
        }
        ArrayList<Integer> cp = new ArrayList<>(ary);
        quickSort(cp);

        Integer max = cp.get(0);
        for(int i=0; i<N; i++){
            if(ary.get(i) == max){
                System.out.println(cp.get(1));
            }else{
                System.out.println(max);
            }
        }
    }

    public static void swap(ArrayList<Integer> ary, int i, int j){
        Integer tmp = ary.get(i);
        ary.set(i, ary.get(j));
        ary.set(j, tmp);
    }

    public static int selectPivotIndexRondomly(int left, int right){
        Random rand = new Random();
        return rand.nextInt(right-left+1)+left;
    }

    public static void _quickSort(ArrayList<Integer> ary, int left,int right){
        if(left>=right){return;}
        int pivotIndex = selectPivotIndexRondomly(left, right);
        Integer pivot = ary.get(pivotIndex);
        int l=left, r=right;
        while(l<=r){
            while(ary.get(l)>pivot){l++;}
            while(ary.get(r)<pivot){r--;}
            if(l<=r){
                swap(ary, l, r);
                l++; r--;
            }
        }
        _quickSort(ary, left, r);
        _quickSort(ary, l, right);
    }
    public static void quickSort(ArrayList<Integer> ary){
        int l = 0;
        int r = ary.size() - 1;
        _quickSort(ary, l, r);
    }
} Main public static void main(String[] args){
        Scanner scanner = new Scanner(System.in);
        int N = scanner.nextInt();
        ArrayList<Integer> ary = new ArrayList<>();
        for(int i=0; i<N; i++){
            ary.add(scanner.nextInt());
        }
        ArrayList<Integer> cp = new ArrayList<>(ary);
        quickSort(cp);

        Integer max = cp.get(0);
        for(int i=0; i<N; i++){
            if(ary.get(i) == max){
                System.out.println(cp.get(1));
            }else{
                System.out.println(max);
            }
        }
    } main {
        Scanner scanner = new Scanner(System.in);
        int N = scanner.nextInt();
        ArrayList<Integer> ary = new ArrayList<>();
        for(int i=0; i<N; i++){
            ary.add(scanner.nextInt());
        }
        ArrayList<Integer> cp = new ArrayList<>(ary);
        quickSort(cp);

        Integer max = cp.get(0);
        for(int i=0; i<N; i++){
            if(ary.get(i) == max){
                System.out.println(cp.get(1));
            }else{
                System.out.println(max);
            }
        }
    } Scanner scanner = new Scanner(System.in); scanner new Scanner(System.in) int N = scanner.nextInt(); N scanner.nextInt() scanner.nextInt scanner ArrayList<Integer> ary = new ArrayList<>(); ary new ArrayList<>() for(int i=0; i<N; i++){
            ary.add(scanner.nextInt());
        } int i=0; int i=0; i 0 i<N i N i++ i++ i {
            ary.add(scanner.nextInt());
        } {
            ary.add(scanner.nextInt());
        } ary.add(scanner.nextInt()) ary.add ary scanner.nextInt() scanner.nextInt scanner ArrayList<Integer> cp = new ArrayList<>(ary); cp new ArrayList<>(ary) quickSort(cp) quickSort cp Integer max = cp.get(0); max cp.get(0) cp.get cp 0 for(int i=0; i<N; i++){
            if(ary.get(i) == max){
                System.out.println(cp.get(1));
            }else{
                System.out.println(max);
            }
        } int i=0; int i=0; i 0 i<N i N i++ i++ i {
            if(ary.get(i) == max){
                System.out.println(cp.get(1));
            }else{
                System.out.println(max);
            }
        } {
            if(ary.get(i) == max){
                System.out.println(cp.get(1));
            }else{
                System.out.println(max);
            }
        } if(ary.get(i) == max){
                System.out.println(cp.get(1));
            }else{
                System.out.println(max);
            } ary.get(i) == max ary.get(i) ary.get ary i max {
                System.out.println(cp.get(1));
            } System.out.println(cp.get(1)) System.out.println System.out System System.out cp.get(1) cp.get cp 1 {
                System.out.println(max);
            } System.out.println(max) System.out.println System.out System System.out max String[] args args public static void swap(ArrayList<Integer> ary, int i, int j){
        Integer tmp = ary.get(i);
        ary.set(i, ary.get(j));
        ary.set(j, tmp);
    } swap {
        Integer tmp = ary.get(i);
        ary.set(i, ary.get(j));
        ary.set(j, tmp);
    } Integer tmp = ary.get(i); tmp ary.get(i) ary.get ary i ary.set(i, ary.get(j)) ary.set ary i ary.get(j) ary.get ary j ary.set(j, tmp) ary.set ary j tmp ArrayList<Integer> ary ary int i i int j j public static int selectPivotIndexRondomly(int left, int right){
        Random rand = new Random();
        return rand.nextInt(right-left+1)+left;
    } selectPivotIndexRondomly {
        Random rand = new Random();
        return rand.nextInt(right-left+1)+left;
    } Random rand = new Random(); rand new Random() return rand.nextInt(right-left+1)+left; rand.nextInt(right-left+1)+left rand.nextInt(right-left+1) rand.nextInt rand right-left+1 right-left right left 1 left int left left int right right public static void _quickSort(ArrayList<Integer> ary, int left,int right){
        if(left>=right){return;}
        int pivotIndex = selectPivotIndexRondomly(left, right);
        Integer pivot = ary.get(pivotIndex);
        int l=left, r=right;
        while(l<=r){
            while(ary.get(l)>pivot){l++;}
            while(ary.get(r)<pivot){r--;}
            if(l<=r){
                swap(ary, l, r);
                l++; r--;
            }
        }
        _quickSort(ary, left, r);
        _quickSort(ary, l, right);
    } _quickSort {
        if(left>=right){return;}
        int pivotIndex = selectPivotIndexRondomly(left, right);
        Integer pivot = ary.get(pivotIndex);
        int l=left, r=right;
        while(l<=r){
            while(ary.get(l)>pivot){l++;}
            while(ary.get(r)<pivot){r--;}
            if(l<=r){
                swap(ary, l, r);
                l++; r--;
            }
        }
        _quickSort(ary, left, r);
        _quickSort(ary, l, right);
    } if(left>=right){return;} left>=right left right {return;} return; int pivotIndex = selectPivotIndexRondomly(left, right); pivotIndex selectPivotIndexRondomly(left, right) selectPivotIndexRondomly left right Integer pivot = ary.get(pivotIndex); pivot ary.get(pivotIndex) ary.get ary pivotIndex int l=left l left r=right; r right while(l<=r){
            while(ary.get(l)>pivot){l++;}
            while(ary.get(r)<pivot){r--;}
            if(l<=r){
                swap(ary, l, r);
                l++; r--;
            }
        } l<=r l r {
            while(ary.get(l)>pivot){l++;}
            while(ary.get(r)<pivot){r--;}
            if(l<=r){
                swap(ary, l, r);
                l++; r--;
            }
        } while(ary.get(l)>pivot){l++;} ary.get(l)>pivot ary.get(l) ary.get ary l pivot {l++;} l++ l while(ary.get(r)<pivot){r--;} ary.get(r)<pivot ary.get(r) ary.get ary r pivot {r--;} r-- r if(l<=r){
                swap(ary, l, r);
                l++; r--;
            } l<=r l r {
                swap(ary, l, r);
                l++; r--;
            } swap(ary, l, r) swap ary l r l++ l r-- r _quickSort(ary, left, r) _quickSort ary left r _quickSort(ary, l, right) _quickSort ary l right ArrayList<Integer> ary ary int left left int right right public static void quickSort(ArrayList<Integer> ary){
        int l = 0;
        int r = ary.size() - 1;
        _quickSort(ary, l, r);
    } quickSort {
        int l = 0;
        int r = ary.size() - 1;
        _quickSort(ary, l, r);
    } int l = 0; l 0 int r = ary.size() - 1; r ary.size() - 1 ary.size() ary.size ary 1 _quickSort(ary, l, r) _quickSort ary l r ArrayList<Integer> ary ary public class Main {
    public static void main(String[] args){
        Scanner scanner = new Scanner(System.in);
        int N = scanner.nextInt();
        ArrayList<Integer> ary = new ArrayList<>();
        for(int i=0; i<N; i++){
            ary.add(scanner.nextInt());
        }
        ArrayList<Integer> cp = new ArrayList<>(ary);
        quickSort(cp);

        Integer max = cp.get(0);
        for(int i=0; i<N; i++){
            if(ary.get(i) == max){
                System.out.println(cp.get(1));
            }else{
                System.out.println(max);
            }
        }
    }

    public static void swap(ArrayList<Integer> ary, int i, int j){
        Integer tmp = ary.get(i);
        ary.set(i, ary.get(j));
        ary.set(j, tmp);
    }

    public static int selectPivotIndexRondomly(int left, int right){
        Random rand = new Random();
        return rand.nextInt(right-left+1)+left;
    }

    public static void _quickSort(ArrayList<Integer> ary, int left,int right){
        if(left>=right){return;}
        int pivotIndex = selectPivotIndexRondomly(left, right);
        Integer pivot = ary.get(pivotIndex);
        int l=left, r=right;
        while(l<=r){
            while(ary.get(l)>pivot){l++;}
            while(ary.get(r)<pivot){r--;}
            if(l<=r){
                swap(ary, l, r);
                l++; r--;
            }
        }
        _quickSort(ary, left, r);
        _quickSort(ary, l, right);
    }
    public static void quickSort(ArrayList<Integer> ary){
        int l = 0;
        int r = ary.size() - 1;
        _quickSort(ary, l, r);
    }
} public class Main {
    public static void main(String[] args){
        Scanner scanner = new Scanner(System.in);
        int N = scanner.nextInt();
        ArrayList<Integer> ary = new ArrayList<>();
        for(int i=0; i<N; i++){
            ary.add(scanner.nextInt());
        }
        ArrayList<Integer> cp = new ArrayList<>(ary);
        quickSort(cp);

        Integer max = cp.get(0);
        for(int i=0; i<N; i++){
            if(ary.get(i) == max){
                System.out.println(cp.get(1));
            }else{
                System.out.println(max);
            }
        }
    }

    public static void swap(ArrayList<Integer> ary, int i, int j){
        Integer tmp = ary.get(i);
        ary.set(i, ary.get(j));
        ary.set(j, tmp);
    }

    public static int selectPivotIndexRondomly(int left, int right){
        Random rand = new Random();
        return rand.nextInt(right-left+1)+left;
    }

    public static void _quickSort(ArrayList<Integer> ary, int left,int right){
        if(left>=right){return;}
        int pivotIndex = selectPivotIndexRondomly(left, right);
        Integer pivot = ary.get(pivotIndex);
        int l=left, r=right;
        while(l<=r){
            while(ary.get(l)>pivot){l++;}
            while(ary.get(r)<pivot){r--;}
            if(l<=r){
                swap(ary, l, r);
                l++; r--;
            }
        }
        _quickSort(ary, left, r);
        _quickSort(ary, l, right);
    }
    public static void quickSort(ArrayList<Integer> ary){
        int l = 0;
        int r = ary.size() - 1;
        _quickSort(ary, l, r);
    }
} Main

import java.util.ArrayList;
import java.util.Random;
import java.util.Scanner;

public class Main {
    public static void main(String[] args){
        Scanner scanner = new Scanner(System.in);
        int N = scanner.nextInt();
        ArrayList<Integer> ary = new ArrayList<>();
        for(int i=0; i<N; i++){
            ary.add(scanner.nextInt());
        }
        ArrayList<Integer> cp = new ArrayList<>(ary);
        quickSort(cp);

        Integer max = cp.get(0);
        for(int i=0; i<N; i++){
            if(ary.get(i) == max){
                System.out.println(cp.get(1));
            }else{
                System.out.println(max);
            }
        }
    }

    public static void swap(ArrayList<Integer> ary, int i, int j){
        Integer tmp = ary.get(i);
        ary.set(i, ary.get(j));
        ary.set(j, tmp);
    }

    public static int selectPivotIndexRondomly(int left, int right){
        Random rand = new Random();
        return rand.nextInt(right-left+1)+left;
    }

    public static void _quickSort(ArrayList<Integer> ary, int left,int right){
        if(left>=right){return;}
        int pivotIndex = selectPivotIndexRondomly(left, right);
        Integer pivot = ary.get(pivotIndex);
        int l=left, r=right;
        while(l<=r){
            while(ary.get(l)>pivot){l++;}
            while(ary.get(r)<pivot){r--;}
            if(l<=r){
                swap(ary, l, r);
                l++; r--;
            }
        }
        _quickSort(ary, left, r);
        _quickSort(ary, l, right);
    }
    public static void quickSort(ArrayList<Integer> ary){
        int l = 0;
        int r = ary.size() - 1;
        _quickSort(ary, l, r);
    }
}
