You are given an integer sequence a_1, a_2, ..., a_n.

Find the number of pairs of indices (l, r) (1 ≤ l ≤ r ≤ n) such that the value of median of a_l, a_{l+1}, ..., a_r is exactly the given number m.

The median of a sequence is the value of an element which is in the middle of the sequence after sorting it in non-decreasing order. If the length of the sequence is even, the left of two middle elements is used.

For example, if a=[4, 2, 7, 5] then its median is 4 since after sorting the sequence, it will look like [2, 4, 5, 7] and the left of two middle elements is equal to 4. The median of [7, 1, 2, 9, 6] equals 6 since after sorting, the value 6 will be in the middle of the sequence.

Write a program to find the number of pairs of indices (l, r) (1 ≤ l ≤ r ≤ n) such that the value of median of a_l, a_{l+1}, ..., a_r is exactly the given number m.

Input

The first line contains integers n and m (1 ≤ n,m ≤ 2⋅10^5) — the length of the given sequence and the required value of the median.

The second line contains an integer sequence a_1, a_2, ..., a_n (1 ≤ a_i ≤ 2⋅10^5).

Output

Print the required number.

Examples

Input

5 4
1 4 5 60 4


Output

8


Input

3 1
1 1 1


Output

6


Input

15 2
1 2 3 1 2 3 1 2 3 1 2 3 1 2 3


Output

97

Note

