#include <bits/stdc++.h>
using namespace std;
long long n;
vector<long long> v;
long long solve(long long m) {
  vector<long long> cf(2 * n + 1, 0);
  long long sum = n;
  long long cur = 0;
  long long ans = 0;
  cf[sum] = 1;
  for (long long i = 0; i < n; i++) {
    if (v[i] < m) {
      sum = sum - 1;
      cur -= cf[sum];
      ans += cur;
      cf[sum]++;
    } else {
      cur += cf[sum];
      ans += cur;
      sum = sum + 1;
      cf[sum]++;
    }
  }
  return ans;
}
int32_t main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ;
  long long m;
  cin >> n >> m;
  v.resize(n);
  for (long long i = 0; i < n; i++) cin >> v[i];
  cout << solve(m) - solve(m + 1);
  return 0;
}
