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 = -1;
    int max2 = -1;
    int maxi = -1;
    for (int i = 0; i < N; i++) {
    	int a = sc.nextInt();
    	if (a > max) {
    		max2 = max;
    		max = a;
    		maxi = i;
    	} else 	if (a > max2) {
    		max2 = a;
    	}
    }
    for (int i = 0; i < N; i++) {
    	System.out.println(i == maxi ? max2 : max);
    }
  }
} 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 = -1;
    int max2 = -1;
    int maxi = -1;
    for (int i = 0; i < N; i++) {
    	int a = sc.nextInt();
    	if (a > max) {
    		max2 = max;
    		max = a;
    		maxi = i;
    	} else 	if (a > max2) {
    		max2 = a;
    	}
    }
    for (int i = 0; i < N; i++) {
    	System.out.println(i == maxi ? max2 : max);
    }
  }
} Main public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    int max = -1;
    int max2 = -1;
    int maxi = -1;
    for (int i = 0; i < N; i++) {
    	int a = sc.nextInt();
    	if (a > max) {
    		max2 = max;
    		max = a;
    		maxi = i;
    	} else 	if (a > max2) {
    		max2 = a;
    	}
    }
    for (int i = 0; i < N; i++) {
    	System.out.println(i == maxi ? max2 : max);
    }
  } main {
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    int max = -1;
    int max2 = -1;
    int maxi = -1;
    for (int i = 0; i < N; i++) {
    	int a = sc.nextInt();
    	if (a > max) {
    		max2 = max;
    		max = a;
    		maxi = i;
    	} else 	if (a > max2) {
    		max2 = a;
    	}
    }
    for (int i = 0; i < N; i++) {
    	System.out.println(i == maxi ? max2 : max);
    }
  } Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int N = sc.nextInt(); N sc.nextInt() sc.nextInt sc int max = -1; max -1 1 int max2 = -1; max2 -1 1 int maxi = -1; maxi -1 1 for (int i = 0; i < N; i++) {
    	int a = sc.nextInt();
    	if (a > max) {
    		max2 = max;
    		max = a;
    		maxi = i;
    	} else 	if (a > max2) {
    		max2 = a;
    	}
    } int i = 0; int i = 0; i 0 i < N i N i++ i++ i {
    	int a = sc.nextInt();
    	if (a > max) {
    		max2 = max;
    		max = a;
    		maxi = i;
    	} else 	if (a > max2) {
    		max2 = a;
    	}
    } {
    	int a = sc.nextInt();
    	if (a > max) {
    		max2 = max;
    		max = a;
    		maxi = i;
    	} else 	if (a > max2) {
    		max2 = a;
    	}
    } int a = sc.nextInt(); a sc.nextInt() sc.nextInt sc if (a > max) {
    		max2 = max;
    		max = a;
    		maxi = i;
    	} else 	if (a > max2) {
    		max2 = a;
    	} a > max a max {
    		max2 = max;
    		max = a;
    		maxi = i;
    	} max2 = max max2 max max = a max a maxi = i maxi i if (a > max2) {
    		max2 = a;
    	} a > max2 a max2 {
    		max2 = a;
    	} max2 = a max2 a for (int i = 0; i < N; i++) {
    	System.out.println(i == maxi ? max2 : max);
    } int i = 0; int i = 0; i 0 i < N i N i++ i++ i {
    	System.out.println(i == maxi ? max2 : max);
    } {
    	System.out.println(i == maxi ? max2 : max);
    } System.out.println(i == maxi ? max2 : max) System.out.println System.out System System.out i == maxi ? max2 : max i == maxi i maxi max2 max String[] args args public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    int max = -1;
    int max2 = -1;
    int maxi = -1;
    for (int i = 0; i < N; i++) {
    	int a = sc.nextInt();
    	if (a > max) {
    		max2 = max;
    		max = a;
    		maxi = i;
    	} else 	if (a > max2) {
    		max2 = a;
    	}
    }
    for (int i = 0; i < N; i++) {
    	System.out.println(i == maxi ? max2 : max);
    }
  }
} public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    int max = -1;
    int max2 = -1;
    int maxi = -1;
    for (int i = 0; i < N; i++) {
    	int a = sc.nextInt();
    	if (a > max) {
    		max2 = max;
    		max = a;
    		maxi = i;
    	} else 	if (a > max2) {
    		max2 = a;
    	}
    }
    for (int i = 0; i < N; i++) {
    	System.out.println(i == maxi ? max2 : max);
    }
  }
} 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 = -1;
    int max2 = -1;
    int maxi = -1;
    for (int i = 0; i < N; i++) {
    	int a = sc.nextInt();
    	if (a > max) {
    		max2 = max;
    		max = a;
    		maxi = i;
    	} else 	if (a > max2) {
    		max2 = a;
    	}
    }
    for (int i = 0; i < N; i++) {
    	System.out.println(i == maxi ? max2 : max);
    }
  }
}
