#include <bits/stdc++.h>
using namespace std;
const long long N = 2e5 + 5;
long long n, m, ans;
long long a[N], cnt[2 * N];
long long Greater(long long x) {
  long long res = 0, sum = n, add = 0;
  for (long long i = 0; i <= 2 * n; ++i) cnt[i] = 0;
  cnt[sum]++;
  for (long long i = 1; i <= n; ++i) {
    if (a[i] >= x)
      add += cnt[sum], sum++;
    else
      sum--, add -= cnt[sum];
    cnt[sum]++;
    res += add;
  }
  return res;
}
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cin >> n >> m;
  for (long long i = 1; i <= n; ++i) cin >> a[i];
  cout << Greater(m) - Greater(m + 1);
}
