import java.util.Scanner;
class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int f = 0;
    int s = 0;
    int index = 0;
    int cur;
    for(int i = 0 ; i < n ; i++){
      cur = Integer.parseInt(sc.next());
      if(cur >= f){
        s = f;
        f = cur;
        index = i;
      }else if(cur > s){
        s = cur;
      }
    }
    for(int i = 0; i < n; i++){
      if(i != index){
        System.out.println(f);
      }else{
        System.out.println(s);
      }
    }
  }
}

 import java.util.Scanner; Scanner java.util class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int f = 0;
    int s = 0;
    int index = 0;
    int cur;
    for(int i = 0 ; i < n ; i++){
      cur = Integer.parseInt(sc.next());
      if(cur >= f){
        s = f;
        f = cur;
        index = i;
      }else if(cur > s){
        s = cur;
      }
    }
    for(int i = 0; i < n; i++){
      if(i != index){
        System.out.println(f);
      }else{
        System.out.println(s);
      }
    }
  }
} Main public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int f = 0;
    int s = 0;
    int index = 0;
    int cur;
    for(int i = 0 ; i < n ; i++){
      cur = Integer.parseInt(sc.next());
      if(cur >= f){
        s = f;
        f = cur;
        index = i;
      }else if(cur > s){
        s = cur;
      }
    }
    for(int i = 0; i < n; i++){
      if(i != index){
        System.out.println(f);
      }else{
        System.out.println(s);
      }
    }
  } main {
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int f = 0;
    int s = 0;
    int index = 0;
    int cur;
    for(int i = 0 ; i < n ; i++){
      cur = Integer.parseInt(sc.next());
      if(cur >= f){
        s = f;
        f = cur;
        index = i;
      }else if(cur > s){
        s = cur;
      }
    }
    for(int i = 0; i < n; i++){
      if(i != index){
        System.out.println(f);
      }else{
        System.out.println(s);
      }
    }
  } Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int n = sc.nextInt(); n sc.nextInt() sc.nextInt sc int f = 0; f 0 int s = 0; s 0 int index = 0; index 0 int cur; cur for(int i = 0 ; i < n ; i++){
      cur = Integer.parseInt(sc.next());
      if(cur >= f){
        s = f;
        f = cur;
        index = i;
      }else if(cur > s){
        s = cur;
      }
    } int i = 0 ; int i = 0 ; i 0 i < n i n i++ i++ i {
      cur = Integer.parseInt(sc.next());
      if(cur >= f){
        s = f;
        f = cur;
        index = i;
      }else if(cur > s){
        s = cur;
      }
    } {
      cur = Integer.parseInt(sc.next());
      if(cur >= f){
        s = f;
        f = cur;
        index = i;
      }else if(cur > s){
        s = cur;
      }
    } cur = Integer.parseInt(sc.next()) cur Integer.parseInt(sc.next()) Integer.parseInt Integer sc.next() sc.next sc if(cur >= f){
        s = f;
        f = cur;
        index = i;
      }else if(cur > s){
        s = cur;
      } cur >= f cur f {
        s = f;
        f = cur;
        index = i;
      } s = f s f f = cur f cur index = i index i if(cur > s){
        s = cur;
      } cur > s cur s {
        s = cur;
      } s = cur s cur for(int i = 0; i < n; i++){
      if(i != index){
        System.out.println(f);
      }else{
        System.out.println(s);
      }
    } int i = 0; int i = 0; i 0 i < n i n i++ i++ i {
      if(i != index){
        System.out.println(f);
      }else{
        System.out.println(s);
      }
    } {
      if(i != index){
        System.out.println(f);
      }else{
        System.out.println(s);
      }
    } if(i != index){
        System.out.println(f);
      }else{
        System.out.println(s);
      } i != index i index {
        System.out.println(f);
      } System.out.println(f) System.out.println System.out System System.out f {
        System.out.println(s);
      } System.out.println(s) System.out.println System.out System System.out s String[] args args
import java.util.Scanner;
class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int f = 0;
    int s = 0;
    int index = 0;
    int cur;
    for(int i = 0 ; i < n ; i++){
      cur = Integer.parseInt(sc.next());
      if(cur >= f){
        s = f;
        f = cur;
        index = i;
      }else if(cur > s){
        s = cur;
      }
    }
    for(int i = 0; i < n; i++){
      if(i != index){
        System.out.println(f);
      }else{
        System.out.println(s);
      }
    }
  }
}


