#include <bits/stdc++.h>
using namespace std;
int n, m;
int a[211111];
int c[444444];
void add(int x, int y) {
  for (; x <= n + 210000; x += (x & (-x))) {
    c[x] += y;
  }
}
long long ask(int x) {
  long long ans = 0;
  for (; x; x -= (x & (-x))) {
    ans += (long long)c[x];
  }
  return ans;
}
long long greatCount(int midian) {
  memset(c, 0, sizeof(c));
  long long result = 0, sum = 0;
  add(210000, 1);
  for (int i = 1; i <= n; i++) {
    if (a[i] >= midian)
      sum++;
    else
      sum--;
    if (i != n) add(sum + 210000, 1);
    result += ask(sum - 1 + 210000);
  }
  return result;
}
int main(int argc, char const *argv[]) {
  cin >> n >> m;
  for (int i = 1; i <= n; i++) {
    scanf("%d", &a[i]);
  }
  cout << greatCount(m) - greatCount(m + 1) << endl;
  return 0;
}
