/*
Stay innocent, be naive. 
But still dream big. 
Dream big to the point that it is beyond your ability and endeavour to achieve it. 
So dream big and don�t lose your innocence.
*/
import java.util.*;
import java.io.*;

   public class Main
   {
      public static void main(String args[]) throws Exception
      {
         BufferedReader infile = new BufferedReader(new InputStreamReader(System.in));  
         StringTokenizer st = new StringTokenizer(infile.readLine());
         int N = Integer.parseInt(st.nextToken());
         int max = 0;
         int max2 = 0;
         int maxcnt = 0;
         int[] arr = new int[N];
         for(int i=0; i < N; i++)
            arr[i] = Integer.parseInt(infile.readLine());
         for(int i=0; i < N; i++)
            max = Math.max(max, arr[i]);
         for(int a: arr)
            if(max == a)
               maxcnt++;
         for(int i=0; i < N; i++)
            if(arr[i] < max)
               max2 = Math.max(max2, arr[i]);
         for(int i=0; i < N; i++)
         {
            if(maxcnt > 1)
               System.out.println(max);
            else
            {
               if(arr[i] == max)
                  System.out.println(max2);
               else
                  System.out.println(max);   
            }
         }
      }
      public static void sort(int[] arr)
      {
         //stable heap sort
         PriorityQueue<Integer> pq = new PriorityQueue<Integer>();
         for(int a: arr)
            pq.add(a);
         for(int i=0; i < arr.length; i++)
            arr[i] = pq.poll();
      }
   } import java.util.*; util.* java import java.io.*; io.* java public class Main
   {
      public static void main(String args[]) throws Exception
      {
         BufferedReader infile = new BufferedReader(new InputStreamReader(System.in));  
         StringTokenizer st = new StringTokenizer(infile.readLine());
         int N = Integer.parseInt(st.nextToken());
         int max = 0;
         int max2 = 0;
         int maxcnt = 0;
         int[] arr = new int[N];
         for(int i=0; i < N; i++)
            arr[i] = Integer.parseInt(infile.readLine());
         for(int i=0; i < N; i++)
            max = Math.max(max, arr[i]);
         for(int a: arr)
            if(max == a)
               maxcnt++;
         for(int i=0; i < N; i++)
            if(arr[i] < max)
               max2 = Math.max(max2, arr[i]);
         for(int i=0; i < N; i++)
         {
            if(maxcnt > 1)
               System.out.println(max);
            else
            {
               if(arr[i] == max)
                  System.out.println(max2);
               else
                  System.out.println(max);   
            }
         }
      }
      public static void sort(int[] arr)
      {
         //stable heap sort
         PriorityQueue<Integer> pq = new PriorityQueue<Integer>();
         for(int a: arr)
            pq.add(a);
         for(int i=0; i < arr.length; i++)
            arr[i] = pq.poll();
      }
   } Main public static void main(String args[]) throws Exception
      {
         BufferedReader infile = new BufferedReader(new InputStreamReader(System.in));  
         StringTokenizer st = new StringTokenizer(infile.readLine());
         int N = Integer.parseInt(st.nextToken());
         int max = 0;
         int max2 = 0;
         int maxcnt = 0;
         int[] arr = new int[N];
         for(int i=0; i < N; i++)
            arr[i] = Integer.parseInt(infile.readLine());
         for(int i=0; i < N; i++)
            max = Math.max(max, arr[i]);
         for(int a: arr)
            if(max == a)
               maxcnt++;
         for(int i=0; i < N; i++)
            if(arr[i] < max)
               max2 = Math.max(max2, arr[i]);
         for(int i=0; i < N; i++)
         {
            if(maxcnt > 1)
               System.out.println(max);
            else
            {
               if(arr[i] == max)
                  System.out.println(max2);
               else
                  System.out.println(max);   
            }
         }
      } main {
         BufferedReader infile = new BufferedReader(new InputStreamReader(System.in));  
         StringTokenizer st = new StringTokenizer(infile.readLine());
         int N = Integer.parseInt(st.nextToken());
         int max = 0;
         int max2 = 0;
         int maxcnt = 0;
         int[] arr = new int[N];
         for(int i=0; i < N; i++)
            arr[i] = Integer.parseInt(infile.readLine());
         for(int i=0; i < N; i++)
            max = Math.max(max, arr[i]);
         for(int a: arr)
            if(max == a)
               maxcnt++;
         for(int i=0; i < N; i++)
            if(arr[i] < max)
               max2 = Math.max(max2, arr[i]);
         for(int i=0; i < N; i++)
         {
            if(maxcnt > 1)
               System.out.println(max);
            else
            {
               if(arr[i] == max)
                  System.out.println(max2);
               else
                  System.out.println(max);   
            }
         }
      } BufferedReader infile = new BufferedReader(new InputStreamReader(System.in)); infile new BufferedReader(new InputStreamReader(System.in)) StringTokenizer st = new StringTokenizer(infile.readLine()); st new StringTokenizer(infile.readLine()) int N = Integer.parseInt(st.nextToken()); N Integer.parseInt(st.nextToken()) Integer.parseInt Integer st.nextToken() st.nextToken st int max = 0; max 0 int max2 = 0; max2 0 int maxcnt = 0; maxcnt 0 int[] arr = new int[N]; arr new int[N] N for(int i=0; i < N; i++)
            arr[i] = Integer.parseInt(infile.readLine()); int i=0; int i=0; i 0 i < N i N i++ i++ i arr[i] = Integer.parseInt(infile.readLine()); arr[i] = Integer.parseInt(infile.readLine()) arr[i] arr i Integer.parseInt(infile.readLine()) Integer.parseInt Integer infile.readLine() infile.readLine infile for(int i=0; i < N; i++)
            max = Math.max(max, arr[i]); int i=0; int i=0; i 0 i < N i N i++ i++ i max = Math.max(max, arr[i]); max = Math.max(max, arr[i]) max Math.max(max, arr[i]) Math.max Math max arr[i] arr i for(int a: arr)
            if(max == a)
               maxcnt++; int a arr if(max == a)
               maxcnt++; if(max == a)
               maxcnt++; max == a max a maxcnt++ maxcnt for(int i=0; i < N; i++)
            if(arr[i] < max)
               max2 = Math.max(max2, arr[i]); int i=0; int i=0; i 0 i < N i N i++ i++ i if(arr[i] < max)
               max2 = Math.max(max2, arr[i]); if(arr[i] < max)
               max2 = Math.max(max2, arr[i]); arr[i] < max arr[i] arr i max max2 = Math.max(max2, arr[i]) max2 Math.max(max2, arr[i]) Math.max Math max2 arr[i] arr i for(int i=0; i < N; i++)
         {
            if(maxcnt > 1)
               System.out.println(max);
            else
            {
               if(arr[i] == max)
                  System.out.println(max2);
               else
                  System.out.println(max);   
            }
         } int i=0; int i=0; i 0 i < N i N i++ i++ i {
            if(maxcnt > 1)
               System.out.println(max);
            else
            {
               if(arr[i] == max)
                  System.out.println(max2);
               else
                  System.out.println(max);   
            }
         } {
            if(maxcnt > 1)
               System.out.println(max);
            else
            {
               if(arr[i] == max)
                  System.out.println(max2);
               else
                  System.out.println(max);   
            }
         } if(maxcnt > 1)
               System.out.println(max);
            else
            {
               if(arr[i] == max)
                  System.out.println(max2);
               else
                  System.out.println(max);   
            } maxcnt > 1 maxcnt 1 System.out.println(max) System.out.println System.out System System.out max {
               if(arr[i] == max)
                  System.out.println(max2);
               else
                  System.out.println(max);   
            } if(arr[i] == max)
                  System.out.println(max2);
               else
                  System.out.println(max); arr[i] == max arr[i] arr i max System.out.println(max2) System.out.println System.out System System.out max2 System.out.println(max) System.out.println System.out System System.out max String args[] args public static void sort(int[] arr)
      {
         //stable heap sort
         PriorityQueue<Integer> pq = new PriorityQueue<Integer>();
         for(int a: arr)
            pq.add(a);
         for(int i=0; i < arr.length; i++)
            arr[i] = pq.poll();
      } sort {
         //stable heap sort
         PriorityQueue<Integer> pq = new PriorityQueue<Integer>();
         for(int a: arr)
            pq.add(a);
         for(int i=0; i < arr.length; i++)
            arr[i] = pq.poll();
      } PriorityQueue<Integer> pq = new PriorityQueue<Integer>(); pq new PriorityQueue<Integer>() for(int a: arr)
            pq.add(a); int a arr pq.add(a); pq.add(a) pq.add pq a for(int i=0; i < arr.length; i++)
            arr[i] = pq.poll(); int i=0; int i=0; i 0 i < arr.length i arr.length arr arr.length i++ i++ i arr[i] = pq.poll(); arr[i] = pq.poll() arr[i] arr i pq.poll() pq.poll pq int[] arr arr public class Main
   {
      public static void main(String args[]) throws Exception
      {
         BufferedReader infile = new BufferedReader(new InputStreamReader(System.in));  
         StringTokenizer st = new StringTokenizer(infile.readLine());
         int N = Integer.parseInt(st.nextToken());
         int max = 0;
         int max2 = 0;
         int maxcnt = 0;
         int[] arr = new int[N];
         for(int i=0; i < N; i++)
            arr[i] = Integer.parseInt(infile.readLine());
         for(int i=0; i < N; i++)
            max = Math.max(max, arr[i]);
         for(int a: arr)
            if(max == a)
               maxcnt++;
         for(int i=0; i < N; i++)
            if(arr[i] < max)
               max2 = Math.max(max2, arr[i]);
         for(int i=0; i < N; i++)
         {
            if(maxcnt > 1)
               System.out.println(max);
            else
            {
               if(arr[i] == max)
                  System.out.println(max2);
               else
                  System.out.println(max);   
            }
         }
      }
      public static void sort(int[] arr)
      {
         //stable heap sort
         PriorityQueue<Integer> pq = new PriorityQueue<Integer>();
         for(int a: arr)
            pq.add(a);
         for(int i=0; i < arr.length; i++)
            arr[i] = pq.poll();
      }
   } public class Main
   {
      public static void main(String args[]) throws Exception
      {
         BufferedReader infile = new BufferedReader(new InputStreamReader(System.in));  
         StringTokenizer st = new StringTokenizer(infile.readLine());
         int N = Integer.parseInt(st.nextToken());
         int max = 0;
         int max2 = 0;
         int maxcnt = 0;
         int[] arr = new int[N];
         for(int i=0; i < N; i++)
            arr[i] = Integer.parseInt(infile.readLine());
         for(int i=0; i < N; i++)
            max = Math.max(max, arr[i]);
         for(int a: arr)
            if(max == a)
               maxcnt++;
         for(int i=0; i < N; i++)
            if(arr[i] < max)
               max2 = Math.max(max2, arr[i]);
         for(int i=0; i < N; i++)
         {
            if(maxcnt > 1)
               System.out.println(max);
            else
            {
               if(arr[i] == max)
                  System.out.println(max2);
               else
                  System.out.println(max);   
            }
         }
      }
      public static void sort(int[] arr)
      {
         //stable heap sort
         PriorityQueue<Integer> pq = new PriorityQueue<Integer>();
         for(int a: arr)
            pq.add(a);
         for(int i=0; i < arr.length; i++)
            arr[i] = pq.poll();
      }
   } Main
