#include <bits/stdc++.h>
using namespace std;
const int maxn = 4e5 + 10;
int bit[maxn];
int a[maxn], b[maxn], n;
void add(int i, int x) {
  while (i < maxn) {
    bit[i] += x;
    i += i & -i;
  }
}
int sum(int i) {
  int res = 0;
  while (i) {
    res += bit[i];
    i -= i & -i;
  }
  return res;
}
long long solve(int k) {
  memset(bit, 0, sizeof(bit));
  for (int i = 1; i <= n; i++) {
    b[i] = a[i] >= k ? 1 : -1;
    b[i] += b[i - 1];
  }
  long long ans = 0;
  add(n + 1, 1);
  for (int i = 1; i <= n; i++) {
    ans += sum(b[i] + n);
    add(b[i] + n + 1, 1);
  }
  return ans;
}
int main() {
  int m;
  cin >> n >> m;
  for (int i = 1; i <= n; i++) {
    scanf("%d", &a[i]);
  }
  cout << solve(m) - solve(m + 1) << endl;
  return 0;
}
