import java.util.*;
import java.io.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int tmp = 0;
    ArrayList<Integer> ans1 = new ArrayList<Integer>();
    ArrayList<Integer> maxcount = new ArrayList<Integer>();
    int count = 0;
    for (int i = 0; i < n; i++) {
      ans1.add(sc.nextInt());
    }
    int ans = Collections.max(ans1);
    for(int i = 0; i < n; i++){
      if (ans == ans1.get(i)) {
        count++;
        maxcount.add(i);
      }
    }
    for(int i = 0; i < n; i++){
      if(count >= 2){
        System.out.println(ans);
      }else{
        if(i == maxcount.get(0)){
          ans1.remove(i);
          tmp = Collections.max(ans1);
          System.out.println(tmp);
          ans1.add(i, ans); 
        }else{
          System.out.println(ans);
        }
      }
    }
  }
} import java.util.*; util.* java import java.io.*; io.* java public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int tmp = 0;
    ArrayList<Integer> ans1 = new ArrayList<Integer>();
    ArrayList<Integer> maxcount = new ArrayList<Integer>();
    int count = 0;
    for (int i = 0; i < n; i++) {
      ans1.add(sc.nextInt());
    }
    int ans = Collections.max(ans1);
    for(int i = 0; i < n; i++){
      if (ans == ans1.get(i)) {
        count++;
        maxcount.add(i);
      }
    }
    for(int i = 0; i < n; i++){
      if(count >= 2){
        System.out.println(ans);
      }else{
        if(i == maxcount.get(0)){
          ans1.remove(i);
          tmp = Collections.max(ans1);
          System.out.println(tmp);
          ans1.add(i, ans); 
        }else{
          System.out.println(ans);
        }
      }
    }
  }
} Main public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int tmp = 0;
    ArrayList<Integer> ans1 = new ArrayList<Integer>();
    ArrayList<Integer> maxcount = new ArrayList<Integer>();
    int count = 0;
    for (int i = 0; i < n; i++) {
      ans1.add(sc.nextInt());
    }
    int ans = Collections.max(ans1);
    for(int i = 0; i < n; i++){
      if (ans == ans1.get(i)) {
        count++;
        maxcount.add(i);
      }
    }
    for(int i = 0; i < n; i++){
      if(count >= 2){
        System.out.println(ans);
      }else{
        if(i == maxcount.get(0)){
          ans1.remove(i);
          tmp = Collections.max(ans1);
          System.out.println(tmp);
          ans1.add(i, ans); 
        }else{
          System.out.println(ans);
        }
      }
    }
  } main {
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int tmp = 0;
    ArrayList<Integer> ans1 = new ArrayList<Integer>();
    ArrayList<Integer> maxcount = new ArrayList<Integer>();
    int count = 0;
    for (int i = 0; i < n; i++) {
      ans1.add(sc.nextInt());
    }
    int ans = Collections.max(ans1);
    for(int i = 0; i < n; i++){
      if (ans == ans1.get(i)) {
        count++;
        maxcount.add(i);
      }
    }
    for(int i = 0; i < n; i++){
      if(count >= 2){
        System.out.println(ans);
      }else{
        if(i == maxcount.get(0)){
          ans1.remove(i);
          tmp = Collections.max(ans1);
          System.out.println(tmp);
          ans1.add(i, ans); 
        }else{
          System.out.println(ans);
        }
      }
    }
  } Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int n = sc.nextInt(); n sc.nextInt() sc.nextInt sc int tmp = 0; tmp 0 ArrayList<Integer> ans1 = new ArrayList<Integer>(); ans1 new ArrayList<Integer>() ArrayList<Integer> maxcount = new ArrayList<Integer>(); maxcount new ArrayList<Integer>() int count = 0; count 0 for (int i = 0; i < n; i++) {
      ans1.add(sc.nextInt());
    } int i = 0; int i = 0; i 0 i < n i n i++ i++ i {
      ans1.add(sc.nextInt());
    } {
      ans1.add(sc.nextInt());
    } ans1.add(sc.nextInt()) ans1.add ans1 sc.nextInt() sc.nextInt sc int ans = Collections.max(ans1); ans Collections.max(ans1) Collections.max Collections ans1 for(int i = 0; i < n; i++){
      if (ans == ans1.get(i)) {
        count++;
        maxcount.add(i);
      }
    } int i = 0; int i = 0; i 0 i < n i n i++ i++ i {
      if (ans == ans1.get(i)) {
        count++;
        maxcount.add(i);
      }
    } {
      if (ans == ans1.get(i)) {
        count++;
        maxcount.add(i);
      }
    } if (ans == ans1.get(i)) {
        count++;
        maxcount.add(i);
      } ans == ans1.get(i) ans ans1.get(i) ans1.get ans1 i {
        count++;
        maxcount.add(i);
      } count++ count maxcount.add(i) maxcount.add maxcount i for(int i = 0; i < n; i++){
      if(count >= 2){
        System.out.println(ans);
      }else{
        if(i == maxcount.get(0)){
          ans1.remove(i);
          tmp = Collections.max(ans1);
          System.out.println(tmp);
          ans1.add(i, ans); 
        }else{
          System.out.println(ans);
        }
      }
    } int i = 0; int i = 0; i 0 i < n i n i++ i++ i {
      if(count >= 2){
        System.out.println(ans);
      }else{
        if(i == maxcount.get(0)){
          ans1.remove(i);
          tmp = Collections.max(ans1);
          System.out.println(tmp);
          ans1.add(i, ans); 
        }else{
          System.out.println(ans);
        }
      }
    } {
      if(count >= 2){
        System.out.println(ans);
      }else{
        if(i == maxcount.get(0)){
          ans1.remove(i);
          tmp = Collections.max(ans1);
          System.out.println(tmp);
          ans1.add(i, ans); 
        }else{
          System.out.println(ans);
        }
      }
    } if(count >= 2){
        System.out.println(ans);
      }else{
        if(i == maxcount.get(0)){
          ans1.remove(i);
          tmp = Collections.max(ans1);
          System.out.println(tmp);
          ans1.add(i, ans); 
        }else{
          System.out.println(ans);
        }
      } count >= 2 count 2 {
        System.out.println(ans);
      } System.out.println(ans) System.out.println System.out System System.out ans {
        if(i == maxcount.get(0)){
          ans1.remove(i);
          tmp = Collections.max(ans1);
          System.out.println(tmp);
          ans1.add(i, ans); 
        }else{
          System.out.println(ans);
        }
      } if(i == maxcount.get(0)){
          ans1.remove(i);
          tmp = Collections.max(ans1);
          System.out.println(tmp);
          ans1.add(i, ans); 
        }else{
          System.out.println(ans);
        } i == maxcount.get(0) i maxcount.get(0) maxcount.get maxcount 0 {
          ans1.remove(i);
          tmp = Collections.max(ans1);
          System.out.println(tmp);
          ans1.add(i, ans); 
        } ans1.remove(i) ans1.remove ans1 i tmp = Collections.max(ans1) tmp Collections.max(ans1) Collections.max Collections ans1 System.out.println(tmp) System.out.println System.out System System.out tmp ans1.add(i, ans) ans1.add ans1 i ans {
          System.out.println(ans);
        } System.out.println(ans) System.out.println System.out System System.out ans String[] args args public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int tmp = 0;
    ArrayList<Integer> ans1 = new ArrayList<Integer>();
    ArrayList<Integer> maxcount = new ArrayList<Integer>();
    int count = 0;
    for (int i = 0; i < n; i++) {
      ans1.add(sc.nextInt());
    }
    int ans = Collections.max(ans1);
    for(int i = 0; i < n; i++){
      if (ans == ans1.get(i)) {
        count++;
        maxcount.add(i);
      }
    }
    for(int i = 0; i < n; i++){
      if(count >= 2){
        System.out.println(ans);
      }else{
        if(i == maxcount.get(0)){
          ans1.remove(i);
          tmp = Collections.max(ans1);
          System.out.println(tmp);
          ans1.add(i, ans); 
        }else{
          System.out.println(ans);
        }
      }
    }
  }
} public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int tmp = 0;
    ArrayList<Integer> ans1 = new ArrayList<Integer>();
    ArrayList<Integer> maxcount = new ArrayList<Integer>();
    int count = 0;
    for (int i = 0; i < n; i++) {
      ans1.add(sc.nextInt());
    }
    int ans = Collections.max(ans1);
    for(int i = 0; i < n; i++){
      if (ans == ans1.get(i)) {
        count++;
        maxcount.add(i);
      }
    }
    for(int i = 0; i < n; i++){
      if(count >= 2){
        System.out.println(ans);
      }else{
        if(i == maxcount.get(0)){
          ans1.remove(i);
          tmp = Collections.max(ans1);
          System.out.println(tmp);
          ans1.add(i, ans); 
        }else{
          System.out.println(ans);
        }
      }
    }
  }
} Main
import java.util.*;
import java.io.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int tmp = 0;
    ArrayList<Integer> ans1 = new ArrayList<Integer>();
    ArrayList<Integer> maxcount = new ArrayList<Integer>();
    int count = 0;
    for (int i = 0; i < n; i++) {
      ans1.add(sc.nextInt());
    }
    int ans = Collections.max(ans1);
    for(int i = 0; i < n; i++){
      if (ans == ans1.get(i)) {
        count++;
        maxcount.add(i);
      }
    }
    for(int i = 0; i < n; i++){
      if(count >= 2){
        System.out.println(ans);
      }else{
        if(i == maxcount.get(0)){
          ans1.remove(i);
          tmp = Collections.max(ans1);
          System.out.println(tmp);
          ans1.add(i, ans); 
        }else{
          System.out.println(ans);
        }
      }
    }
  }
}