#include <bits/stdc++.h>
using namespace std;
const int maxn = (int)2e5 + 5;
int n, m;
int a[maxn];
template <typename T, size_t N>
struct fenwick_tree {
  static const size_t maxn = N * 2 + 1;
  vector<T> tree;
  fenwick_tree() : tree(maxn) {}
  void update(int i) {
    i += N;
    while (i <= maxn) {
      ++tree[i];
      i |= i + 1;
    }
  }
  T query(int i) {
    i += N;
    T ans = 0;
    while (i >= 0) {
      ans += tree[i];
      i = (i & i + 1) - 1;
    }
    return ans;
  }
};
int s[maxn];
long long calc(int x) {
  for (int i = 1; i <= n; ++i) {
    s[i] = s[i - 1] + (a[i] <= x ? 1 : 0);
  }
  fenwick_tree<int, maxn> ft;
  ft.update(0);
  long long ans = 0;
  for (int i = 1; i <= n; ++i) {
    ans += ft.query(2 * s[i] - i);
    ft.update(2 * s[i] - i);
  }
  return ans;
}
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= n; ++i) {
    scanf("%d", a + i);
  }
  long long ans = calc(m) - calc(m - 1);
  printf("%I64d\n", ans);
  return 0;
}
