import java.util.Scanner;

public class Main {

  public static void main(String[] args) {

    Scanner sc = new Scanner(System.in);

    int n = sc.nextInt();
    int first = 0;
    int second = 0;
    int maxindex = 0;

    for (int i = 0; i < n; i++) {
      int a = sc.nextInt();
      int ftmp = first;
      first = Math.max(ftmp, a);
      if (first > ftmp) {
        maxindex = i;
      }
      second = med(ftmp, second, a);
    }

    for (int i = 0; i < n; i++) {
      if (i == maxindex) {
        System.out.println(second);
      } else {
        System.out.println(first);
      }
    }

  }

  // 3数の中央値を求めるメソッド
  static int med(int a, int b, int c) {
    if (a >= b) {
      if (b >= c) {
        return b;
      } else if (a <= c) {
        return a;
      } else {
        return c;
      }
    } else if (a > c) {
      return a;
    } else if (b > c) {
      return c;
    } else {
      return b;
    }
  }

} 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 first = 0;
    int second = 0;
    int maxindex = 0;

    for (int i = 0; i < n; i++) {
      int a = sc.nextInt();
      int ftmp = first;
      first = Math.max(ftmp, a);
      if (first > ftmp) {
        maxindex = i;
      }
      second = med(ftmp, second, a);
    }

    for (int i = 0; i < n; i++) {
      if (i == maxindex) {
        System.out.println(second);
      } else {
        System.out.println(first);
      }
    }

  }

  // 3数の中央値を求めるメソッド
  static int med(int a, int b, int c) {
    if (a >= b) {
      if (b >= c) {
        return b;
      } else if (a <= c) {
        return a;
      } else {
        return c;
      }
    } else if (a > c) {
      return a;
    } else if (b > c) {
      return c;
    } else {
      return b;
    }
  }

} Main public static void main(String[] args) {

    Scanner sc = new Scanner(System.in);

    int n = sc.nextInt();
    int first = 0;
    int second = 0;
    int maxindex = 0;

    for (int i = 0; i < n; i++) {
      int a = sc.nextInt();
      int ftmp = first;
      first = Math.max(ftmp, a);
      if (first > ftmp) {
        maxindex = i;
      }
      second = med(ftmp, second, a);
    }

    for (int i = 0; i < n; i++) {
      if (i == maxindex) {
        System.out.println(second);
      } else {
        System.out.println(first);
      }
    }

  } main {

    Scanner sc = new Scanner(System.in);

    int n = sc.nextInt();
    int first = 0;
    int second = 0;
    int maxindex = 0;

    for (int i = 0; i < n; i++) {
      int a = sc.nextInt();
      int ftmp = first;
      first = Math.max(ftmp, a);
      if (first > ftmp) {
        maxindex = i;
      }
      second = med(ftmp, second, a);
    }

    for (int i = 0; i < n; i++) {
      if (i == maxindex) {
        System.out.println(second);
      } else {
        System.out.println(first);
      }
    }

  } Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int n = sc.nextInt(); n sc.nextInt() sc.nextInt sc int first = 0; first 0 int second = 0; second 0 int maxindex = 0; maxindex 0 for (int i = 0; i < n; i++) {
      int a = sc.nextInt();
      int ftmp = first;
      first = Math.max(ftmp, a);
      if (first > ftmp) {
        maxindex = i;
      }
      second = med(ftmp, second, a);
    } int i = 0; int i = 0; i 0 i < n i n i++ i++ i {
      int a = sc.nextInt();
      int ftmp = first;
      first = Math.max(ftmp, a);
      if (first > ftmp) {
        maxindex = i;
      }
      second = med(ftmp, second, a);
    } {
      int a = sc.nextInt();
      int ftmp = first;
      first = Math.max(ftmp, a);
      if (first > ftmp) {
        maxindex = i;
      }
      second = med(ftmp, second, a);
    } int a = sc.nextInt(); a sc.nextInt() sc.nextInt sc int ftmp = first; ftmp first first = Math.max(ftmp, a) first Math.max(ftmp, a) Math.max Math ftmp a if (first > ftmp) {
        maxindex = i;
      } first > ftmp first ftmp {
        maxindex = i;
      } maxindex = i maxindex i second = med(ftmp, second, a) second med(ftmp, second, a) med ftmp second a for (int i = 0; i < n; i++) {
      if (i == maxindex) {
        System.out.println(second);
      } else {
        System.out.println(first);
      }
    } int i = 0; int i = 0; i 0 i < n i n i++ i++ i {
      if (i == maxindex) {
        System.out.println(second);
      } else {
        System.out.println(first);
      }
    } {
      if (i == maxindex) {
        System.out.println(second);
      } else {
        System.out.println(first);
      }
    } if (i == maxindex) {
        System.out.println(second);
      } else {
        System.out.println(first);
      } i == maxindex i maxindex {
        System.out.println(second);
      } System.out.println(second) System.out.println System.out System System.out second {
        System.out.println(first);
      } System.out.println(first) System.out.println System.out System System.out first String[] args args // 3数の中央値を求めるメソッド
  static int med(int a, int b, int c) {
    if (a >= b) {
      if (b >= c) {
        return b;
      } else if (a <= c) {
        return a;
      } else {
        return c;
      }
    } else if (a > c) {
      return a;
    } else if (b > c) {
      return c;
    } else {
      return b;
    }
  } med {
    if (a >= b) {
      if (b >= c) {
        return b;
      } else if (a <= c) {
        return a;
      } else {
        return c;
      }
    } else if (a > c) {
      return a;
    } else if (b > c) {
      return c;
    } else {
      return b;
    }
  } if (a >= b) {
      if (b >= c) {
        return b;
      } else if (a <= c) {
        return a;
      } else {
        return c;
      }
    } else if (a > c) {
      return a;
    } else if (b > c) {
      return c;
    } else {
      return b;
    } a >= b a b {
      if (b >= c) {
        return b;
      } else if (a <= c) {
        return a;
      } else {
        return c;
      }
    } if (b >= c) {
        return b;
      } else if (a <= c) {
        return a;
      } else {
        return c;
      } b >= c b c {
        return b;
      } return b; b if (a <= c) {
        return a;
      } else {
        return c;
      } a <= c a c {
        return a;
      } return a; a {
        return c;
      } return c; c if (a > c) {
      return a;
    } else if (b > c) {
      return c;
    } else {
      return b;
    } a > c a c {
      return a;
    } return a; a if (b > c) {
      return c;
    } else {
      return b;
    } b > c b c {
      return c;
    } return c; c {
      return b;
    } return b; b int a a int b b int c c public class Main {

  public static void main(String[] args) {

    Scanner sc = new Scanner(System.in);

    int n = sc.nextInt();
    int first = 0;
    int second = 0;
    int maxindex = 0;

    for (int i = 0; i < n; i++) {
      int a = sc.nextInt();
      int ftmp = first;
      first = Math.max(ftmp, a);
      if (first > ftmp) {
        maxindex = i;
      }
      second = med(ftmp, second, a);
    }

    for (int i = 0; i < n; i++) {
      if (i == maxindex) {
        System.out.println(second);
      } else {
        System.out.println(first);
      }
    }

  }

  // 3数の中央値を求めるメソッド
  static int med(int a, int b, int c) {
    if (a >= b) {
      if (b >= c) {
        return b;
      } else if (a <= c) {
        return a;
      } else {
        return c;
      }
    } else if (a > c) {
      return a;
    } else if (b > c) {
      return c;
    } else {
      return b;
    }
  }

} public class Main {

  public static void main(String[] args) {

    Scanner sc = new Scanner(System.in);

    int n = sc.nextInt();
    int first = 0;
    int second = 0;
    int maxindex = 0;

    for (int i = 0; i < n; i++) {
      int a = sc.nextInt();
      int ftmp = first;
      first = Math.max(ftmp, a);
      if (first > ftmp) {
        maxindex = i;
      }
      second = med(ftmp, second, a);
    }

    for (int i = 0; i < n; i++) {
      if (i == maxindex) {
        System.out.println(second);
      } else {
        System.out.println(first);
      }
    }

  }

  // 3数の中央値を求めるメソッド
  static int med(int a, int b, int c) {
    if (a >= b) {
      if (b >= c) {
        return b;
      } else if (a <= c) {
        return a;
      } else {
        return c;
      }
    } else if (a > c) {
      return a;
    } else if (b > c) {
      return c;
    } else {
      return b;
    }
  }

} 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 first = 0;
    int second = 0;
    int maxindex = 0;

    for (int i = 0; i < n; i++) {
      int a = sc.nextInt();
      int ftmp = first;
      first = Math.max(ftmp, a);
      if (first > ftmp) {
        maxindex = i;
      }
      second = med(ftmp, second, a);
    }

    for (int i = 0; i < n; i++) {
      if (i == maxindex) {
        System.out.println(second);
      } else {
        System.out.println(first);
      }
    }

  }

  // 3数の中央値を求めるメソッド
  static int med(int a, int b, int c) {
    if (a >= b) {
      if (b >= c) {
        return b;
      } else if (a <= c) {
        return a;
      } else {
        return c;
      }
    } else if (a > c) {
      return a;
    } else if (b > c) {
      return c;
    } else {
      return b;
    }
  }

}