#include <bits/stdc++.h>
using namespace std;
int n, m;
int A[200005];
long long greaterCount(int m) {
  map<int, int> s;
  int sum = 0;
  long long ret = 0, add = 0;
  s[0] = 1;
  for (int i = 1; i <= n; ++i) {
    if (A[i] < m)
      --sum, add -= s[sum];
    else
      add += s[sum], ++sum;
    ret += add;
    ++s[sum];
  }
  return ret;
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cin >> n >> m;
  for (int i = 1; i <= n; ++i) cin >> A[i];
  cout << greaterCount(m) - greaterCount(m + 1) << endl;
  return 0;
}
