#include <bits/stdc++.h>
using namespace std;
long long read() {
  char c;
  long long num, f = 1;
  while (c = (char)getchar(), !isdigit(c))
    if (c == '-') f = -1;
  num = (long long)(c - '0');
  while (c = (char)getchar(), isdigit(c)) num = num * 10 + (long long)(c - '0');
  return num * f;
}
long long n, m;
vector<long long> a;
long long greaterCount(long long m) {
  vector<long long> s(2 * n + 1);
  long long sum = n, result = 0, add = 0;
  s[sum] = 1;
  for (long long i = 0; i < n; i++) {
    if (a[i] < m)
      sum--, add -= s[sum];
    else
      add += s[sum], sum++;
    result += add;
    s[sum]++;
  }
  return result;
}
void work() {
  n = read();
  m = read();
  a = vector<long long>(n);
  for (long long i = 0; i < n; i++) a[i] = read();
  cout << greaterCount(m) - greaterCount(m + 1) << endl;
  return;
}
signed main() {
  long long T = 1;
  for (long long Case = 1; Case <= T; Case++) {
    work();
  }
  return 0;
}
