import java.util.Scanner;
public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int max_first = 0;
    int max_second = 0;
    int[] a = new int[n];
    for(int i=0; i<n; ++i){
      a[i] = sc.nextInt();
      if(max_first<=a[i]) {
        max_second=max_first;
        max_first=a[i];
      }
      if(max_first>a[i] && max_second<=a[i]) {
        max_second=a[i];
      }
    }
    for(int ii:a) {
      if(ii!=max_first)
        System.out.println(max_first);
      else if(ii!=0)
        System.out.println(max_second);
    }
  }
} import java.util.Scanner; Scanner java.util public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int max_first = 0;
    int max_second = 0;
    int[] a = new int[n];
    for(int i=0; i<n; ++i){
      a[i] = sc.nextInt();
      if(max_first<=a[i]) {
        max_second=max_first;
        max_first=a[i];
      }
      if(max_first>a[i] && max_second<=a[i]) {
        max_second=a[i];
      }
    }
    for(int ii:a) {
      if(ii!=max_first)
        System.out.println(max_first);
      else if(ii!=0)
        System.out.println(max_second);
    }
  }
} Main public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int max_first = 0;
    int max_second = 0;
    int[] a = new int[n];
    for(int i=0; i<n; ++i){
      a[i] = sc.nextInt();
      if(max_first<=a[i]) {
        max_second=max_first;
        max_first=a[i];
      }
      if(max_first>a[i] && max_second<=a[i]) {
        max_second=a[i];
      }
    }
    for(int ii:a) {
      if(ii!=max_first)
        System.out.println(max_first);
      else if(ii!=0)
        System.out.println(max_second);
    }
  } main {
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int max_first = 0;
    int max_second = 0;
    int[] a = new int[n];
    for(int i=0; i<n; ++i){
      a[i] = sc.nextInt();
      if(max_first<=a[i]) {
        max_second=max_first;
        max_first=a[i];
      }
      if(max_first>a[i] && max_second<=a[i]) {
        max_second=a[i];
      }
    }
    for(int ii:a) {
      if(ii!=max_first)
        System.out.println(max_first);
      else if(ii!=0)
        System.out.println(max_second);
    }
  } Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int n = sc.nextInt(); n sc.nextInt() sc.nextInt sc int max_first = 0; max_first 0 int max_second = 0; max_second 0 int[] a = new int[n]; a new int[n] n for(int i=0; i<n; ++i){
      a[i] = sc.nextInt();
      if(max_first<=a[i]) {
        max_second=max_first;
        max_first=a[i];
      }
      if(max_first>a[i] && max_second<=a[i]) {
        max_second=a[i];
      }
    } int i=0; int i=0; i 0 i<n i n ++i ++i i {
      a[i] = sc.nextInt();
      if(max_first<=a[i]) {
        max_second=max_first;
        max_first=a[i];
      }
      if(max_first>a[i] && max_second<=a[i]) {
        max_second=a[i];
      }
    } {
      a[i] = sc.nextInt();
      if(max_first<=a[i]) {
        max_second=max_first;
        max_first=a[i];
      }
      if(max_first>a[i] && max_second<=a[i]) {
        max_second=a[i];
      }
    } a[i] = sc.nextInt() a[i] a i sc.nextInt() sc.nextInt sc if(max_first<=a[i]) {
        max_second=max_first;
        max_first=a[i];
      } max_first<=a[i] max_first a[i] a i {
        max_second=max_first;
        max_first=a[i];
      } max_second=max_first max_second max_first max_first=a[i] max_first a[i] a i if(max_first>a[i] && max_second<=a[i]) {
        max_second=a[i];
      } max_first>a[i] && max_second<=a[i] max_first>a[i] max_first a[i] a i max_second<=a[i] max_second a[i] a i {
        max_second=a[i];
      } max_second=a[i] max_second a[i] a i for(int ii:a) {
      if(ii!=max_first)
        System.out.println(max_first);
      else if(ii!=0)
        System.out.println(max_second);
    } int ii a {
      if(ii!=max_first)
        System.out.println(max_first);
      else if(ii!=0)
        System.out.println(max_second);
    } {
      if(ii!=max_first)
        System.out.println(max_first);
      else if(ii!=0)
        System.out.println(max_second);
    } if(ii!=max_first)
        System.out.println(max_first);
      else if(ii!=0)
        System.out.println(max_second); ii!=max_first ii max_first System.out.println(max_first) System.out.println System.out System System.out max_first if(ii!=0)
        System.out.println(max_second); ii!=0 ii 0 System.out.println(max_second) System.out.println System.out System System.out max_second String[] args args public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int max_first = 0;
    int max_second = 0;
    int[] a = new int[n];
    for(int i=0; i<n; ++i){
      a[i] = sc.nextInt();
      if(max_first<=a[i]) {
        max_second=max_first;
        max_first=a[i];
      }
      if(max_first>a[i] && max_second<=a[i]) {
        max_second=a[i];
      }
    }
    for(int ii:a) {
      if(ii!=max_first)
        System.out.println(max_first);
      else if(ii!=0)
        System.out.println(max_second);
    }
  }
} public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int max_first = 0;
    int max_second = 0;
    int[] a = new int[n];
    for(int i=0; i<n; ++i){
      a[i] = sc.nextInt();
      if(max_first<=a[i]) {
        max_second=max_first;
        max_first=a[i];
      }
      if(max_first>a[i] && max_second<=a[i]) {
        max_second=a[i];
      }
    }
    for(int ii:a) {
      if(ii!=max_first)
        System.out.println(max_first);
      else if(ii!=0)
        System.out.println(max_second);
    }
  }
} Main
import java.util.Scanner;
public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int max_first = 0;
    int max_second = 0;
    int[] a = new int[n];
    for(int i=0; i<n; ++i){
      a[i] = sc.nextInt();
      if(max_first<=a[i]) {
        max_second=max_first;
        max_first=a[i];
      }
      if(max_first>a[i] && max_second<=a[i]) {
        max_second=a[i];
      }
    }
    for(int ii:a) {
      if(ii!=max_first)
        System.out.println(max_first);
      else if(ii!=0)
        System.out.println(max_second);
    }
  }
}