#include <bits/stdc++.h>
using namespace std;
template <class T>
bool uin(T &a, T b) {
  return a > b ? (a = b, true) : false;
}
template <class T>
bool uax(T &a, T b) {
  return a < b ? (a = b, true) : false;
}
const int maxn = 1000001;
long long bit[maxn], a[maxn];
int n, n1, m;
void upd(int idx, int val) {
  while (idx <= n) {
    bit[idx] += val;
    idx += (idx & -idx);
  }
}
long long query(int idx) {
  long long sum = 0;
  while (idx > 0) {
    sum += bit[idx];
    idx -= (idx & -idx);
  }
  return sum;
}
long long sub_ar(int m) {
  long long ans = 0;
  long long sum = n1 + 1;
  memset(bit, 0, sizeof(bit));
  upd(sum, 1);
  for (long long i = 0; i < (long long)(n1); ++i) {
    if (a[i] >= m) {
      ans += query(sum);
      sum += 1;
      upd(sum, 1);
    } else {
      sum -= 1;
      ans += query(sum - 1);
      upd(sum, 1);
    }
  }
  return ans;
}
int main() {
  cin >> n1 >> m;
  n = 2 * n1 + 4;
  for (long long i = 0; i < (long long)(n1); ++i) cin >> a[i];
  cout << sub_ar(m) - sub_ar(m + 1) << endl;
  return 0;
}
