#include <bits/stdc++.h>
using namespace std;
const long long N = 2e5 + 7;
long long n, m;
long long a[N], v[N << 1];
long long chu(long long x) {
  memset(v, 0, sizeof v);
  long long ans = 0, now = n, add = 0;
  v[now] = 1;
  for (long long i = 1; i <= n; i++) {
    if (a[i] >= x) {
      add += v[now];
      now++;
    } else {
      now--;
      add -= v[now];
    }
    ans += add;
    v[now]++;
  }
  return ans;
}
signed main() {
  scanf("%lld%lld", &n, &m);
  for (long long i = 1; i <= n; i++) scanf("%lld", &a[i]);
  printf("%lld", chu(m) - chu(m + 1));
}
