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).
/**
 * BaZ :D
 */
import java.util.*;
import java.io.*;
import static java.lang.Math.*;
public class Main
{  
    static Reader scan;
    static PrintWriter pw;
    static int n,m,arr[],tree[],OFFSET,N;
    public static void main(String[] args) {
        new Thread(null,null,"BaZ",1<<25)
        {
           public void run()
           {
               try
               {
                   solve();
               }
               catch(Exception e)
               {  
                   e.printStackTrace();
                   System.exit(1);
               }
           }
        }.start();
    }
    static void solve() throws IOException
    {
        scan = new Reader();
        pw = new PrintWriter(System.out,true);
        StringBuilder sb = new StringBuilder();
        n = ni();
        m = ni();
        arr = new int[n];
        for(int i=0;i<n;++i)
            arr[i] = ni();
        pl(solve(m)-solve(m+1));
        pw.flush();
        pw.close();
    }
    static long solve(int m)
    {  
        //pl("m : "+m);
        int aux[] = new int[n];
        for(int i=0;i<n;++i)
        {
            if(arr[i]>=m)
                aux[i] = 1;
            else aux[i] = -1;
            if(i>0)
                aux[i]+=aux[i-1];
        }
        //pa("aux",aux);
        OFFSET = n;
        N = 2*n + 1;
        int sz = (int)(pow(2,ceil(log(N)/log(2))+1));
        tree = new int[sz];
        long cnt = 0;
        for(int i=n-1;i>=0;--i)
        {
            cnt+=query(aux[i]+OFFSET+1,N-1);
            update(aux[i]+OFFSET,1);
        }
        cnt+=query(OFFSET+1,N-1);
        //pl("cnt : "+cnt);
        return cnt;
    }
    static void update(int treein,int low,int high,int idx,int val)
    {
        if(low==high)
            tree[treein] += val;
        else
        {
            int mid = (low+high)>>1;
            if(idx<=mid)
                update(2*treein,low,mid,idx,val);
            else update(2*treein+1,mid+1,high,idx,val);
            tree[treein] = tree[2*treein]+tree[2*treein+1];
        }
    }
    static int query(int treein,int low,int high,int l,int r)
    {
        if(l<=low && high<=r)
            return tree[treein];
        if(low>r || high<l)
            return 0;
        int mid = (low+high)>>1;
        return query(2*treein,low,mid,l,r)+query(2*treein+1,mid+1,high,l,r);
    }
    static int query(int l,int r)
    {
        return query(1,0,N-1,l,r);
    }
    static void update(int idx,int val)
    {
        update(1,0,N-1,idx,val);
    }
    static int ni() throws IOException
    {
        return scan.nextInt();
    }
    static long nl() throws IOException
    {
        return scan.nextLong();
    }
    static double nd() throws IOException
    {
        return scan.nextDouble();
    }
    static void pl()
    {
        pw.println();
    }
    static void p(Object o)
    {
        pw.print(o+" ");
    }
    static void pl(Object o)
    {
        pw.println(o);
    }
    static void psb(StringBuilder sb)
    {
        pw.print(sb);
    }
    static void pa(String arrayName, Object arr[])
    {  
        pl(arrayName+" : ");
        for(Object o : arr)
            p(o);
        pl();
    }
    static void pa(String arrayName, int arr[])
    {
        pl(arrayName+" : ");
        for(int o : arr)
            p(o);
        pl();
    }
    static void pa(String arrayName, long arr[])
    {
        pl(arrayName+" : ");
        for(long o : arr)
            p(o);
        pl();
    }
    static void pa(String arrayName, double arr[])
    {
        pl(arrayName+" : ");
        for(double o : arr)
            p(o);
        pl();
    }
    static void pa(String arrayName, char arr[])
    {
        pl(arrayName+" : ");
        for(char o : arr)
            p(o);
        pl();
    }
    static void pa(String listName, List<Object> list) 
    {
        pl(listName+" : ");
        for(Object o : list)
            p(o);
        pl();
    }
    static class Reader {
    final private int BUFFER_SIZE = 1 << 16;
    private DataInputStream din;
    private byte[] buffer;
    private int bufferPointer, bytesRead;

    public Reader() {
        din = new DataInputStream(System.in);
        buffer = new byte[BUFFER_SIZE];
        bufferPointer = bytesRead = 0;
    }

    public Reader(String file_name) throws IOException {
        din = new DataInputStream(new FileInputStream(file_name));
        buffer = new byte[BUFFER_SIZE];
        bufferPointer = bytesRead = 0;
    }

    public String readLine() throws IOException {
        byte[] buf = new byte[64];
        int cnt = 0, c;
        while ((c = read()) != -1) {
            if (c == '\n') break;
            buf[cnt++] = (byte) c;
        }
        return new String(buf, 0, cnt);
    }

    public int nextInt() throws IOException {
        int ret = 0;
        byte c = read();
        while (c <= ' ') c = read();
        boolean neg = (c == '-');
        if (neg) c = read();
        do {
            ret = ret * 10 + c - '0';
        } while ((c = read()) >= '0' && c <= '9');
        if (neg) return -ret;
        return ret;
    }

    public long nextLong() throws IOException {
        long ret = 0;
        byte c = read();
        while (c <= ' ') c = read();
        boolean neg = (c == '-');
        if (neg) c = read();
        do {
            ret = ret * 10 + c - '0';
        } while ((c = read()) >= '0' && c <= '9');
        if (neg) return -ret;
        return ret;
    }

    public double nextDouble() throws IOException {
        double ret = 0, div = 1;
        byte c = read();
        while (c <= ' ') c = read();
        boolean neg = (c == '-');
        if (neg) c = read();
        do {
            ret = ret * 10 + c - '0';
        } while ((c = read()) >= '0' && c <= '9');
        if (c == '.') while ((c = read()) >= '0' && c <= '9') ret += (c - '0') / (div *= 10);
        if (neg) return -ret;
        return ret;
    }

    private void fillBuffer() throws IOException {
        bytesRead = din.read(buffer, bufferPointer = 0, BUFFER_SIZE);
        if (bytesRead == -1) buffer[0] = -1;
    }

    private byte read() throws IOException {
        if (bufferPointer == bytesRead) fillBuffer();
        return buffer[bufferPointer++];
    }

    public void close() throws IOException {
        if (din == null) return;
        din.close();
    }
}
}