#include <bits/stdc++.h>
using namespace std;
const long long N = 2e5 + 5;
long long mas[N], n;
long long gr(long long m) {
  vector<long long> s(2 * n + 5);
  long long res = 0, sum = n + 2, cur = 0;
  s[sum] = 1;
  for (long long i = 1; i <= n; i++) {
    if (mas[i] < m)
      cur -= s[--sum];
    else
      cur += s[sum++];
    s[sum]++;
    res += cur;
  }
  return res;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  long long m;
  cin >> n >> m;
  for (long long i = 1; i <= n; i++) cin >> mas[i];
  cout << gr(m) - gr(m + 1);
  return 0;
}
