import java.util.Scanner;

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

    int N = scanner.nextInt();
    int[] a = new int[N];
    int max = 0;
    int nmax = 0;
    int maxi = -1;
    for (int i = 0; i < N; i++) {
      a[i] = scanner.nextInt();
      if (a[i] > max) {
        nmax = max;
        max = a[i];
        maxi = i;
      } else if (a[i] > nmax) {
        nmax = a[i];
      }
    }

    for (int i = 0; i < N; i++) {
      if (i == maxi)
        System.out.println(nmax);
      else
        System.out.println(max);
    }
  }
} import java.util.Scanner; Scanner java.util public class Main {
  public static void main(String[] args) {
    Scanner scanner = new Scanner(System.in);

    int N = scanner.nextInt();
    int[] a = new int[N];
    int max = 0;
    int nmax = 0;
    int maxi = -1;
    for (int i = 0; i < N; i++) {
      a[i] = scanner.nextInt();
      if (a[i] > max) {
        nmax = max;
        max = a[i];
        maxi = i;
      } else if (a[i] > nmax) {
        nmax = a[i];
      }
    }

    for (int i = 0; i < N; i++) {
      if (i == maxi)
        System.out.println(nmax);
      else
        System.out.println(max);
    }
  }
} Main public static void main(String[] args) {
    Scanner scanner = new Scanner(System.in);

    int N = scanner.nextInt();
    int[] a = new int[N];
    int max = 0;
    int nmax = 0;
    int maxi = -1;
    for (int i = 0; i < N; i++) {
      a[i] = scanner.nextInt();
      if (a[i] > max) {
        nmax = max;
        max = a[i];
        maxi = i;
      } else if (a[i] > nmax) {
        nmax = a[i];
      }
    }

    for (int i = 0; i < N; i++) {
      if (i == maxi)
        System.out.println(nmax);
      else
        System.out.println(max);
    }
  } main {
    Scanner scanner = new Scanner(System.in);

    int N = scanner.nextInt();
    int[] a = new int[N];
    int max = 0;
    int nmax = 0;
    int maxi = -1;
    for (int i = 0; i < N; i++) {
      a[i] = scanner.nextInt();
      if (a[i] > max) {
        nmax = max;
        max = a[i];
        maxi = i;
      } else if (a[i] > nmax) {
        nmax = a[i];
      }
    }

    for (int i = 0; i < N; i++) {
      if (i == maxi)
        System.out.println(nmax);
      else
        System.out.println(max);
    }
  } Scanner scanner = new Scanner(System.in); scanner new Scanner(System.in) int N = scanner.nextInt(); N scanner.nextInt() scanner.nextInt scanner int[] a = new int[N]; a new int[N] N int max = 0; max 0 int nmax = 0; nmax 0 int maxi = -1; maxi -1 1 for (int i = 0; i < N; i++) {
      a[i] = scanner.nextInt();
      if (a[i] > max) {
        nmax = max;
        max = a[i];
        maxi = i;
      } else if (a[i] > nmax) {
        nmax = a[i];
      }
    } int i = 0; int i = 0; i 0 i < N i N i++ i++ i {
      a[i] = scanner.nextInt();
      if (a[i] > max) {
        nmax = max;
        max = a[i];
        maxi = i;
      } else if (a[i] > nmax) {
        nmax = a[i];
      }
    } {
      a[i] = scanner.nextInt();
      if (a[i] > max) {
        nmax = max;
        max = a[i];
        maxi = i;
      } else if (a[i] > nmax) {
        nmax = a[i];
      }
    } a[i] = scanner.nextInt() a[i] a i scanner.nextInt() scanner.nextInt scanner if (a[i] > max) {
        nmax = max;
        max = a[i];
        maxi = i;
      } else if (a[i] > nmax) {
        nmax = a[i];
      } a[i] > max a[i] a i max {
        nmax = max;
        max = a[i];
        maxi = i;
      } nmax = max nmax max max = a[i] max a[i] a i maxi = i maxi i if (a[i] > nmax) {
        nmax = a[i];
      } a[i] > nmax a[i] a i nmax {
        nmax = a[i];
      } nmax = a[i] nmax a[i] a i for (int i = 0; i < N; i++) {
      if (i == maxi)
        System.out.println(nmax);
      else
        System.out.println(max);
    } int i = 0; int i = 0; i 0 i < N i N i++ i++ i {
      if (i == maxi)
        System.out.println(nmax);
      else
        System.out.println(max);
    } {
      if (i == maxi)
        System.out.println(nmax);
      else
        System.out.println(max);
    } if (i == maxi)
        System.out.println(nmax);
      else
        System.out.println(max); i == maxi i maxi System.out.println(nmax) System.out.println System.out System System.out nmax 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 scanner = new Scanner(System.in);

    int N = scanner.nextInt();
    int[] a = new int[N];
    int max = 0;
    int nmax = 0;
    int maxi = -1;
    for (int i = 0; i < N; i++) {
      a[i] = scanner.nextInt();
      if (a[i] > max) {
        nmax = max;
        max = a[i];
        maxi = i;
      } else if (a[i] > nmax) {
        nmax = a[i];
      }
    }

    for (int i = 0; i < N; i++) {
      if (i == maxi)
        System.out.println(nmax);
      else
        System.out.println(max);
    }
  }
} public class Main {
  public static void main(String[] args) {
    Scanner scanner = new Scanner(System.in);

    int N = scanner.nextInt();
    int[] a = new int[N];
    int max = 0;
    int nmax = 0;
    int maxi = -1;
    for (int i = 0; i < N; i++) {
      a[i] = scanner.nextInt();
      if (a[i] > max) {
        nmax = max;
        max = a[i];
        maxi = i;
      } else if (a[i] > nmax) {
        nmax = a[i];
      }
    }

    for (int i = 0; i < N; i++) {
      if (i == maxi)
        System.out.println(nmax);
      else
        System.out.println(max);
    }
  }
} Main
import java.util.Scanner;

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

    int N = scanner.nextInt();
    int[] a = new int[N];
    int max = 0;
    int nmax = 0;
    int maxi = -1;
    for (int i = 0; i < N; i++) {
      a[i] = scanner.nextInt();
      if (a[i] > max) {
        nmax = max;
        max = a[i];
        maxi = i;
      } else if (a[i] > nmax) {
        nmax = a[i];
      }
    }

    for (int i = 0; i < N; i++) {
      if (i == maxi)
        System.out.println(nmax);
      else
        System.out.println(max);
    }
  }
}
