#include <bits/stdc++.h>
using namespace std;
const long long inf = 9.2e18;
const int maxn = 2e5 + 70;
const int INF = 2.1e9;
const int maxm = 1e6 + 70;
const int MOD = 1e9 + 7;
const double eps = 1e-7;
const double PI = acos(-1.0);
int n, m, k;
int a[maxn], s[2 * maxn];
long long solve(int m) {
  memset(s, 0, sizeof(s));
  long long ans = 0;
  int sum = n, cnt = 0;
  s[sum]++;
  for (int i = 1; i <= n; i++) {
    if (a[i] >= m)
      cnt += s[sum++];
    else
      cnt -= s[--sum];
    ans += cnt;
    s[sum]++;
  }
  return ans;
}
int main() {
  while (cin >> n >> m) {
    for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
    long long ans = solve(m) - solve(m + 1);
    cout << ans << endl;
  }
  return 0;
}
