#include <bits/stdc++.h>
using namespace std;
long long solve(int m, vector<int>& a) {
  int n = int(a.size());
  vector<int> x(n);
  vector<int> ft(2 * n + 10, 0);
  auto get = [&](int pos) {
    long long ret = 0;
    while (pos) {
      ret += ft[pos];
      pos -= pos & -pos;
    }
    return ret;
  };
  auto update = [&](int pos, int val) {
    while (pos < int(ft.size())) {
      ft[pos] += val;
      pos += pos & -pos;
    }
  };
  int sum = 0;
  int offset = n + 2;
  long long ret = 0;
  update(offset + 0, 1);
  for (int i = 0; i < n; i++) {
    if (a[i] < m)
      sum -= 1;
    else
      sum += 1;
    ret += get(offset + sum - 1);
    update(offset + sum, 1);
  }
  return ret;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n, m;
  cin >> n >> m;
  vector<int> a(n);
  for (int& ai : a) cin >> ai;
  cout << solve(m, a) - solve(m + 1, a) << '\n';
  return (0);
}
