#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 7;
int c[N * 2], n, m, i, j, a[N], b[N];
void add(int x) {
  while (x <= n * 2 + 1) c[x]++, x += x & -x;
}
int sum(int x, int res = 0) {
  while (x) res += c[x], x -= x & -x;
  return res;
}
long long solve(int m, long long res = 0) {
  for (i = 1; i <= n; ++i) b[i] = b[i - 1] + (a[i] <= m ? 1 : -1);
  for (memset(c, 0, sizeof(c)), i = 0; i <= n; ++i) {
    res += sum(b[i] + n + 1);
    add(b[i] + n + 1);
  }
  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));
}
