import java.util.*;
class Main {
  public static void main(String[] args) {
	Scanner sc = new Scanner(System.in);
  	int n = sc.nextInt();
  	int[] arr = new int[n];
    int max = 0;
  	int sec = 0;
  	for(int i=0;i<n;i++) {
    	arr[i] = sc.nextInt();
    	if(arr[i] > max) {
        	sec = max;
          	max = arr[i];
        }
      	else if(arr[i] > sec){
      		sec = arr[i];
      	}
    }
  	for(int i=0;i<n;i++) {
    	if(arr[i] == max) {
        	System.out.println(sec);
        }
      	else System.out.println(max);
    }
  }
} import java.util.*; util.* java class Main {
  public static void main(String[] args) {
	Scanner sc = new Scanner(System.in);
  	int n = sc.nextInt();
  	int[] arr = new int[n];
    int max = 0;
  	int sec = 0;
  	for(int i=0;i<n;i++) {
    	arr[i] = sc.nextInt();
    	if(arr[i] > max) {
        	sec = max;
          	max = arr[i];
        }
      	else if(arr[i] > sec){
      		sec = arr[i];
      	}
    }
  	for(int i=0;i<n;i++) {
    	if(arr[i] == max) {
        	System.out.println(sec);
        }
      	else System.out.println(max);
    }
  }
} Main public static void main(String[] args) {
	Scanner sc = new Scanner(System.in);
  	int n = sc.nextInt();
  	int[] arr = new int[n];
    int max = 0;
  	int sec = 0;
  	for(int i=0;i<n;i++) {
    	arr[i] = sc.nextInt();
    	if(arr[i] > max) {
        	sec = max;
          	max = arr[i];
        }
      	else if(arr[i] > sec){
      		sec = arr[i];
      	}
    }
  	for(int i=0;i<n;i++) {
    	if(arr[i] == max) {
        	System.out.println(sec);
        }
      	else System.out.println(max);
    }
  } main {
	Scanner sc = new Scanner(System.in);
  	int n = sc.nextInt();
  	int[] arr = new int[n];
    int max = 0;
  	int sec = 0;
  	for(int i=0;i<n;i++) {
    	arr[i] = sc.nextInt();
    	if(arr[i] > max) {
        	sec = max;
          	max = arr[i];
        }
      	else if(arr[i] > sec){
      		sec = arr[i];
      	}
    }
  	for(int i=0;i<n;i++) {
    	if(arr[i] == max) {
        	System.out.println(sec);
        }
      	else System.out.println(max);
    }
  } Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int n = sc.nextInt(); n sc.nextInt() sc.nextInt sc int[] arr = new int[n]; arr new int[n] n int max = 0; max 0 int sec = 0; sec 0 for(int i=0;i<n;i++) {
    	arr[i] = sc.nextInt();
    	if(arr[i] > max) {
        	sec = max;
          	max = arr[i];
        }
      	else if(arr[i] > sec){
      		sec = arr[i];
      	}
    } int i=0; int i=0; i 0 i<n i n i++ i++ i {
    	arr[i] = sc.nextInt();
    	if(arr[i] > max) {
        	sec = max;
          	max = arr[i];
        }
      	else if(arr[i] > sec){
      		sec = arr[i];
      	}
    } {
    	arr[i] = sc.nextInt();
    	if(arr[i] > max) {
        	sec = max;
          	max = arr[i];
        }
      	else if(arr[i] > sec){
      		sec = arr[i];
      	}
    } arr[i] = sc.nextInt() arr[i] arr i sc.nextInt() sc.nextInt sc if(arr[i] > max) {
        	sec = max;
          	max = arr[i];
        }
      	else if(arr[i] > sec){
      		sec = arr[i];
      	} arr[i] > max arr[i] arr i max {
        	sec = max;
          	max = arr[i];
        } sec = max sec max max = arr[i] max arr[i] arr i if(arr[i] > sec){
      		sec = arr[i];
      	} arr[i] > sec arr[i] arr i sec {
      		sec = arr[i];
      	} sec = arr[i] sec arr[i] arr i for(int i=0;i<n;i++) {
    	if(arr[i] == max) {
        	System.out.println(sec);
        }
      	else System.out.println(max);
    } int i=0; int i=0; i 0 i<n i n i++ i++ i {
    	if(arr[i] == max) {
        	System.out.println(sec);
        }
      	else System.out.println(max);
    } {
    	if(arr[i] == max) {
        	System.out.println(sec);
        }
      	else System.out.println(max);
    } if(arr[i] == max) {
        	System.out.println(sec);
        }
      	else System.out.println(max); arr[i] == max arr[i] arr i max {
        	System.out.println(sec);
        } System.out.println(sec) System.out.println System.out System System.out sec System.out.println(max) System.out.println System.out System System.out max String[] args args
import java.util.*;
class Main {
  public static void main(String[] args) {
	Scanner sc = new Scanner(System.in);
  	int n = sc.nextInt();
  	int[] arr = new int[n];
    int max = 0;
  	int sec = 0;
  	for(int i=0;i<n;i++) {
    	arr[i] = sc.nextInt();
    	if(arr[i] > max) {
        	sec = max;
          	max = arr[i];
        }
      	else if(arr[i] > sec){
      		sec = arr[i];
      	}
    }
  	for(int i=0;i<n;i++) {
    	if(arr[i] == max) {
        	System.out.println(sec);
        }
      	else System.out.println(max);
    }
  }
}
