#include <bits/stdc++.h>
using namespace std;
int n, a[200005];
long long greaterCount(int m) {
  map<int, int> s;
  int sum = 0;
  long long add = 0, res = 0;
  s[sum] = 1;
  for (int i = 0; i < n; i++) {
    if (a[i] < m)
      add -= s[--sum];
    else
      add += s[sum++];
    res += add;
    s[sum]++;
  }
  return res;
}
int main() {
  int m;
  cin >> n >> m;
  for (int i = 0; i < n; i++) cin >> a[i];
  cout << greaterCount(m) - greaterCount(m + 1) << endl;
  return 0;
}
