#include <bits/stdc++.h>
using namespace std;
inline long long read() {
  long long x = 0, f = 1;
  char c = getchar();
  while (c < '0' || c > '9') {
    if (c == '-') f = -1;
    c = getchar();
  }
  while (c >= '0' && c <= '9') {
    x = (x << 1) + (x << 3) + c - '0';
    c = getchar();
  }
  return x * f;
}
int n, m, a[200010];
struct BIT {
  int b[200010 << 1];
  void clear() { memset(b, 0, sizeof(b)); }
  inline int lowbit(int x) { return x & (-x); }
  inline void Add(int x) {
    while (x <= (n << 1 | 1)) ++b[x], x += lowbit(x);
  }
  inline int Ask(int x) {
    int ans = 0;
    while (x) ans += b[x], x -= lowbit(x);
    return ans;
  }
} B;
long long Solve(long long x) {
  B.clear();
  B.Add(n + 1);
  int now = 0;
  long long ans = 0;
  for (int i = 1; i <= n; ++i) {
    now += a[i] >= x ? 1 : -1;
    ans += B.Ask(now + n - 1 + 1);
    B.Add(now + n + 1);
  }
  return ans;
}
int main() {
  n = read(), m = read();
  for (int i = 1; i <= n; ++i) {
    a[i] = read();
  }
  printf("%lld\n", Solve(m) - Solve(m + 1));
  return 0;
}
