import java.util.*;

public class Main {
  public static void main (String[] args) {
    Scanner sc = new Scanner(System.in);

    int n = sc.nextInt();
    int[] a = new int[n];

    int max = 0;
    for (int i = 0; i < n; i++) {
      a[i] = sc.nextInt();
      max = Math.max(max, a[i]);
    }

    for (int i = 0; i < n; i++) {
      if (a[i] == max) {
        int ans = 0;
        for (int j = 0; j < n; j++) {
          if(i != j && a[j] == max) {
            ans = max;
            break;
          } else if (i != j) {
            ans = Math.max(ans, a[j]);
          }
        }
        System.out.println(ans);
      } else {
        System.out.println(max);
      }
    }
    
  }
} import java.util.*; util.* java public class Main {
  public static void main (String[] args) {
    Scanner sc = new Scanner(System.in);

    int n = sc.nextInt();
    int[] a = new int[n];

    int max = 0;
    for (int i = 0; i < n; i++) {
      a[i] = sc.nextInt();
      max = Math.max(max, a[i]);
    }

    for (int i = 0; i < n; i++) {
      if (a[i] == max) {
        int ans = 0;
        for (int j = 0; j < n; j++) {
          if(i != j && a[j] == max) {
            ans = max;
            break;
          } else if (i != j) {
            ans = Math.max(ans, a[j]);
          }
        }
        System.out.println(ans);
      } else {
        System.out.println(max);
      }
    }
    
  }
} Main public static void main (String[] args) {
    Scanner sc = new Scanner(System.in);

    int n = sc.nextInt();
    int[] a = new int[n];

    int max = 0;
    for (int i = 0; i < n; i++) {
      a[i] = sc.nextInt();
      max = Math.max(max, a[i]);
    }

    for (int i = 0; i < n; i++) {
      if (a[i] == max) {
        int ans = 0;
        for (int j = 0; j < n; j++) {
          if(i != j && a[j] == max) {
            ans = max;
            break;
          } else if (i != j) {
            ans = Math.max(ans, a[j]);
          }
        }
        System.out.println(ans);
      } else {
        System.out.println(max);
      }
    }
    
  } main {
    Scanner sc = new Scanner(System.in);

    int n = sc.nextInt();
    int[] a = new int[n];

    int max = 0;
    for (int i = 0; i < n; i++) {
      a[i] = sc.nextInt();
      max = Math.max(max, a[i]);
    }

    for (int i = 0; i < n; i++) {
      if (a[i] == max) {
        int ans = 0;
        for (int j = 0; j < n; j++) {
          if(i != j && a[j] == max) {
            ans = max;
            break;
          } else if (i != j) {
            ans = Math.max(ans, a[j]);
          }
        }
        System.out.println(ans);
      } 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[] a = new int[n]; a new int[n] n int max = 0; max 0 for (int i = 0; i < n; i++) {
      a[i] = sc.nextInt();
      max = Math.max(max, a[i]);
    } int i = 0; int i = 0; i 0 i < n i n i++ i++ i {
      a[i] = sc.nextInt();
      max = Math.max(max, a[i]);
    } {
      a[i] = sc.nextInt();
      max = Math.max(max, a[i]);
    } a[i] = sc.nextInt() a[i] a i sc.nextInt() sc.nextInt sc max = Math.max(max, a[i]) max Math.max(max, a[i]) Math.max Math max a[i] a i for (int i = 0; i < n; i++) {
      if (a[i] == max) {
        int ans = 0;
        for (int j = 0; j < n; j++) {
          if(i != j && a[j] == max) {
            ans = max;
            break;
          } else if (i != j) {
            ans = Math.max(ans, a[j]);
          }
        }
        System.out.println(ans);
      } else {
        System.out.println(max);
      }
    } int i = 0; int i = 0; i 0 i < n i n i++ i++ i {
      if (a[i] == max) {
        int ans = 0;
        for (int j = 0; j < n; j++) {
          if(i != j && a[j] == max) {
            ans = max;
            break;
          } else if (i != j) {
            ans = Math.max(ans, a[j]);
          }
        }
        System.out.println(ans);
      } else {
        System.out.println(max);
      }
    } {
      if (a[i] == max) {
        int ans = 0;
        for (int j = 0; j < n; j++) {
          if(i != j && a[j] == max) {
            ans = max;
            break;
          } else if (i != j) {
            ans = Math.max(ans, a[j]);
          }
        }
        System.out.println(ans);
      } else {
        System.out.println(max);
      }
    } if (a[i] == max) {
        int ans = 0;
        for (int j = 0; j < n; j++) {
          if(i != j && a[j] == max) {
            ans = max;
            break;
          } else if (i != j) {
            ans = Math.max(ans, a[j]);
          }
        }
        System.out.println(ans);
      } else {
        System.out.println(max);
      } a[i] == max a[i] a i max {
        int ans = 0;
        for (int j = 0; j < n; j++) {
          if(i != j && a[j] == max) {
            ans = max;
            break;
          } else if (i != j) {
            ans = Math.max(ans, a[j]);
          }
        }
        System.out.println(ans);
      } int ans = 0; ans 0 for (int j = 0; j < n; j++) {
          if(i != j && a[j] == max) {
            ans = max;
            break;
          } else if (i != j) {
            ans = Math.max(ans, a[j]);
          }
        } int j = 0; int j = 0; j 0 j < n j n j++ j++ j {
          if(i != j && a[j] == max) {
            ans = max;
            break;
          } else if (i != j) {
            ans = Math.max(ans, a[j]);
          }
        } {
          if(i != j && a[j] == max) {
            ans = max;
            break;
          } else if (i != j) {
            ans = Math.max(ans, a[j]);
          }
        } if(i != j && a[j] == max) {
            ans = max;
            break;
          } else if (i != j) {
            ans = Math.max(ans, a[j]);
          } i != j && a[j] == max i != j i j a[j] == max a[j] a j max {
            ans = max;
            break;
          } ans = max ans max break; if (i != j) {
            ans = Math.max(ans, a[j]);
          } i != j i j {
            ans = Math.max(ans, a[j]);
          } ans = Math.max(ans, a[j]) ans Math.max(ans, a[j]) Math.max Math ans a[j] a j System.out.println(ans) System.out.println System.out System System.out ans {
        System.out.println(max);
      } System.out.println(max) System.out.println System.out System System.out max String[] args args public class Main {
  public static void main (String[] args) {
    Scanner sc = new Scanner(System.in);

    int n = sc.nextInt();
    int[] a = new int[n];

    int max = 0;
    for (int i = 0; i < n; i++) {
      a[i] = sc.nextInt();
      max = Math.max(max, a[i]);
    }

    for (int i = 0; i < n; i++) {
      if (a[i] == max) {
        int ans = 0;
        for (int j = 0; j < n; j++) {
          if(i != j && a[j] == max) {
            ans = max;
            break;
          } else if (i != j) {
            ans = Math.max(ans, a[j]);
          }
        }
        System.out.println(ans);
      } else {
        System.out.println(max);
      }
    }
    
  }
} public class Main {
  public static void main (String[] args) {
    Scanner sc = new Scanner(System.in);

    int n = sc.nextInt();
    int[] a = new int[n];

    int max = 0;
    for (int i = 0; i < n; i++) {
      a[i] = sc.nextInt();
      max = Math.max(max, a[i]);
    }

    for (int i = 0; i < n; i++) {
      if (a[i] == max) {
        int ans = 0;
        for (int j = 0; j < n; j++) {
          if(i != j && a[j] == max) {
            ans = max;
            break;
          } else if (i != j) {
            ans = Math.max(ans, a[j]);
          }
        }
        System.out.println(ans);
      } else {
        System.out.println(max);
      }
    }
    
  }
} Main
import java.util.*;

public class Main {
  public static void main (String[] args) {
    Scanner sc = new Scanner(System.in);

    int n = sc.nextInt();
    int[] a = new int[n];

    int max = 0;
    for (int i = 0; i < n; i++) {
      a[i] = sc.nextInt();
      max = Math.max(max, a[i]);
    }

    for (int i = 0; i < n; i++) {
      if (a[i] == max) {
        int ans = 0;
        for (int j = 0; j < n; j++) {
          if(i != j && a[j] == max) {
            ans = max;
            break;
          } else if (i != j) {
            ans = Math.max(ans, a[j]);
          }
        }
        System.out.println(ans);
      } else {
        System.out.println(max);
      }
    }
    
  }
}
