import java.util.*;
import java.io.*;
import java.lang.Math;
public class Main{
    public static void main(String[] args){
        Scanner sn = new Scanner(System.in);


        //入力読み込み
        int i =0;
        int N =0;
		ArrayList<Integer> list = new ArrayList<Integer>();
        while (sn.hasNextLine()) {
        		String str = sn.nextLine();
            try{
                if(i ==0){
                    N = Integer.parseInt(str);
                    if(N<2 || N>200000){
                        System.out.println("error");
                        return;
                    }
                }else{
                    int x = Integer.parseInt(str);
                    if(x<1 || x > 200000){
                        System.out.println("error2");
                        return;
                    }
					list.add(x);
                }
            }catch(Exception e){
                System.out.println("error3");
                //do nothing
                return;
            }
            i++;
            if(i>N){
                break;
            }
        }     
        sn.close();  

        //logic1
		int y = 0;
		try{
		Integer m = Collections.max(list);
		int maxarray = list.indexOf(m);
		list.remove(maxarray);
		Integer n = Collections.max(list);
		
		for (int j = 0; j < N; j++){
			if(j == maxarray){
				System.out.println(n);
			}else{
				System.out.println(m);
			}
		}
		}catch(Exception e){
			System.out.println(e);
		}
	}
  } import java.util.*; util.* java import java.io.*; io.* java import java.lang.Math; Math java.lang public class Main{
    public static void main(String[] args){
        Scanner sn = new Scanner(System.in);


        //入力読み込み
        int i =0;
        int N =0;
		ArrayList<Integer> list = new ArrayList<Integer>();
        while (sn.hasNextLine()) {
        		String str = sn.nextLine();
            try{
                if(i ==0){
                    N = Integer.parseInt(str);
                    if(N<2 || N>200000){
                        System.out.println("error");
                        return;
                    }
                }else{
                    int x = Integer.parseInt(str);
                    if(x<1 || x > 200000){
                        System.out.println("error2");
                        return;
                    }
					list.add(x);
                }
            }catch(Exception e){
                System.out.println("error3");
                //do nothing
                return;
            }
            i++;
            if(i>N){
                break;
            }
        }     
        sn.close();  

        //logic1
		int y = 0;
		try{
		Integer m = Collections.max(list);
		int maxarray = list.indexOf(m);
		list.remove(maxarray);
		Integer n = Collections.max(list);
		
		for (int j = 0; j < N; j++){
			if(j == maxarray){
				System.out.println(n);
			}else{
				System.out.println(m);
			}
		}
		}catch(Exception e){
			System.out.println(e);
		}
	}
  } Main public static void main(String[] args){
        Scanner sn = new Scanner(System.in);


        //入力読み込み
        int i =0;
        int N =0;
		ArrayList<Integer> list = new ArrayList<Integer>();
        while (sn.hasNextLine()) {
        		String str = sn.nextLine();
            try{
                if(i ==0){
                    N = Integer.parseInt(str);
                    if(N<2 || N>200000){
                        System.out.println("error");
                        return;
                    }
                }else{
                    int x = Integer.parseInt(str);
                    if(x<1 || x > 200000){
                        System.out.println("error2");
                        return;
                    }
					list.add(x);
                }
            }catch(Exception e){
                System.out.println("error3");
                //do nothing
                return;
            }
            i++;
            if(i>N){
                break;
            }
        }     
        sn.close();  

        //logic1
		int y = 0;
		try{
		Integer m = Collections.max(list);
		int maxarray = list.indexOf(m);
		list.remove(maxarray);
		Integer n = Collections.max(list);
		
		for (int j = 0; j < N; j++){
			if(j == maxarray){
				System.out.println(n);
			}else{
				System.out.println(m);
			}
		}
		}catch(Exception e){
			System.out.println(e);
		}
	} main {
        Scanner sn = new Scanner(System.in);


        //入力読み込み
        int i =0;
        int N =0;
		ArrayList<Integer> list = new ArrayList<Integer>();
        while (sn.hasNextLine()) {
        		String str = sn.nextLine();
            try{
                if(i ==0){
                    N = Integer.parseInt(str);
                    if(N<2 || N>200000){
                        System.out.println("error");
                        return;
                    }
                }else{
                    int x = Integer.parseInt(str);
                    if(x<1 || x > 200000){
                        System.out.println("error2");
                        return;
                    }
					list.add(x);
                }
            }catch(Exception e){
                System.out.println("error3");
                //do nothing
                return;
            }
            i++;
            if(i>N){
                break;
            }
        }     
        sn.close();  

        //logic1
		int y = 0;
		try{
		Integer m = Collections.max(list);
		int maxarray = list.indexOf(m);
		list.remove(maxarray);
		Integer n = Collections.max(list);
		
		for (int j = 0; j < N; j++){
			if(j == maxarray){
				System.out.println(n);
			}else{
				System.out.println(m);
			}
		}
		}catch(Exception e){
			System.out.println(e);
		}
	} Scanner sn = new Scanner(System.in); sn new Scanner(System.in) int i =0; i 0 int N =0; N 0 ArrayList<Integer> list = new ArrayList<Integer>(); list new ArrayList<Integer>() while (sn.hasNextLine()) {
        		String str = sn.nextLine();
            try{
                if(i ==0){
                    N = Integer.parseInt(str);
                    if(N<2 || N>200000){
                        System.out.println("error");
                        return;
                    }
                }else{
                    int x = Integer.parseInt(str);
                    if(x<1 || x > 200000){
                        System.out.println("error2");
                        return;
                    }
					list.add(x);
                }
            }catch(Exception e){
                System.out.println("error3");
                //do nothing
                return;
            }
            i++;
            if(i>N){
                break;
            }
        } sn.hasNextLine() sn.hasNextLine sn {
        		String str = sn.nextLine();
            try{
                if(i ==0){
                    N = Integer.parseInt(str);
                    if(N<2 || N>200000){
                        System.out.println("error");
                        return;
                    }
                }else{
                    int x = Integer.parseInt(str);
                    if(x<1 || x > 200000){
                        System.out.println("error2");
                        return;
                    }
					list.add(x);
                }
            }catch(Exception e){
                System.out.println("error3");
                //do nothing
                return;
            }
            i++;
            if(i>N){
                break;
            }
        } String str = sn.nextLine(); str sn.nextLine() sn.nextLine sn try{
                if(i ==0){
                    N = Integer.parseInt(str);
                    if(N<2 || N>200000){
                        System.out.println("error");
                        return;
                    }
                }else{
                    int x = Integer.parseInt(str);
                    if(x<1 || x > 200000){
                        System.out.println("error2");
                        return;
                    }
					list.add(x);
                }
            }catch(Exception e){
                System.out.println("error3");
                //do nothing
                return;
            } catch(Exception e){
                System.out.println("error3");
                //do nothing
                return;
            } Exception e {
                System.out.println("error3");
                //do nothing
                return;
            } System.out.println("error3") System.out.println System.out System System.out "error3" return; {
                if(i ==0){
                    N = Integer.parseInt(str);
                    if(N<2 || N>200000){
                        System.out.println("error");
                        return;
                    }
                }else{
                    int x = Integer.parseInt(str);
                    if(x<1 || x > 200000){
                        System.out.println("error2");
                        return;
                    }
					list.add(x);
                }
            } if(i ==0){
                    N = Integer.parseInt(str);
                    if(N<2 || N>200000){
                        System.out.println("error");
                        return;
                    }
                }else{
                    int x = Integer.parseInt(str);
                    if(x<1 || x > 200000){
                        System.out.println("error2");
                        return;
                    }
					list.add(x);
                } i ==0 i 0 {
                    N = Integer.parseInt(str);
                    if(N<2 || N>200000){
                        System.out.println("error");
                        return;
                    }
                } N = Integer.parseInt(str) N Integer.parseInt(str) Integer.parseInt Integer str if(N<2 || N>200000){
                        System.out.println("error");
                        return;
                    } N<2 || N>200000 N<2 N 2 N>200000 N 200000 {
                        System.out.println("error");
                        return;
                    } System.out.println("error") System.out.println System.out System System.out "error" return; {
                    int x = Integer.parseInt(str);
                    if(x<1 || x > 200000){
                        System.out.println("error2");
                        return;
                    }
					list.add(x);
                } int x = Integer.parseInt(str); x Integer.parseInt(str) Integer.parseInt Integer str if(x<1 || x > 200000){
                        System.out.println("error2");
                        return;
                    } x<1 || x > 200000 x<1 x 1 x > 200000 x 200000 {
                        System.out.println("error2");
                        return;
                    } System.out.println("error2") System.out.println System.out System System.out "error2" return; list.add(x) list.add list x i++ i if(i>N){
                break;
            } i>N i N {
                break;
            } break; sn.close() sn.close sn int y = 0; y 0 try{
		Integer m = Collections.max(list);
		int maxarray = list.indexOf(m);
		list.remove(maxarray);
		Integer n = Collections.max(list);
		
		for (int j = 0; j < N; j++){
			if(j == maxarray){
				System.out.println(n);
			}else{
				System.out.println(m);
			}
		}
		}catch(Exception e){
			System.out.println(e);
		} catch(Exception e){
			System.out.println(e);
		} Exception e {
			System.out.println(e);
		} System.out.println(e) System.out.println System.out System System.out e {
		Integer m = Collections.max(list);
		int maxarray = list.indexOf(m);
		list.remove(maxarray);
		Integer n = Collections.max(list);
		
		for (int j = 0; j < N; j++){
			if(j == maxarray){
				System.out.println(n);
			}else{
				System.out.println(m);
			}
		}
		} Integer m = Collections.max(list); m Collections.max(list) Collections.max Collections list int maxarray = list.indexOf(m); maxarray list.indexOf(m) list.indexOf list m list.remove(maxarray) list.remove list maxarray Integer n = Collections.max(list); n Collections.max(list) Collections.max Collections list for (int j = 0; j < N; j++){
			if(j == maxarray){
				System.out.println(n);
			}else{
				System.out.println(m);
			}
		} int j = 0; int j = 0; j 0 j < N j N j++ j++ j {
			if(j == maxarray){
				System.out.println(n);
			}else{
				System.out.println(m);
			}
		} {
			if(j == maxarray){
				System.out.println(n);
			}else{
				System.out.println(m);
			}
		} if(j == maxarray){
				System.out.println(n);
			}else{
				System.out.println(m);
			} j == maxarray j maxarray {
				System.out.println(n);
			} System.out.println(n) System.out.println System.out System System.out n {
				System.out.println(m);
			} System.out.println(m) System.out.println System.out System System.out m String[] args args public class Main{
    public static void main(String[] args){
        Scanner sn = new Scanner(System.in);


        //入力読み込み
        int i =0;
        int N =0;
		ArrayList<Integer> list = new ArrayList<Integer>();
        while (sn.hasNextLine()) {
        		String str = sn.nextLine();
            try{
                if(i ==0){
                    N = Integer.parseInt(str);
                    if(N<2 || N>200000){
                        System.out.println("error");
                        return;
                    }
                }else{
                    int x = Integer.parseInt(str);
                    if(x<1 || x > 200000){
                        System.out.println("error2");
                        return;
                    }
					list.add(x);
                }
            }catch(Exception e){
                System.out.println("error3");
                //do nothing
                return;
            }
            i++;
            if(i>N){
                break;
            }
        }     
        sn.close();  

        //logic1
		int y = 0;
		try{
		Integer m = Collections.max(list);
		int maxarray = list.indexOf(m);
		list.remove(maxarray);
		Integer n = Collections.max(list);
		
		for (int j = 0; j < N; j++){
			if(j == maxarray){
				System.out.println(n);
			}else{
				System.out.println(m);
			}
		}
		}catch(Exception e){
			System.out.println(e);
		}
	}
  } public class Main{
    public static void main(String[] args){
        Scanner sn = new Scanner(System.in);


        //入力読み込み
        int i =0;
        int N =0;
		ArrayList<Integer> list = new ArrayList<Integer>();
        while (sn.hasNextLine()) {
        		String str = sn.nextLine();
            try{
                if(i ==0){
                    N = Integer.parseInt(str);
                    if(N<2 || N>200000){
                        System.out.println("error");
                        return;
                    }
                }else{
                    int x = Integer.parseInt(str);
                    if(x<1 || x > 200000){
                        System.out.println("error2");
                        return;
                    }
					list.add(x);
                }
            }catch(Exception e){
                System.out.println("error3");
                //do nothing
                return;
            }
            i++;
            if(i>N){
                break;
            }
        }     
        sn.close();  

        //logic1
		int y = 0;
		try{
		Integer m = Collections.max(list);
		int maxarray = list.indexOf(m);
		list.remove(maxarray);
		Integer n = Collections.max(list);
		
		for (int j = 0; j < N; j++){
			if(j == maxarray){
				System.out.println(n);
			}else{
				System.out.println(m);
			}
		}
		}catch(Exception e){
			System.out.println(e);
		}
	}
  } Main
import java.util.*;
import java.io.*;
import java.lang.Math;
public class Main{
    public static void main(String[] args){
        Scanner sn = new Scanner(System.in);


        //入力読み込み
        int i =0;
        int N =0;
		ArrayList<Integer> list = new ArrayList<Integer>();
        while (sn.hasNextLine()) {
        		String str = sn.nextLine();
            try{
                if(i ==0){
                    N = Integer.parseInt(str);
                    if(N<2 || N>200000){
                        System.out.println("error");
                        return;
                    }
                }else{
                    int x = Integer.parseInt(str);
                    if(x<1 || x > 200000){
                        System.out.println("error2");
                        return;
                    }
					list.add(x);
                }
            }catch(Exception e){
                System.out.println("error3");
                //do nothing
                return;
            }
            i++;
            if(i>N){
                break;
            }
        }     
        sn.close();  

        //logic1
		int y = 0;
		try{
		Integer m = Collections.max(list);
		int maxarray = list.indexOf(m);
		list.remove(maxarray);
		Integer n = Collections.max(list);
		
		for (int j = 0; j < N; j++){
			if(j == maxarray){
				System.out.println(n);
			}else{
				System.out.println(m);
			}
		}
		}catch(Exception e){
			System.out.println(e);
		}
	}
  }