#include <bits/stdc++.h>
using namespace std;
void _out() { cerr << '\n'; }
template <typename H, typename... T>
void _out(H h, T... t) {
  cerr << ' ' << h;
  _out(t...);
}
const long long N = 1e6 + 100;
long long tr[N];
long long lowbit(long long x) { return x & -x; }
long long sum(long long x) {
  long long res = 0;
  for (long long i = x; i; i -= lowbit(i)) res += tr[i];
  return res;
}
void add(long long x, long long c) {
  for (long long i = x; i <= 1e6; i += lowbit(i)) {
    tr[i] += c;
  }
}
void solve() {
  long long n, m;
  cin >> n >> m;
  vector<long long> a(n + 1);
  for (long long i = 1; i <= n; i++) cin >> a[i];
  auto get = [&](long long x) {
    long long res = 0;
    memset(tr, 0, sizeof tr);
    vector<long long> b(n + 1);
    add(n + 1, 1);
    for (long long i = 1; i <= n; i++) {
      b[i] = a[i] >= x ? 1 : -1;
      b[i] += b[i - 1];
    }
    for (long long i = 1; i <= n; i++) {
      res += sum(b[i] + n);
      add(b[i] + n + 1, 1);
    }
    return res;
  };
  cout << get(m) - get(m + 1);
}
signed main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  solve();
}
