#include <bits/stdc++.h>
using namespace std;
long long n;
long long a[400100];
long long m;
long long cnt[400100];
long long cal(long long x) {
  long long ret = 0;
  long long add = 0;
  memset(cnt, 0, sizeof(cnt));
  long long cur = 200005;
  ++cnt[cur];
  for (long long i = 1; i <= n; ++i) {
    if (a[i] < x)
      add -= cnt[--cur];
    else
      add += cnt[cur++];
    ret += add;
    ++cnt[cur];
  }
  return ret;
}
int main() {
  scanf("%lld %lld", &n, &m);
  for (long long i = 1; i <= n; ++i) scanf("%lld", a + i);
  printf("%lld\n", cal(m) - cal(m + 1));
  return 0;
}
