#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e5 + 10;
int a[maxn], sum[2 * maxn], n;
long long count(int m) {
  memset(sum, 0, sizeof(sum));
  int cnt = n;
  sum[n] = 1;
  long long add = 0, result = 0;
  for (int i = 1; i <= n; i++) {
    if (a[i] >= m) {
      add += sum[cnt];
      cnt++;
    } else {
      cnt--;
      add -= sum[cnt];
    }
    sum[cnt]++;
    result += add;
  }
  return result;
}
int main() {
  int m, i, j, k, x, y, z;
  long long ans;
  while (scanf("%d%d", &n, &m) != EOF) {
    for (i = 1; i <= n; i++) scanf("%d", &a[i]);
    ans = count(m) - count(m + 1);
    printf("%lld\n", ans);
  }
  return 0;
}
