#include <bits/stdc++.h>
using namespace std;
void solve() {
  int n, m;
  scanf("%d%d", &n, &m);
  vector<int> a(n);
  for (int &x : a) scanf("%d", &x);
  auto cal = [&](int m) {
    map<int, int> s;
    int sum = n;
    long long result = 0;
    s[sum] = 1;
    long long add = 0;
    for (int i = 0; i < n; ++i) {
      if (a[i] < m) {
        sum--;
        add -= s[sum];
      } else {
        add += s[sum];
        sum++;
      }
      result += add;
      s[sum]++;
    };
    return result;
  };
  printf("%lld", cal(m) - cal(m + 1));
}
int main() {
  int t = 1;
  while (t--) solve();
}
