#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 5;
int n, m, a[N], b[N], d[N << 1];
void add(int i, int c) {
  for (; i < (N << 1); i += i & -i) d[i] += c;
}
int sum(int i) {
  int res = 0;
  for (; i; i -= i & -i) res += d[i];
  return res;
}
long long f(int m) {
  memset(d, 0, sizeof(d));
  for (int i = 1; i <= n; ++i) b[i] = b[i - 1] + (a[i] <= m ? 1 : -1);
  long long res = 0;
  for (int i = 1; i <= n; ++i) {
    res += sum(b[i] + n + 1) + (b[i] >= 0);
    add(b[i] + n + 1, 1);
  }
  return res;
}
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= n; ++i) scanf("%d", &a[i]);
  printf("%lld\n", f(m) - f(m - 1));
  return 0;
}
