#include <bits/stdc++.h>
using namespace std;
const int N = 222222;
int a[N], sum[N];
int n, m;
long long solve(int m) {
  fill(sum, sum + N, 0);
  map<int, int> sm, lazy;
  long long ans = 0;
  lazy[1] = 1;
  for (int i = 1; i <= n; i++) {
    int cur = (a[i] >= m) * 2 - 1;
    sum[i] = sum[i - 1] + cur;
    sm[sum[i]] += lazy[sum[i]];
    lazy[sum[i] + 1] += lazy[sum[i]];
    lazy[sum[i]] = 0;
    ans += sm[sum[i]];
    lazy[sum[i] + 1]++;
  }
  return ans;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin >> n >> m;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
  }
  long long ans = solve(m) - solve(m + 1);
  cout << ans << "\n";
  return 0;
}
