#include <bits/stdc++.h>
using namespace std;
long long n, m, a[1000005], tree[1000005];
inline long long query(long long pos) {
  long long ans = 0;
  for (long long i = pos; i > 0; i -= i & (-i)) ans += tree[i];
  return ans;
}
inline void modify(long long pos) {
  for (long long i = pos; i <= 1000005; i += i & (-i)) tree[i] += 1;
}
long long x[1000005], y[1000005];
inline long long X(long long m) {
  memset(tree, 0, sizeof(tree));
  long long ans = 0, l1 = n + 1;
  modify(l1);
  for (int i = 1; i <= n; i++) {
    if (a[i] <= m)
      l1++;
    else
      l1--;
    ans += query(l1);
    modify(l1);
  }
  return ans;
}
int main() {
  scanf("%lld%lld", &n, &m);
  for (int i = 1; i <= n; i++) scanf("%lld", &a[i]);
  printf("%lld\n", X(m) - X(m - 1));
}
