import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        Integer n = scanner.nextInt();
        List<Integer> list = new ArrayList<Integer>();
        for(int index = 0; index < n; index++) {
          list.add(scanner.nextInt());
        }
        
        Integer candidate = Collections.max(list);
        int indexOfCandidate = list.indexOf(candidate);
        list.remove(indexOfCandidate);
        
        Integer secondCandidate = Collections.max(list);
        
        for(int index = 0;index < n; index++) {
          if(index == indexOfCandidate) {
            System.out.println(secondCandidate);
          } else {
            System.out.println(candidate);
          }
        }
}
} import java.util.ArrayList; ArrayList java.util import java.util.Collections; Collections java.util import java.util.List; List java.util import java.util.Scanner; Scanner java.util public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        Integer n = scanner.nextInt();
        List<Integer> list = new ArrayList<Integer>();
        for(int index = 0; index < n; index++) {
          list.add(scanner.nextInt());
        }
        
        Integer candidate = Collections.max(list);
        int indexOfCandidate = list.indexOf(candidate);
        list.remove(indexOfCandidate);
        
        Integer secondCandidate = Collections.max(list);
        
        for(int index = 0;index < n; index++) {
          if(index == indexOfCandidate) {
            System.out.println(secondCandidate);
          } else {
            System.out.println(candidate);
          }
        }
}
} Main public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        Integer n = scanner.nextInt();
        List<Integer> list = new ArrayList<Integer>();
        for(int index = 0; index < n; index++) {
          list.add(scanner.nextInt());
        }
        
        Integer candidate = Collections.max(list);
        int indexOfCandidate = list.indexOf(candidate);
        list.remove(indexOfCandidate);
        
        Integer secondCandidate = Collections.max(list);
        
        for(int index = 0;index < n; index++) {
          if(index == indexOfCandidate) {
            System.out.println(secondCandidate);
          } else {
            System.out.println(candidate);
          }
        }
} main {
        Scanner scanner = new Scanner(System.in);
        Integer n = scanner.nextInt();
        List<Integer> list = new ArrayList<Integer>();
        for(int index = 0; index < n; index++) {
          list.add(scanner.nextInt());
        }
        
        Integer candidate = Collections.max(list);
        int indexOfCandidate = list.indexOf(candidate);
        list.remove(indexOfCandidate);
        
        Integer secondCandidate = Collections.max(list);
        
        for(int index = 0;index < n; index++) {
          if(index == indexOfCandidate) {
            System.out.println(secondCandidate);
          } else {
            System.out.println(candidate);
          }
        }
} Scanner scanner = new Scanner(System.in); scanner new Scanner(System.in) Integer n = scanner.nextInt(); n scanner.nextInt() scanner.nextInt scanner List<Integer> list = new ArrayList<Integer>(); list new ArrayList<Integer>() for(int index = 0; index < n; index++) {
          list.add(scanner.nextInt());
        } int index = 0; int index = 0; index 0 index < n index n index++ index++ index {
          list.add(scanner.nextInt());
        } {
          list.add(scanner.nextInt());
        } list.add(scanner.nextInt()) list.add list scanner.nextInt() scanner.nextInt scanner Integer candidate = Collections.max(list); candidate Collections.max(list) Collections.max Collections list int indexOfCandidate = list.indexOf(candidate); indexOfCandidate list.indexOf(candidate) list.indexOf list candidate list.remove(indexOfCandidate) list.remove list indexOfCandidate Integer secondCandidate = Collections.max(list); secondCandidate Collections.max(list) Collections.max Collections list for(int index = 0;index < n; index++) {
          if(index == indexOfCandidate) {
            System.out.println(secondCandidate);
          } else {
            System.out.println(candidate);
          }
        } int index = 0; int index = 0; index 0 index < n index n index++ index++ index {
          if(index == indexOfCandidate) {
            System.out.println(secondCandidate);
          } else {
            System.out.println(candidate);
          }
        } {
          if(index == indexOfCandidate) {
            System.out.println(secondCandidate);
          } else {
            System.out.println(candidate);
          }
        } if(index == indexOfCandidate) {
            System.out.println(secondCandidate);
          } else {
            System.out.println(candidate);
          } index == indexOfCandidate index indexOfCandidate {
            System.out.println(secondCandidate);
          } System.out.println(secondCandidate) System.out.println System.out System System.out secondCandidate {
            System.out.println(candidate);
          } System.out.println(candidate) System.out.println System.out System System.out candidate String[] args args public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        Integer n = scanner.nextInt();
        List<Integer> list = new ArrayList<Integer>();
        for(int index = 0; index < n; index++) {
          list.add(scanner.nextInt());
        }
        
        Integer candidate = Collections.max(list);
        int indexOfCandidate = list.indexOf(candidate);
        list.remove(indexOfCandidate);
        
        Integer secondCandidate = Collections.max(list);
        
        for(int index = 0;index < n; index++) {
          if(index == indexOfCandidate) {
            System.out.println(secondCandidate);
          } else {
            System.out.println(candidate);
          }
        }
}
} public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        Integer n = scanner.nextInt();
        List<Integer> list = new ArrayList<Integer>();
        for(int index = 0; index < n; index++) {
          list.add(scanner.nextInt());
        }
        
        Integer candidate = Collections.max(list);
        int indexOfCandidate = list.indexOf(candidate);
        list.remove(indexOfCandidate);
        
        Integer secondCandidate = Collections.max(list);
        
        for(int index = 0;index < n; index++) {
          if(index == indexOfCandidate) {
            System.out.println(secondCandidate);
          } else {
            System.out.println(candidate);
          }
        }
}
} Main
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        Integer n = scanner.nextInt();
        List<Integer> list = new ArrayList<Integer>();
        for(int index = 0; index < n; index++) {
          list.add(scanner.nextInt());
        }
        
        Integer candidate = Collections.max(list);
        int indexOfCandidate = list.indexOf(candidate);
        list.remove(indexOfCandidate);
        
        Integer secondCandidate = Collections.max(list);
        
        for(int index = 0;index < n; index++) {
          if(index == indexOfCandidate) {
            System.out.println(secondCandidate);
          } else {
            System.out.println(candidate);
          }
        }
}
}