#include <bits/stdc++.h>
using namespace std;
int a[200004], n, m;
int c[400004];
long long greaterc(int m) {
  long long ans = 0, add = 0;
  memset(c, 0, sizeof(c));
  int div = n;
  c[n] = 1;
  for (int i = 0; i < n; i++) {
    if (a[i] < m)
      div--, add -= c[div];
    else
      add += c[div], div++;
    ans += add;
    c[div]++;
  }
  return ans;
}
int main() {
  cin >> n >> m;
  for (int i = 0; i < n; i++) cin >> a[i];
  cout << greaterc(m) - greaterc(m + 1) << endl;
  return 0;
}
