#include <bits/stdc++.h>
const int MaxN = 2e5;
using namespace std;
int n, m;
int a[MaxN + 5], c[MaxN * 2 + 5], b[MaxN + 5];
void Add(int x, int w) {
  for (int i = x; i <= 2 * MaxN; i += (i & (-i))) c[i] += w;
}
int Ask(int x) {
  int res = 0;
  for (int i = x; i > 0; i -= (i & (-i))) res += c[i];
  return res;
}
long long Solve(int x) {
  memset(c, 0, sizeof(c));
  for (int i = 1; i <= n; i++)
    if (a[i] <= x)
      b[i] = 1;
    else
      b[i] = -1;
  for (int i = 1; i <= n; i++) b[i] += b[i - 1];
  Add(n + 1, 1);
  long long res = 0;
  for (int i = 1; i <= n; i++) {
    res = res + Ask(b[i] + n + 1);
    Add(b[i] + n + 1, 1);
  }
  return res;
}
int main() {
  while (~scanf("%d%d", &n, &m)) {
    for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
    printf("%lld\n", Solve(m) - Solve(m - 1));
  }
  return 0;
}
