#include <bits/stdc++.h>
using namespace std;
const int N = 200005;
int n, m, a[N];
using ll = long long;
ll calc(ll m) {
  vector<int> b(n * 2 + 1);
  ll s = 0, ret = 0;
  int cur = n;
  b[cur] = 1;
  for (int i = 1; i <= n; i++) {
    if (a[i] < m)
      s -= b[--cur];
    else
      s += b[cur++];
    ret += s;
    ++b[cur];
  }
  return ret;
}
int main() {
  ios::sync_with_stdio(false);
  cin >> n >> m;
  for (int i = 1; i <= n; i++) cin >> a[i];
  cout << calc(m) - calc(m + 1) << endl;
  return 0;
}
