#include <bits/stdc++.h>
using namespace std;
const int MAXN = 2e5 + 5;
int a[MAXN];
int s[MAXN * 2];
int n, m;
long long cal(int x) {
  int sum = n + 1;
  memset(s, 0, sizeof(s));
  s[sum] = 1;
  long long ss = 0;
  long long ans = 0;
  for (int i = 1; i <= n; i++) {
    if (a[i] >= x)
      ss += s[sum++];
    else
      ss -= s[--sum];
    ans += ss;
    s[sum]++;
  }
  return ans;
}
int main() {
  ios::sync_with_stdio(false);
  cin >> n >> m;
  for (int i = 1; i <= n; i++) cin >> a[i];
  cout << cal(m) - cal(m + 1);
  return 0;
}
