#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 3;
int n, m;
int a[N], bit[2 * N + 1], sum[N];
void ud(int x) {
  for (; x <= 2 * N; x += x & -x) bit[x]++;
}
int query(int x) {
  long long res = 0;
  for (; x > 0; x -= x & -x) res += bit[x];
  return res;
}
long long solve(int x) {
  long long res = 0;
  memset(bit, 0, sizeof(bit));
  int cur = 0;
  for (int i = 1; i <= n; ++i) {
    if (a[i] < x)
      --cur;
    else
      ++cur;
    sum[i] = cur;
  }
  ud(n + 1);
  for (int i = 1; i <= n; ++i) {
    res += query(sum[i] + n);
    ud(sum[i] + n + 1);
  }
  return res;
}
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= n; ++i) scanf("%d", &a[i]);
  cout << solve(m) - solve(m + 1);
}
