#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e5 + 5;
const int N = 2 * maxn;
int n, m, a[maxn];
int v[N];
void jl(int x) {
  for (int i = x; i < N; i += i & -i) {
    v[i]++;
  }
}
long long s(int x) {
  long long sum = 0;
  for (int i = x; i > 0; i -= i & -i) {
    sum += v[i];
  }
  return sum;
}
long long cal(int k) {
  memset(v, 0, sizeof(v));
  jl(n + 1);
  int dp = 0;
  long long sum = 0;
  for (int i = 0; i < n; i++) {
    if (a[i] <= k)
      dp -= 1;
    else
      dp += 1;
    sum += s(dp + n);
    jl(dp + n + 1);
  }
  return sum;
}
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 0; i < n; i++) scanf("%d", &a[i]);
  cout << cal(m - 1) - cal(m) << endl;
  return 0;
}
