import java.util.Scanner;
import java.util.InputMismatchException;

class Main {
   public static void main(String args[]) {
      int N=0;
      int[] z;
      Scanner scanner = new Scanner(System.in);
      N = scanner.nextInt();
      z = new int[N];
      for (int i=0; i<N; i++) {
         z[i] = scanner.nextInt();
      }
      scanner.close();
      int max = -1;
      int count = 0;
      for (int i=0; i<N; i++) {
         if (z[i]>max) {
            //System.out.println(z[i]);
            max = z[i];
         }
      }
      for (int i=0; i<N; i++) {
         if (z[i] == max) {
            count++;
         }
      }
      int max2 = -1;
      for (int i=0; i<N; i++) {
         if (z[i] == max) {
            continue;
         } else if (z[i] > max2) {
            max2 = z[i];
         }
      }

      if (max2 == -1) {
         for (int i=0; i<N; i++) {
            System.out.println(max);
         }
      } else {
         for (int i=0; i<N; i++) {
            if (z[i] == max && count == 1) {
               System.out.println(max2);
            } else {
               System.out.println(max);
            }
         }
      }

   }
} import java.util.Scanner; Scanner java.util import java.util.InputMismatchException; InputMismatchException java.util class Main {
   public static void main(String args[]) {
      int N=0;
      int[] z;
      Scanner scanner = new Scanner(System.in);
      N = scanner.nextInt();
      z = new int[N];
      for (int i=0; i<N; i++) {
         z[i] = scanner.nextInt();
      }
      scanner.close();
      int max = -1;
      int count = 0;
      for (int i=0; i<N; i++) {
         if (z[i]>max) {
            //System.out.println(z[i]);
            max = z[i];
         }
      }
      for (int i=0; i<N; i++) {
         if (z[i] == max) {
            count++;
         }
      }
      int max2 = -1;
      for (int i=0; i<N; i++) {
         if (z[i] == max) {
            continue;
         } else if (z[i] > max2) {
            max2 = z[i];
         }
      }

      if (max2 == -1) {
         for (int i=0; i<N; i++) {
            System.out.println(max);
         }
      } else {
         for (int i=0; i<N; i++) {
            if (z[i] == max && count == 1) {
               System.out.println(max2);
            } else {
               System.out.println(max);
            }
         }
      }

   }
} Main public static void main(String args[]) {
      int N=0;
      int[] z;
      Scanner scanner = new Scanner(System.in);
      N = scanner.nextInt();
      z = new int[N];
      for (int i=0; i<N; i++) {
         z[i] = scanner.nextInt();
      }
      scanner.close();
      int max = -1;
      int count = 0;
      for (int i=0; i<N; i++) {
         if (z[i]>max) {
            //System.out.println(z[i]);
            max = z[i];
         }
      }
      for (int i=0; i<N; i++) {
         if (z[i] == max) {
            count++;
         }
      }
      int max2 = -1;
      for (int i=0; i<N; i++) {
         if (z[i] == max) {
            continue;
         } else if (z[i] > max2) {
            max2 = z[i];
         }
      }

      if (max2 == -1) {
         for (int i=0; i<N; i++) {
            System.out.println(max);
         }
      } else {
         for (int i=0; i<N; i++) {
            if (z[i] == max && count == 1) {
               System.out.println(max2);
            } else {
               System.out.println(max);
            }
         }
      }

   } main {
      int N=0;
      int[] z;
      Scanner scanner = new Scanner(System.in);
      N = scanner.nextInt();
      z = new int[N];
      for (int i=0; i<N; i++) {
         z[i] = scanner.nextInt();
      }
      scanner.close();
      int max = -1;
      int count = 0;
      for (int i=0; i<N; i++) {
         if (z[i]>max) {
            //System.out.println(z[i]);
            max = z[i];
         }
      }
      for (int i=0; i<N; i++) {
         if (z[i] == max) {
            count++;
         }
      }
      int max2 = -1;
      for (int i=0; i<N; i++) {
         if (z[i] == max) {
            continue;
         } else if (z[i] > max2) {
            max2 = z[i];
         }
      }

      if (max2 == -1) {
         for (int i=0; i<N; i++) {
            System.out.println(max);
         }
      } else {
         for (int i=0; i<N; i++) {
            if (z[i] == max && count == 1) {
               System.out.println(max2);
            } else {
               System.out.println(max);
            }
         }
      }

   } int N=0; N 0 int[] z; z Scanner scanner = new Scanner(System.in); scanner new Scanner(System.in) N = scanner.nextInt() N scanner.nextInt() scanner.nextInt scanner z = new int[N] z new int[N] N for (int i=0; i<N; i++) {
         z[i] = scanner.nextInt();
      } int i=0; int i=0; i 0 i<N i N i++ i++ i {
         z[i] = scanner.nextInt();
      } {
         z[i] = scanner.nextInt();
      } z[i] = scanner.nextInt() z[i] z i scanner.nextInt() scanner.nextInt scanner scanner.close() scanner.close scanner int max = -1; max -1 1 int count = 0; count 0 for (int i=0; i<N; i++) {
         if (z[i]>max) {
            //System.out.println(z[i]);
            max = z[i];
         }
      } int i=0; int i=0; i 0 i<N i N i++ i++ i {
         if (z[i]>max) {
            //System.out.println(z[i]);
            max = z[i];
         }
      } {
         if (z[i]>max) {
            //System.out.println(z[i]);
            max = z[i];
         }
      } if (z[i]>max) {
            //System.out.println(z[i]);
            max = z[i];
         } z[i]>max z[i] z i max {
            //System.out.println(z[i]);
            max = z[i];
         } max = z[i] max z[i] z i for (int i=0; i<N; i++) {
         if (z[i] == max) {
            count++;
         }
      } int i=0; int i=0; i 0 i<N i N i++ i++ i {
         if (z[i] == max) {
            count++;
         }
      } {
         if (z[i] == max) {
            count++;
         }
      } if (z[i] == max) {
            count++;
         } z[i] == max z[i] z i max {
            count++;
         } count++ count int max2 = -1; max2 -1 1 for (int i=0; i<N; i++) {
         if (z[i] == max) {
            continue;
         } else if (z[i] > max2) {
            max2 = z[i];
         }
      } int i=0; int i=0; i 0 i<N i N i++ i++ i {
         if (z[i] == max) {
            continue;
         } else if (z[i] > max2) {
            max2 = z[i];
         }
      } {
         if (z[i] == max) {
            continue;
         } else if (z[i] > max2) {
            max2 = z[i];
         }
      } if (z[i] == max) {
            continue;
         } else if (z[i] > max2) {
            max2 = z[i];
         } z[i] == max z[i] z i max {
            continue;
         } continue; if (z[i] > max2) {
            max2 = z[i];
         } z[i] > max2 z[i] z i max2 {
            max2 = z[i];
         } max2 = z[i] max2 z[i] z i if (max2 == -1) {
         for (int i=0; i<N; i++) {
            System.out.println(max);
         }
      } else {
         for (int i=0; i<N; i++) {
            if (z[i] == max && count == 1) {
               System.out.println(max2);
            } else {
               System.out.println(max);
            }
         }
      } max2 == -1 max2 -1 1 {
         for (int i=0; i<N; i++) {
            System.out.println(max);
         }
      } for (int i=0; i<N; i++) {
            System.out.println(max);
         } int i=0; int i=0; i 0 i<N i N i++ i++ i {
            System.out.println(max);
         } {
            System.out.println(max);
         } System.out.println(max) System.out.println System.out System System.out max {
         for (int i=0; i<N; i++) {
            if (z[i] == max && count == 1) {
               System.out.println(max2);
            } else {
               System.out.println(max);
            }
         }
      } for (int i=0; i<N; i++) {
            if (z[i] == max && count == 1) {
               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 (z[i] == max && count == 1) {
               System.out.println(max2);
            } else {
               System.out.println(max);
            }
         } {
            if (z[i] == max && count == 1) {
               System.out.println(max2);
            } else {
               System.out.println(max);
            }
         } if (z[i] == max && count == 1) {
               System.out.println(max2);
            } else {
               System.out.println(max);
            } z[i] == max && count == 1 z[i] == max z[i] z i max count == 1 count 1 {
               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
import java.util.Scanner;
import java.util.InputMismatchException;

class Main {
   public static void main(String args[]) {
      int N=0;
      int[] z;
      Scanner scanner = new Scanner(System.in);
      N = scanner.nextInt();
      z = new int[N];
      for (int i=0; i<N; i++) {
         z[i] = scanner.nextInt();
      }
      scanner.close();
      int max = -1;
      int count = 0;
      for (int i=0; i<N; i++) {
         if (z[i]>max) {
            //System.out.println(z[i]);
            max = z[i];
         }
      }
      for (int i=0; i<N; i++) {
         if (z[i] == max) {
            count++;
         }
      }
      int max2 = -1;
      for (int i=0; i<N; i++) {
         if (z[i] == max) {
            continue;
         } else if (z[i] > max2) {
            max2 = z[i];
         }
      }

      if (max2 == -1) {
         for (int i=0; i<N; i++) {
            System.out.println(max);
         }
      } else {
         for (int i=0; i<N; i++) {
            if (z[i] == max && count == 1) {
               System.out.println(max2);
            } else {
               System.out.println(max);
            }
         }
      }

   }
}
