#include <bits/stdc++.h>
using namespace std;
#pragma comment(linker, "/stck:1024000000,1024000000")
int a[200005], b[400015], n, m;
long long solve(int k) {
  int cur = 200001, pos = 0;
  long long ans = 0;
  memset(b, 0, sizeof(b));
  ++b[cur];
  for (int i = 0; i < n; i++) {
    if (a[i] <= k)
      pos += b[++cur];
    else
      pos -= b[cur--];
    ans += pos;
    ++b[cur];
  }
  return ans;
}
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 0; i < n; i++) scanf("%d", &a[i]);
  printf("%lld\n", solve(m) - solve(m - 1));
  return 0;
}