In the first example, the suitable pairs of indices are: (1, 3), (1, 4), (1, 5), (2, 2), (2, 3), (2, 5), (4, 5) and (5, 5).
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.io.BufferedWriter;
import java.util.InputMismatchException;
import java.io.IOException;
import java.io.Writer;
import java.io.OutputStreamWriter;
import java.io.InputStream;

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

    static class E1MedianOnSegmentsPermutationsEdition {
        int[] array;

        public void solve(int testNumber, InputReader in, OutputWriter out) {
            int n = in.readInt();
            int median = in.readInt();
            int im = -1;
            array = new int[n];
            for (int i = 0; i < n; ++i) {
                array[i] = in.readInt();
                if (array[i] == median) im = i;
            }
            long ans = count(median) - count(median + 1);
            out.printLine(ans);
        }

        private long count(int median) {
            int n = array.length;
            int[] psum = new int[n];
            long res = 0;
            Bst bst = new Bst(n);
            bst.add(0);
            for (int i = 0; i < n; ++i) {
                psum[i] = array[i] >= median ? +1 : -1;
                if (i > 0) psum[i] += psum[i - 1];
                res += bst.nLess(psum[i]);
                bst.add(psum[i]);
            }
            return res;
        }

        class Bst extends AbstractBST<Integer> {
            int[] ndup;
            int[] tsize;

            public Bst(int size) {
                super(size);
                ndup = new int[size + 2];
                tsize = new int[size + 2];
            }


            public void found(int cur, Integer nobj) {
                ndup[cur]++;
            }


            public void create(int cur, Integer nobj) {
                tsize[cur] = ndup[cur] = 1;
            }


            public void before(int cur, Integer nobj) {

            }


            public void after(int cur, Integer nobj) {
                tsize[cur] = tsize[left[cur]] + tsize[right[cur]] + ndup[cur];
            }

            public long nLess(int obj) {
                return nLess(ROOT, obj);
            }

            private long nLess(int root, int obj) {
                if (root == NULL || isEmpty())
                    return 0;
                int cmp = obj - get(root);
                if (cmp == 0)
                    return tsize[left[root]];
                else if (obj < get(root))
                    return nLess(left[root], obj);
                else
                    return tsize[root] - tsize[right[root]] + nLess(right[root], obj);
            }

        }

    }

    static class InputReader {
        private InputStream stream;
        private byte[] buf = new byte[1024];
        private int curChar;
        private int numChars;
        private InputReader.SpaceCharFilter filter;

        public InputReader(InputStream stream) {
            this.stream = stream;
        }

        public int read() {
            if (numChars == -1) {
                throw new InputMismatchException();
            }
            if (curChar >= numChars) {
                curChar = 0;
                try {
                    numChars = stream.read(buf);
                } catch (IOException e) {
                    throw new InputMismatchException();
                }
                if (numChars <= 0) {
                    return -1;
                }
            }
            return buf[curChar++];
        }

        public int readInt() {
            int c = read();
            while (isSpaceChar(c)) {
                c = read();
            }
            int sgn = 1;
            if (c == '-') {
                sgn = -1;
                c = read();
            }
            int res = 0;
            do {
                if (c < '0' || c > '9') {
                    throw new InputMismatchException();
                }
                res *= 10;
                res += c - '0';
                c = read();
            } while (!isSpaceChar(c));
            return res * sgn;
        }

        public boolean isSpaceChar(int c) {
            if (filter != null) {
                return filter.isSpaceChar(c);
            }
            return isWhitespace(c);
        }

        public static boolean isWhitespace(int c) {
            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }

        public interface SpaceCharFilter {
            public boolean isSpaceChar(int ch);

        }

    }

    static class OutputWriter {
        private final PrintWriter writer;

        public OutputWriter(OutputStream outputStream) {
            writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream)));
        }

        public OutputWriter(Writer writer) {
            this.writer = new PrintWriter(writer);
        }

        public void close() {
            writer.close();
        }

        public void printLine(long i) {
            writer.println(i);
        }

    }

    static abstract class AbstractBST<T extends Comparable<T>> {
        public int[] left;
        public int[] right;
        public int[] height;
        public Object[] values;
        int size = 1;
        public int ROOT = 1;
        public int NULL = 0;
        int acc;
        int maxAcc = 5;

        public AbstractBST(int size) {
            left = new int[size + 2];
            right = new int[size + 2];
            height = new int[size + 2];
            values = new Object[size + 2];
        }

        public T get(int index) {
            return (T) values[index];
        }

        public boolean isEmpty() {
            return size == 1;
        }

        public boolean add(T nobj) {
            boolean inserted = add(ROOT, nobj);
            if (inserted && ++acc > maxAcc) {
                ROOT = rotate(ROOT, nobj);
                acc = 0;
            }
            return inserted;
        }

        private boolean add(int root, T nobj) {
            boolean inserted = false;
            before(root, nobj);
            if (size == 1) {
                values[1] = nobj;
                create(1, nobj);
                size++;
            } else {
                int cmp = nobj.compareTo(get(root));
                if (cmp == 0) {
                    found(root, nobj);
                } else if (cmp < 0) {
                    if (left[root] == 0) {
                        values[size] = nobj;
                        create(size, nobj);
                        left[root] = size;
                        size++;
                        inserted = true;
                    } else {
                        inserted = add(left[root], nobj);
                    }
                } else {
                    if (right[root] == 0) {
                        values[size] = nobj;
                        create(size, nobj);
                        right[root] = size;
                        size++;
                        inserted = true;
                    } else {
                        inserted = add(right[root], nobj);
                    }
                }
            }
            after(root, nobj);
            return inserted;
        }

        public abstract void found(int cur, T nobj);

        public abstract void create(int cur, T nobj);

        public abstract void before(int cur, T nobj);

        public abstract void after(int cur, T nobj);

        private int rotate(int root, T nobj) {
            int cmp = nobj.compareTo(get(root));
            if (cmp == 0)
                return root;
            if (cmp < 0)
                left[root] = rotate(left[root], nobj);
            else
                right[root] = rotate(right[root], nobj);
            int lh = height[left[root]];
            int rh = height[right[root]];
            if (Math.abs(lh - rh) <= 1) {
                height[root] = Math.max(lh, rh) + 1;
                return root;
            }
            int pivot, split, old;
            pivot = split = old = -1;
            if (lh < rh) {
                pivot = right[root];
                old = left[root];
                split = left[pivot];
                right[root] = split;
                left[pivot] = root;
            } else {
                pivot = left[root];
                old = right[root];
                split = right[pivot];
                left[root] = split;
                right[pivot] = root;
            }
            after(root, nobj);
            after(pivot, nobj);
            height[root] = Math.max(height[old], height[split]) + 1;
            height[pivot] = Math.max(height[root] + 1, height[pivot]);
            return pivot;
        }

    }
}

