#include <bits/stdc++.h>
using namespace std;
long long n, m, _, a[200001], t[2 * 200001];
long long lowbit(long long x) { return x & (-x); }
void change(long long x) {
  while (x < 2 * 200001) t[x]++, x += lowbit(x);
}
long long get(long long x) {
  long long res = 0;
  while (x > 0) res += t[x], x -= lowbit(x);
  return res;
}
long long rua(long long x) {
  memset(t, 0, sizeof(t));
  change(200001);
  _ = 0;
  long long res = 0;
  for (long long i = 1; i <= n; i++)
    _ += a[i] <= x ? -1 : 1, res += get(200001 - _), change(200001 - _);
  return res;
}
int main() {
  scanf("%I64d%I64d", &n, &m);
  for (long long i = 1; i <= n; i++) scanf("%I64d", &a[i]);
  printf("%I64d\n", rua(m) - rua(m - 1));
  return 0;
}
