#include <bits/stdc++.h>
using namespace std;
const long long maxn = 1e6 + 5;
const long long maxint = 1e9 + 7;
long long n, k, ans = 0, a[maxn], b[maxn], BIT[1000005];
vector<long long> zip;
inline void Update(long long index, long long val) {
  index++;
  while (index <= zip.size() + 1) {
    BIT[index] += val;
    index += index & -index;
  }
}
inline long long Query(long long index) {
  long long ret = 0;
  index++;
  while (index > 0) {
    ret += BIT[index];
    index -= index & -index;
  }
  return ret;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  scanf("%lld%lld", &n, &k);
  for (long long i = 1; i <= n; i++) scanf("%lld", a + i);
  b[0] = 0;
  for (long long i = 1; i <= n; i++) {
    b[i] = b[i - 1] + (a[i] >= k);
    zip.push_back((b[i] << 1) - i - 1);
    zip.push_back((b[i - 1] << 1) - i);
  }
  sort(zip.begin(), zip.end());
  zip.erase(unique(zip.begin(), zip.end()), zip.end());
  for (long long i = 1; i <= n; i++) {
    long long prePos =
        lower_bound(zip.begin(), zip.end(), (b[i - 1] << 1) - i) - zip.begin();
    Update(prePos, 1);
    long long pos =
        lower_bound(zip.begin(), zip.end(), (b[i] << 1) - i - 1) - zip.begin();
    ans += Query(pos - 1);
  }
  long long fi = ans;
  ans = 0;
  k++;
  b[0] = 0;
  zip.clear();
  memset(BIT, 0, sizeof BIT);
  for (long long i = 1; i <= n; i++) {
    b[i] = b[i - 1] + (a[i] >= k);
    zip.push_back((b[i] << 1) - i - 1);
    zip.push_back((b[i - 1] << 1) - i);
  }
  sort(zip.begin(), zip.end());
  zip.erase(unique(zip.begin(), zip.end()), zip.end());
  for (long long i = 1; i <= n; i++) {
    long long prePos =
        lower_bound(zip.begin(), zip.end(), (b[i - 1] << 1) - i) - zip.begin();
    Update(prePos, 1);
    long long pos =
        lower_bound(zip.begin(), zip.end(), (b[i] << 1) - i - 1) - zip.begin();
    ans += Query(pos - 1);
  }
  fi -= ans;
  cout << fi;
  return 0;
}
