#include <bits/stdc++.h>
using namespace std;
const long long N = 2e5 + 5;
const long long offset = N + 1;
const long long MAX = N + offset + 1;
long long bit[MAX];
long long read(long long i) {
  long long ans = 0;
  i += offset;
  while (i > 0) {
    ans += bit[i];
    i -= (i & (-i));
  }
  return ans;
}
void update(long long i) {
  i += offset;
  while (i < MAX) {
    bit[i] += 1;
    i += (i & (-i));
  }
  return;
}
long long n, arr[N];
long long pref[N];
long long brute(long long m) {
  vector<pair<long long, long long> > subs;
  long long cnt = 0;
  for (long long i = 1; i <= n; ++i) {
    vector<long long> temp;
    for (long long j = i; j <= n; ++j) {
      temp.push_back(arr[j]);
      sort(temp.begin(), temp.end());
      long long idx = (temp.size() - 1) / 2;
      if (temp[idx] >= m) {
        ++cnt;
        subs.push_back({i, j});
      }
    }
  }
  return cnt;
}
long long calc(long long m) {
  for (long long i = 1; i < n + 1; ++i) {
    long long temp = (arr[i] >= m) ? 1 : -1;
    pref[i] = pref[i - 1] + temp;
  }
  memset(bit, 0, sizeof(bit));
  update(0);
  long long ans = 0;
  for (long long i = 1; i <= n; ++i) {
    long long got = read(pref[i] - 1);
    ans = ans + got;
    update(pref[i]);
  }
  return ans;
}
int32_t main() {
  long long m;
  cin >> n >> m;
  for (long long i = 1; i <= n; ++i) cin >> arr[i];
  long long ans = calc(m);
  ans -= calc(m + 1);
  cout << ans << endl;
}
