import java.util.*;

public class Main {
  public static void main(String[] args) {
	  Scanner sc = new Scanner(System.in);
	  int N = Integer.parseInt(sc.next());
	  
	  int[] A = new int[N];
	  int max = 0;
	  int maxIndex = -1;
	  
	  int semimax = 0;
	  for(int i = 0; i < N; i++) {
		  int value = Integer.parseInt(sc.next());
		  A[i] = value;
		  
		  if(value > max) {
			  max = value;
			  maxIndex = i;
		  }
		  else if(value >= semimax) {
			  semimax = value;
		  }
	  }
	  
	  for(int i = 0; i < N; i++) {
		  if(i == maxIndex) {
			  System.out.println(semimax);
		  }
		  else {
			  System.out.println(max);
		  }
		  
	  }
	  
	  sc.close();
	  
  }
} import java.util.*; util.* java public class Main {
  public static void main(String[] args) {
	  Scanner sc = new Scanner(System.in);
	  int N = Integer.parseInt(sc.next());
	  
	  int[] A = new int[N];
	  int max = 0;
	  int maxIndex = -1;
	  
	  int semimax = 0;
	  for(int i = 0; i < N; i++) {
		  int value = Integer.parseInt(sc.next());
		  A[i] = value;
		  
		  if(value > max) {
			  max = value;
			  maxIndex = i;
		  }
		  else if(value >= semimax) {
			  semimax = value;
		  }
	  }
	  
	  for(int i = 0; i < N; i++) {
		  if(i == maxIndex) {
			  System.out.println(semimax);
		  }
		  else {
			  System.out.println(max);
		  }
		  
	  }
	  
	  sc.close();
	  
  }
} Main public static void main(String[] args) {
	  Scanner sc = new Scanner(System.in);
	  int N = Integer.parseInt(sc.next());
	  
	  int[] A = new int[N];
	  int max = 0;
	  int maxIndex = -1;
	  
	  int semimax = 0;
	  for(int i = 0; i < N; i++) {
		  int value = Integer.parseInt(sc.next());
		  A[i] = value;
		  
		  if(value > max) {
			  max = value;
			  maxIndex = i;
		  }
		  else if(value >= semimax) {
			  semimax = value;
		  }
	  }
	  
	  for(int i = 0; i < N; i++) {
		  if(i == maxIndex) {
			  System.out.println(semimax);
		  }
		  else {
			  System.out.println(max);
		  }
		  
	  }
	  
	  sc.close();
	  
  } main {
	  Scanner sc = new Scanner(System.in);
	  int N = Integer.parseInt(sc.next());
	  
	  int[] A = new int[N];
	  int max = 0;
	  int maxIndex = -1;
	  
	  int semimax = 0;
	  for(int i = 0; i < N; i++) {
		  int value = Integer.parseInt(sc.next());
		  A[i] = value;
		  
		  if(value > max) {
			  max = value;
			  maxIndex = i;
		  }
		  else if(value >= semimax) {
			  semimax = value;
		  }
	  }
	  
	  for(int i = 0; i < N; i++) {
		  if(i == maxIndex) {
			  System.out.println(semimax);
		  }
		  else {
			  System.out.println(max);
		  }
		  
	  }
	  
	  sc.close();
	  
  } Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int N = Integer.parseInt(sc.next()); N Integer.parseInt(sc.next()) Integer.parseInt Integer sc.next() sc.next sc int[] A = new int[N]; A new int[N] N int max = 0; max 0 int maxIndex = -1; maxIndex -1 1 int semimax = 0; semimax 0 for(int i = 0; i < N; i++) {
		  int value = Integer.parseInt(sc.next());
		  A[i] = value;
		  
		  if(value > max) {
			  max = value;
			  maxIndex = i;
		  }
		  else if(value >= semimax) {
			  semimax = value;
		  }
	  } int i = 0; int i = 0; i 0 i < N i N i++ i++ i {
		  int value = Integer.parseInt(sc.next());
		  A[i] = value;
		  
		  if(value > max) {
			  max = value;
			  maxIndex = i;
		  }
		  else if(value >= semimax) {
			  semimax = value;
		  }
	  } {
		  int value = Integer.parseInt(sc.next());
		  A[i] = value;
		  
		  if(value > max) {
			  max = value;
			  maxIndex = i;
		  }
		  else if(value >= semimax) {
			  semimax = value;
		  }
	  } int value = Integer.parseInt(sc.next()); value Integer.parseInt(sc.next()) Integer.parseInt Integer sc.next() sc.next sc A[i] = value A[i] A i value if(value > max) {
			  max = value;
			  maxIndex = i;
		  }
		  else if(value >= semimax) {
			  semimax = value;
		  } value > max value max {
			  max = value;
			  maxIndex = i;
		  } max = value max value maxIndex = i maxIndex i if(value >= semimax) {
			  semimax = value;
		  } value >= semimax value semimax {
			  semimax = value;
		  } semimax = value semimax value for(int i = 0; i < N; i++) {
		  if(i == maxIndex) {
			  System.out.println(semimax);
		  }
		  else {
			  System.out.println(max);
		  }
		  
	  } int i = 0; int i = 0; i 0 i < N i N i++ i++ i {
		  if(i == maxIndex) {
			  System.out.println(semimax);
		  }
		  else {
			  System.out.println(max);
		  }
		  
	  } {
		  if(i == maxIndex) {
			  System.out.println(semimax);
		  }
		  else {
			  System.out.println(max);
		  }
		  
	  } if(i == maxIndex) {
			  System.out.println(semimax);
		  }
		  else {
			  System.out.println(max);
		  } i == maxIndex i maxIndex {
			  System.out.println(semimax);
		  } System.out.println(semimax) System.out.println System.out System System.out semimax {
			  System.out.println(max);
		  } System.out.println(max) System.out.println System.out System System.out max sc.close() sc.close sc String[] args args public class Main {
  public static void main(String[] args) {
	  Scanner sc = new Scanner(System.in);
	  int N = Integer.parseInt(sc.next());
	  
	  int[] A = new int[N];
	  int max = 0;
	  int maxIndex = -1;
	  
	  int semimax = 0;
	  for(int i = 0; i < N; i++) {
		  int value = Integer.parseInt(sc.next());
		  A[i] = value;
		  
		  if(value > max) {
			  max = value;
			  maxIndex = i;
		  }
		  else if(value >= semimax) {
			  semimax = value;
		  }
	  }
	  
	  for(int i = 0; i < N; i++) {
		  if(i == maxIndex) {
			  System.out.println(semimax);
		  }
		  else {
			  System.out.println(max);
		  }
		  
	  }
	  
	  sc.close();
	  
  }
} public class Main {
  public static void main(String[] args) {
	  Scanner sc = new Scanner(System.in);
	  int N = Integer.parseInt(sc.next());
	  
	  int[] A = new int[N];
	  int max = 0;
	  int maxIndex = -1;
	  
	  int semimax = 0;
	  for(int i = 0; i < N; i++) {
		  int value = Integer.parseInt(sc.next());
		  A[i] = value;
		  
		  if(value > max) {
			  max = value;
			  maxIndex = i;
		  }
		  else if(value >= semimax) {
			  semimax = value;
		  }
	  }
	  
	  for(int i = 0; i < N; i++) {
		  if(i == maxIndex) {
			  System.out.println(semimax);
		  }
		  else {
			  System.out.println(max);
		  }
		  
	  }
	  
	  sc.close();
	  
  }
} Main
import java.util.*;

public class Main {
  public static void main(String[] args) {
	  Scanner sc = new Scanner(System.in);
	  int N = Integer.parseInt(sc.next());
	  
	  int[] A = new int[N];
	  int max = 0;
	  int maxIndex = -1;
	  
	  int semimax = 0;
	  for(int i = 0; i < N; i++) {
		  int value = Integer.parseInt(sc.next());
		  A[i] = value;
		  
		  if(value > max) {
			  max = value;
			  maxIndex = i;
		  }
		  else if(value >= semimax) {
			  semimax = value;
		  }
	  }
	  
	  for(int i = 0; i < N; i++) {
		  if(i == maxIndex) {
			  System.out.println(semimax);
		  }
		  else {
			  System.out.println(max);
		  }
		  
	  }
	  
	  sc.close();
	  
  }
}
