You are given an integer sequence $a_1, a_2, \dots, a_n$.

Find the number of pairs of indices $(l, r)$ ($1 \le l \le r \le n$) such that the value of median of $a_l, a_{l+1}, \dots, 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 \le l \le r \le n$) such that the value of median of $a_l, a_{l+1}, \dots, a_r$ is exactly the given number $m$.
The first line contains integers $n$ and $m$ ($1 \le n,m \le 2\cdot10^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, \dots, a_n$ ($1 \le a_i \le 2\cdot10^5$).
5 4
1 4 5 60 4
8
3 1
1 1 1
6
15 2
1 2 3 1 2 3 1 2 3 1 2 3 1 2 3
97
1 1
1
1
2 1
1 2
2
2 1
2 1
2
2 2
1 2
1
2 2
2 1
1
3 1
1 2 3
2
3 1
1 3 2
2
3 1
2 1 3
3
3 1
2 3 1
2
3 1
3 1 2
3
3 1
3 2 1
2
2 2
1 1
0
3 2
1 1 2
1
2 1
1 1
3
1 1
2
0
2 2
4 1
0
3 3
5 5 3
2
4 3
3 5 2 3
6
5 2
1 9 2 8 10
5
6 5
7 2 11 8 9 12
0
7 5
14 4 1 11 12 3 4
0
8 2
2 6 11 14 10 9 9 5
2
9 8
10 8 8 15 1 2 13 8 6
27
10 7
14 20 3 3 8 16 17 13 6 4
0
1 200000
1
0
1 200000
200000
1
from collections import defaultdict
import sys
input = sys.stdin.readline

def solve(x):
    u, v = [0], []
    s = 0
    for i in range(n):
        s += 1 if p[i] <= x else 0
        if i % 2:
            u.append(s)
        else:
            v.append(s)
    ans = f(u) + f(v) + g(u, v) + g(v, u[1:])
    return ans

def f(a):
    a = list(a)
    for i in range(len(a)):
        a[i] -= i
    mi = -min(a) + 1
    for i in range(len(a)):
        a[i] += mi
    l = max(a) + 5
    tree = make_tree(l)
    ans = 0
    for i in a:
        ans += get_sum(i, tree)
        add(i, 1, l, tree)
    return ans

def g(a, b):
    a, b = list(a), list(b)
    for i in range(len(a)):
        a[i] -= i
    for i in range(len(b)):
        b[i] -= i
    mi = -min(min(a), min(b)) + 1
    for i in range(len(a)):
        a[i] += mi
    for i in range(len(b)):
        b[i] += mi
    l = max(max(a), max(b)) + 5
    tree = make_tree(l)
    ans = 0
    for i in range(len(b)):
        ai, bi = a[i], b[i]
        add(ai, 1, l, tree)
        ans += get_sum(bi - 1, tree)
    return ans

def make_tree(n):
    tree = [0] * (n + 1)
    return tree

def get_sum(i, tree):
    s = 0
    while i > 0:
        s += tree[i]
        i -= i & -i
    return s

def get_sum_segment(s, t):
    ans = get_sum(t) - get_sum(s - 1)
    return ans

def add(i, x, n, tree):
    while i <= n:
        tree[i] += x
        i += i & -i
    return

n, m = map(int, input().split())
p = list(map(int, input().split()))
ans = solve(m) - solve(m - 1)
print(ans)