/*
Stay innocent, be naive. 
But still dream big. 
Dream big to the point that it is beyond your ability and endeavour to achieve it. 
So dream big and don�t lose your innocence.
*/
import java.util.*;
import java.io.*;

   public class Main
   {
      public static void main(String args[]) throws Exception
      {
         BufferedReader infile = new BufferedReader(new InputStreamReader(System.in));  
         StringTokenizer st = new StringTokenizer(infile.readLine());
         int N = Integer.parseInt(st.nextToken());
         int max = 0;
         int max2 = 0;
         int maxcnt = 0;
         int[] arr = new int[N];
         for(int i=0; i < N; i++)
            arr[i] = Integer.parseInt(infile.readLine());
         for(int i=0; i < N; i++)
            max = Math.max(max, arr[i]);
         for(int a: arr)
            if(max == a)
               maxcnt++;
         for(int i=0; i < N; i++)
            if(arr[i] < max)
               max2 = Math.max(max2, arr[i]);
         for(int i=0; i < N; i++)
         {
            if(maxcnt > 1)
               System.out.println(max);
            else
            {
               if(arr[i] == max)
                  System.out.println(max2);
               else
                  System.out.println(max);   
            }
         }
      }
      public static void sort(int[] arr)
      {
         //stable heap sort
         PriorityQueue<Integer> pq = new PriorityQueue<Integer>();
         for(int a: arr)
            pq.add(a);
         for(int i=0; i < arr.length; i++)
            arr[i] = pq.poll();
      }
   }