#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 5;
int a[N], cnt[N * 2], n, m;
long long solve(int m) {
  int s = n;
  memset(cnt, 0, sizeof(cnt));
  cnt[s] = 1;
  long long add = 0, ans = 0;
  for (int i = 1; i <= n; i++) {
    if (a[i] >= m)
      add += cnt[s], s++;
    else
      s--, add -= cnt[s];
    cnt[s]++;
    ans += add;
  }
  return ans;
}
int main() {
  scanf("%d %d", &n, &m);
  for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
  printf("%lld\n", solve(m) - solve(m + 1));
  return 0;
}
