import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] arr = new int[n];
        int min = Integer.MAX_VALUE, minIndex = -1;
        int max = Integer.MIN_VALUE;
        for (int i = 0; i < n; i++) {
            arr[i] = sc.nextInt();
        }
        for (int i = 0; i < n; i++) {
            if (arr[i] < min) {
                min = arr[i];
                minIndex = i;
            }
        }
        for (int i = 0; i < n; i++) {
            if (arr[i] > max && i != minIndex) {
                max = arr[i];
            }
        }
        System.out.println(max - min);
    }
} 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[] arr = new int[n];
        int min = Integer.MAX_VALUE, minIndex = -1;
        int max = Integer.MIN_VALUE;
        for (int i = 0; i < n; i++) {
            arr[i] = sc.nextInt();
        }
        for (int i = 0; i < n; i++) {
            if (arr[i] < min) {
                min = arr[i];
                minIndex = i;
            }
        }
        for (int i = 0; i < n; i++) {
            if (arr[i] > max && i != minIndex) {
                max = arr[i];
            }
        }
        System.out.println(max - min);
    }
} Main public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] arr = new int[n];
        int min = Integer.MAX_VALUE, minIndex = -1;
        int max = Integer.MIN_VALUE;
        for (int i = 0; i < n; i++) {
            arr[i] = sc.nextInt();
        }
        for (int i = 0; i < n; i++) {
            if (arr[i] < min) {
                min = arr[i];
                minIndex = i;
            }
        }
        for (int i = 0; i < n; i++) {
            if (arr[i] > max && i != minIndex) {
                max = arr[i];
            }
        }
        System.out.println(max - min);
    } main {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] arr = new int[n];
        int min = Integer.MAX_VALUE, minIndex = -1;
        int max = Integer.MIN_VALUE;
        for (int i = 0; i < n; i++) {
            arr[i] = sc.nextInt();
        }
        for (int i = 0; i < n; i++) {
            if (arr[i] < min) {
                min = arr[i];
                minIndex = i;
            }
        }
        for (int i = 0; i < n; i++) {
            if (arr[i] > max && i != minIndex) {
                max = arr[i];
            }
        }
        System.out.println(max - min);
    } Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int n = sc.nextInt(); n sc.nextInt() sc.nextInt sc int[] arr = new int[n]; arr new int[n] n int min = Integer.MAX_VALUE min Integer.MAX_VALUE Integer Integer.MAX_VALUE minIndex = -1; minIndex -1 1 int max = Integer.MIN_VALUE; max Integer.MIN_VALUE Integer Integer.MIN_VALUE for (int i = 0; i < n; i++) {
            arr[i] = sc.nextInt();
        } int i = 0; int i = 0; i 0 i < n i n i++ i++ i {
            arr[i] = sc.nextInt();
        } {
            arr[i] = sc.nextInt();
        } arr[i] = sc.nextInt() arr[i] arr i sc.nextInt() sc.nextInt sc for (int i = 0; i < n; i++) {
            if (arr[i] < min) {
                min = arr[i];
                minIndex = i;
            }
        } int i = 0; int i = 0; i 0 i < n i n i++ i++ i {
            if (arr[i] < min) {
                min = arr[i];
                minIndex = i;
            }
        } {
            if (arr[i] < min) {
                min = arr[i];
                minIndex = i;
            }
        } if (arr[i] < min) {
                min = arr[i];
                minIndex = i;
            } arr[i] < min arr[i] arr i min {
                min = arr[i];
                minIndex = i;
            } min = arr[i] min arr[i] arr i minIndex = i minIndex i for (int i = 0; i < n; i++) {
            if (arr[i] > max && i != minIndex) {
                max = arr[i];
            }
        } int i = 0; int i = 0; i 0 i < n i n i++ i++ i {
            if (arr[i] > max && i != minIndex) {
                max = arr[i];
            }
        } {
            if (arr[i] > max && i != minIndex) {
                max = arr[i];
            }
        } if (arr[i] > max && i != minIndex) {
                max = arr[i];
            } arr[i] > max && i != minIndex arr[i] > max arr[i] arr i max i != minIndex i minIndex {
                max = arr[i];
            } max = arr[i] max arr[i] arr i System.out.println(max - min) System.out.println System.out System System.out max - min max min String[] args args public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] arr = new int[n];
        int min = Integer.MAX_VALUE, minIndex = -1;
        int max = Integer.MIN_VALUE;
        for (int i = 0; i < n; i++) {
            arr[i] = sc.nextInt();
        }
        for (int i = 0; i < n; i++) {
            if (arr[i] < min) {
                min = arr[i];
                minIndex = i;
            }
        }
        for (int i = 0; i < n; i++) {
            if (arr[i] > max && i != minIndex) {
                max = arr[i];
            }
        }
        System.out.println(max - min);
    }
} public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] arr = new int[n];
        int min = Integer.MAX_VALUE, minIndex = -1;
        int max = Integer.MIN_VALUE;
        for (int i = 0; i < n; i++) {
            arr[i] = sc.nextInt();
        }
        for (int i = 0; i < n; i++) {
            if (arr[i] < min) {
                min = arr[i];
                minIndex = i;
            }
        }
        for (int i = 0; i < n; i++) {
            if (arr[i] > max && i != minIndex) {
                max = arr[i];
            }
        }
        System.out.println(max - min);
    }
} 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[] arr = new int[n];
        int min = Integer.MAX_VALUE, minIndex = -1;
        int max = Integer.MIN_VALUE;
        for (int i = 0; i < n; i++) {
            arr[i] = sc.nextInt();
        }
        for (int i = 0; i < n; i++) {
            if (arr[i] < min) {
                min = arr[i];
                minIndex = i;
            }
        }
        for (int i = 0; i < n; i++) {
            if (arr[i] > max && i != minIndex) {
                max = arr[i];
            }
        }
        System.out.println(max - min);
    }
}
