#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 7;
int c[N * 2], a[N], b[N], n, m, i, j, sum, cur;
long long solve(int m, long long res = 0) {
  for (memset(c, 0, sizeof(c)), c[cur = n + 1] = 1, sum = 0, i = 1; i <= n;
       ++i) {
    if (a[i] <= m)
      sum += c[++cur];
    else
      sum -= c[cur--];
    res += sum;
    c[cur]++;
  }
  return res;
}
int main() {
  for (scanf("%d%d", &n, &m), i = 1; i <= n; ++i) scanf("%d", a + i);
  printf("%I64d\n", solve(m) - solve(m - 1));
}
