#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 5;
int n, m;
vector<int> a(N);
long long greaterMedian(int m) {
  vector<int> s(2 * n + 1, 0);
  s[n] = 1;
  long long res = 0;
  long long cnt = 0;
  for (int i = 0, sum = n; i < n; i += 1) {
    if (a[i] < m) {
      sum -= 1;
      cnt -= s[sum];
    } else {
      cnt += s[sum];
      sum += 1;
    }
    s[sum] += 1;
    res += cnt;
  }
  return res;
}
int main() {
  cin >> n >> m;
  for (int i = 0; i < n; i += 1) cin >> a[i];
  cout << greaterMedian(m) - greaterMedian(m + 1) << endl;
}
