#include <bits/stdc++.h>
using namespace std;
template <class T>
struct rge {
  T b, e;
};
template <class T>
rge<T> range(T i, T j) {
  return rge<T>{i, j};
};
template <class A, class B>
ostream &operator<<(ostream &os, pair<A, B> p) {
  return os << "(" << p.first << ", " << p.second << ")";
}
template <class T>
ostream &operator<<(ostream &os, rge<T> d) {
  os << "[";
  for (auto it = d.b; it != d.e; it++) os << (it == d.b ? "" : ", ") << *it;
  return os << "]";
}
const int N = 2e5 + 100;
const int inf = 1e9;
template <class T>
struct fenwick {
  vector<T> fenw;
  fenwick(int _n = 0) { fenw.resize(_n + 5, 0); }
  void update(int sx, T v) {
    for (int x = (sx + N); x <= ((int)(fenw).size() - 1); x += (+(x & -x))) {
      fenw[x] += v;
    }
  }
  T query(int sx) {
    T v = 0;
    for (int x = (sx + N); x >= (1); x += (-(x & -x))) {
      v += fenw[x];
    }
    return v;
  }
};
int a[N];
int n, med;
long long solve(int med) {
  fenwick<long long> cnt(2 * N);
  cnt.update(0, +1);
  long long tot = 0, more = 0;
  for (int i = (0); i <= ((n)-1); i += (+1)) {
    if (a[i] <= med) {
      more--;
    } else {
      more++;
    }
    tot += cnt.query(-more);
    cnt.update(-more, +1);
  }
  return tot;
}
int main() {
  ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0), cout.precision(15);
  while (cin >> n >> med) {
    for (int i = (0); i <= ((n)-1); i += (+1)) {
      cin >> a[i];
    }
    cout << solve(med) - solve(med - 1) << '\n';
  }
  return 0;
}
