You are given an array a consisting of n integer numbers.

Let instability of the array be the following value: max_{i = 1}^{n} a_i - min_{i = 1}^{n} a_i.

You have to remove exactly one element from this array to minimize instability of the resulting (n-1)-elements array. Your task is to calculate the minimum possible instability.

Input

The first line of the input contains one integer n (2 ≤ n ≤ 10^5) — the number of elements in the array a.

The second line of the input contains n integers a_1, a_2, ..., a_n (1 ≤ a_i ≤ 10^5) — elements of the array a.

Output

Print one integer — the minimum possible instability of the array if you have to remove exactly one element from the array a.

Examples

Input


4
1 3 3 7


Output


2


Input


2
1 100000


Output


0

Note

In the first example you can remove 7 then instability of the remaining array will be 3 - 1 = 2.

In the second example you can remove either 1 or 100000 then instability of the remaining array will be 100000 - 100000 = 0 and 1 - 1 = 0 correspondingly.
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.io.FilterInputStream;
import java.io.BufferedInputStream;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        ScanReader in = new ScanReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        BArrayStabilization solver = new BArrayStabilization();
        solver.solve(1, in, out);
        out.close();
    }

    static class BArrayStabilization {
        public void solve(int testNumber, ScanReader in, PrintWriter out) {
            int n = in.scanInt();
            int arr[] = new int[n];
            for (int i = 0; i < n; i++) {
                arr[i] = in.scanInt();
            }
            CodeX.sort(arr);
            long ans = Long.MAX_VALUE;
            AVLTree<Integer> avlTree = new AVLTree<>(true);
            for (int i = 0; i < n; i++) {
                avlTree.insert(arr[i], 1);
            }
            for (int i = 0; i < n; i++) {
                avlTree.remove(arr[i], 1);
                ans = Math.min(ans, avlTree.getMaX() - avlTree.getMin());
                avlTree.insert(arr[i], 1);
            }
            out.println(ans);
        }

    }

    static class AVLTree<T extends Comparable<? super T>> {
        private Node<T> root;
        private boolean multi;
        private Node<T> tempNode;

        public AVLTree() {
            this.root = null;
            this.multi = false;
        }

        public AVLTree(boolean multi) {
            this.root = null;
            this.multi = multi;
        }

        public T getMin() {
            if (root == null) return null;
            tempNode = root;
            while (tempNode.left != null) {
                tempNode = tempNode.left;
            }

            return tempNode.data;
        }

        public T getMaX() {
            if (root == null) return null;
            tempNode = root;
            while (tempNode.right != null) {
                tempNode = tempNode.right;
            }
            return tempNode.data;
        }

        public void insert(T data, int... count) {
            if (count.length == 0) root = insert(data, root, 1);
            else {
                if (count[0] > 0) root = insert(data, root, count[0]);
            }
        }

        private Node<T> insert(T data, Node<T> tempRoot, int count) {
            if (tempRoot == null) {
                if (!multi) {

                    return new Node<>(data);
                } else {

                    return new Node<>(data, count);
                }
            }


            int compartor = data.compareTo(tempRoot.data);
            if (compartor < 0) {
                tempRoot.left = insert(data, tempRoot.left, count);
            } else if (compartor > 0) {
                tempRoot.right = insert(data, tempRoot.right, count);
            } else {
                if (multi) {
                    tempRoot.count += count;
                }
            }


            tempRoot.leftcount = getLeftCount(tempRoot.left) + getRightCount(tempRoot.left) + getCount(tempRoot.left);
            tempRoot.rightcount = getLeftCount(tempRoot.right) + getRightCount(tempRoot.right) + getCount(tempRoot.right);


            tempRoot.height = Math.max(Hieght(tempRoot.left), Hieght(tempRoot.right)) + 1;


            long diff = getBalence(tempRoot);

            if (diff > 1) {
                if (data.compareTo(tempRoot.left.data) < 0) {
                    return rotateRight(tempRoot);
                } else {
                    tempRoot.left = rotateLeft(tempRoot.left);
                    return rotateRight(tempRoot);
                }
            } else if (diff < -1) {
                if (data.compareTo(tempRoot.right.data) > 0) {
                    return rotateLeft(tempRoot);
                } else {
                    tempRoot.right = rotateRight(tempRoot.right);
                    return rotateLeft(tempRoot);
                }
            }

            return tempRoot;


        }

        public Node<T> rotateRight(Node<T> node) {
            Node<T> x = node.left;
            Node<T> t2 = x.right;


            x.right = node;
            node.left = t2;


            node.height = Math.max(Hieght(node.right), Hieght(node.left)) + 1;
            x.height = Math.max(Hieght(x.left), Hieght(x.right)) + 1;


            node.leftcount = getLeftCount(node.left) + getRightCount(node.left) + getCount(node.left);
            node.rightcount = getLeftCount(node.right) + getRightCount(node.right) + getCount(node.right);


            x.leftcount = getLeftCount(x.left) + getRightCount(x.left) + getCount(x.left);
            x.rightcount = getLeftCount(x.right) + getRightCount(x.right) + getCount(x.right);

            return x;

        }

        public Node<T> rotateLeft(Node<T> node) {
            Node<T> x = node.right;
            Node<T> t2 = x.left;


            x.left = node;
            node.right = t2;


            node.height = Math.max(Hieght(node.right), Hieght(node.left)) + 1;
            x.height = Math.max(Hieght(x.left), Hieght(x.right)) + 1;


            node.leftcount = getLeftCount(node.left) + getRightCount(node.left) + getCount(node.left);
            node.rightcount = getLeftCount(node.right) + getRightCount(node.right) + getCount(node.right);


            x.leftcount = getLeftCount(x.left) + getRightCount(x.left) + getCount(x.left);
            x.rightcount = getLeftCount(x.right) + getRightCount(x.right) + getCount(x.right);

            return x;

        }

        public long getLeftCount(Node<T> node) {
            if (node == null) return 0;
            return node.leftcount;
        }

        public long getRightCount(Node<T> node) {
            if (node == null) return 0;
            return node.rightcount;
        }

        public long getCount(Node<T> node) {
            if (node == null) return 0;
            return node.count;
        }

        long getBalence(Node<T> node) {
            if (node == null)
                return 0;

            return Hieght(node.left) - Hieght(node.right);
        }

        public long Hieght(Node<T> Node) {
            if (Node == null) return 0;
            else return Node.height;
        }

        public void remove(T data, int c) {
            if (c > 0) root = remove(root, data, c);
        }

        private Node<T> remove(Node<T> tempRoot, T data, long num) {


            if (tempRoot == null) return null;
            int compartor = data.compareTo(tempRoot.data);
            if (compartor < 0) {
                tempRoot.left = remove(tempRoot.left, data, num);
            } else if (compartor > 0) {
                tempRoot.right = remove(tempRoot.right, data, num);
            } else {
                if (multi && num < tempRoot.count && tempRoot.count > 1) {
                    tempRoot.count -= num;
                } else {
                    if (tempRoot.left == null && tempRoot.right == null) {
                        return null;
                    } else if (tempRoot.left == null) return tempRoot.right;
                    else if (tempRoot.right == null) return tempRoot.left;
                    else {
                        Node<T> minValueNode = getMinValueNode(tempRoot.right);

                        tempRoot.data = minValueNode.data;
                        tempRoot.count = minValueNode.count;

                        tempRoot.right = remove(tempRoot.right, tempRoot.data, tempRoot.count);
                    }

                }
            }


            tempRoot.leftcount = getLeftCount(tempRoot.left) + getRightCount(tempRoot.left) + getCount(tempRoot.left);
            tempRoot.rightcount = getLeftCount(tempRoot.right) + getRightCount(tempRoot.right) + getCount(tempRoot.right);

            tempRoot.height = Math.max(Hieght(tempRoot.left), Hieght(tempRoot.right)) + 1;


            long diff = getBalence(tempRoot);

            if (diff > 1) {
                if (getBalence(tempRoot.left) >= 0) {
                    return rotateRight(tempRoot);
                } else {
                    tempRoot.left = rotateLeft(tempRoot.left);
                    return rotateRight(tempRoot);
                }
            } else if (diff < -1) {
                if (getBalence(tempRoot.right) <= 0) {
                    return rotateLeft(tempRoot);
                } else {
                    tempRoot.right = rotateRight(tempRoot.right);
                    return rotateLeft(tempRoot);
                }
            }

            return tempRoot;
        }

        public Node<T> getMinValueNode(Node<T> node) {
            if (node == null) return null;
            Node<T> currentNode = node;
            while (currentNode.left != null) {
                currentNode = currentNode.left;
            }
            return currentNode;
        }

        public class Node<T> {
            T data;
            long height;
            Node<T> left;
            Node<T> right;
            long leftcount;
            long rightcount;
            long count;

            public Node(T data) {
                this.data = data;
                this.height = 1;
                this.left = null;
                this.right = null;
                this.leftcount = 0;
                this.rightcount = 0;
                this.count = 1;
            }

            public Node(T data, int count) {
                this.data = data;
                this.height = 1;
                this.left = null;
                this.right = null;
                this.leftcount = 0;
                this.rightcount = 0;
                this.count = count;
            }

        }

    }

    static class ScanReader {
        private byte[] buf = new byte[4 * 1024];
        private int INDEX;
        private BufferedInputStream in;
        private int TOTAL;

        public ScanReader(InputStream inputStream) {
            in = new BufferedInputStream(inputStream);
        }

        private int scan() {
            if (INDEX >= TOTAL) {
                INDEX = 0;
                try {
                    TOTAL = in.read(buf);
                } catch (Exception e) {
                    e.printStackTrace();
                }
                if (TOTAL <= 0) return -1;
            }
            return buf[INDEX++];
        }

        public int scanInt() {
            int I = 0;
            int n = scan();
            while (isWhiteSpace(n)) n = scan();
            int neg = 1;
            if (n == '-') {
                neg = -1;
                n = scan();
            }
            while (!isWhiteSpace(n)) {
                if (n >= '0' && n <= '9') {
                    I *= 10;
                    I += n - '0';
                    n = scan();
                }
            }
            return neg * I;
        }

        private boolean isWhiteSpace(int n) {
            if (n == ' ' || n == '\n' || n == '\r' || n == '\t' || n == -1) return true;
            else return false;
        }

    }

    static class CodeX {
        public static void sort(int arr[]) {
            merge_sort(arr, 0, arr.length - 1);
        }

        private static void merge_sort(int A[], int start, int end) {
            if (start < end) {
                int mid = (start + end) / 2;
                merge_sort(A, start, mid);
                merge_sort(A, mid + 1, end);
                merge(A, start, mid, end);
            }

        }

        private static void merge(int A[], int start, int mid, int end) {
            int p = start, q = mid + 1;
            int Arr[] = new int[end - start + 1];
            int k = 0;

            for (int i = start; i <= end; i++) {
                if (p > mid)
                    Arr[k++] = A[q++];

                else if (q > end)
                    Arr[k++] = A[p++];

                else if (A[p] < A[q])
                    Arr[k++] = A[p++];

                else
                    Arr[k++] = A[q++];
            }
            for (int i = 0; i < k; i++) {
                A[start++] = Arr[i];
            }

        }

    }
}

