#include <bits/stdc++.h>
using namespace std;
int n, m;
int arr[200010];
map<int, long long> d;
long long solve(int tmp) {
  d.clear();
  long long ret = 0, t = 0;
  int cur = 0;
  d[0] = 1;
  for (int i = 1; i <= n; i++) {
    if (arr[i] < tmp) {
      cur--;
      t -= d[cur];
    } else {
      t += d[cur];
      cur++;
    }
    ret += t;
    d[cur]++;
  }
  return ret;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cin >> n >> m;
  for (int i = 1; i <= n; i++) cin >> arr[i];
  cout << solve(m) - solve(m + 1) << "\n";
}
