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
import sys
input = lambda: sys.stdin.readline().rstrip()

from typing import List, Union


class FenwickTree:

  '''Build a new FenwickTree. / O(N)'''
  def __init__(self, _n_or_a: Union[List[int], int]):
    if isinstance(_n_or_a, int):
      self._size = _n_or_a
      self._tree = [0] * (self._size+1)
    else:
      a = list(_n_or_a)
      self._size = len(a)
      self._tree = [0] + a
      for i in range(1, self._size):
        if i + (i & -i) <= self._size:
          self._tree[i + (i & -i)] += self._tree[i]
    self._s = 1 << (self._size-1).bit_length()

  '''Return sum([0, r)) of a. / O(logN)'''
  def pref(self, r: int) -> int:
    # assert r <= self._size
    ret = 0
    while r > 0:
      ret += self._tree[r]
      r -= r & -r
    return ret

  '''Return sum([l, n)) of a. / O(logN)'''
  def suff(self, l: int) -> int:
    # assert 0 <= l < self._size
    return self.pref(self._size) - self.pref(l)

  '''Return sum([l, r)] of a. / O(logN)'''
  def sum(self, l: int, r: int) -> int:
    # assert 0 <= l <= r <= self._size
    return self.pref(r) - self.pref(l)

  def __getitem__(self, k: int) -> int:
    return self.sum(k, k+1)

  '''Add x to a[k]. / O(logN)'''
  def add(self, k: int, x: int) -> None:
    # assert 0 <= k < self._size
    k += 1
    while k <= self._size:
      self._tree[k] += x
      k += k & -k

  '''Update A[k] to x. / O(logN)'''
  def set(self, k: int, x: int) -> None:
    pre = self.get(k)
    self.add(k, x - pre)

  '''bisect_left(acc)'''
  def bisect_left(self, w: int) -> int:
    i = 0
    s = self._s
    while s:
      if i + s <= self._size and self._tree[i + s] < w:
        w -= self._tree[i + s]
        i += s
      s >>= 1
    return i if w else None

  '''bisect_right(acc)'''
  def bisect_right(self, w: int) -> int:
    i = 0
    s = self._s
    while s:
      if i + s <= self._size and self._tree[i + s] <= w:
        w -= self._tree[i + s]
        i += s
      s >>= 1
    return i

  def show(self) -> None:
    print('[' + ', '.join(map(str, (self.pref(i) for i in range(self._size+1)))) + ']')

  def tolist(self) -> List[int]:
    return [self.__getitem__(i) for i in range(self._size)]

  @classmethod
  def inversion_num(self, a: List[int], compress: bool=False) -> int:
    ans = 0
    if compress:
      a_ = sorted(set(a))
      z = {e: i for i, e in enumerate(a_)}
      fw = FenwickTree(len(a_))
      for i, e in enumerate(a):
        ans += i - fw.pref(z[e])
        fw.add(z[e], 1)
    else:
      fw = FenwickTree(len(a))
      for i, e in enumerate(a):
        ans += i - fw.pref(e)
        fw.add(e, 1)
    return ans

  def __str__(self):
    sub = [self.pref(i) for i in range(self._size+1)]
    return '[' + ', '.join(map(str, (sub[i+1]-sub[i] for i in range(self._size)))) + ']'

  def __repr__(self):
    return 'FenwickTree(' + str(self) + ')'


#  -----------------------  #

n, m = map(int, input().split())
A = list(map(int, input().split()))

def f(k):
  # 中央値がk以上である区間の個数
  ans = 0
  fw = FenwickTree(2*n+10)
  acc = 0
  for i in range(n):
    fw.add(acc+n, 1)
    acc += 1 if A[i] >= k else -1
    ans += fw.pref(acc+n)
  return ans

ans = f(m) - f(m+1)
print(ans)
