#include <bits/stdc++.h>
using namespace std;
long long get(vector<long long> a, long long median) {
  map<long long, long long> s;
  s[0] = 1;
  long long sum = 0, ans = 0;
  long long add = 0;
  for (long long i = 0; i < (long long)a.size(); i++) {
    if (a[i] >= median) {
      add += s[sum];
      sum++;
    } else {
      sum--;
      add -= s[sum];
    }
    ans += add;
    s[sum]++;
  }
  return ans;
}
void solve() {
  long long n, m;
  cin >> n >> m;
  vector<long long> a(n);
  for (long long i = 0; i < n; i++) {
    cin >> a[i];
  }
  cout << get(a, m) - get(a, m + 1) << '\n';
}
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  long long t = 1;
  for (long long tt = 1; tt <= t; tt++) {
    solve();
  }
}
