#include <bits/stdc++.h>
using namespace std;
const int N = 6e5 + 5;
inline int read() {
  char c = getchar();
  int x = 0, f = 1;
  while (c < '0' || c > '9') {
    if (c == '-') f = -1;
    c = getchar();
  }
  while (c >= '0' && c <= '9') {
    x = x * 10 + c - '0';
    c = getchar();
  }
  return x * f;
}
int n, maxVal = 600000;
struct Operation {
  int a, b, c, w;
  int f;
  bool operator<(const Operation &r) const {
    return (a == r.a && b == r.b) ? c < r.c : (a == r.a ? b < r.b : a > r.a);
  }
} a[N], t[N];
int c[N];
inline int lowbit(int x) { return x & -x; }
inline void add(int p, int v) {
  for (; p <= maxVal; p += lowbit(p)) c[p] += v;
}
inline int sum(int p) {
  int re = 0;
  for (; p; p -= lowbit(p)) re += c[p];
  return re;
}
long long ans = 0;
void CDQ(int l, int r) {
  if (l == r) return;
  int mid = (l + r) >> 1;
  CDQ(l, mid);
  CDQ(mid + 1, r);
  int i = l, j = mid + 1, p = l;
  while (i <= mid || j <= r) {
    if (j > r || (i <= mid && a[i].b < a[j].b))
      add(a[i].c, a[i].w), t[p++] = a[i++];
    else
      ans += sum(a[j].c), t[p++] = a[j++];
  }
  for (int i = l; i <= mid; i++) add(a[i].c, -a[i].w);
  for (int i = l; i <= r; i++) a[i] = t[i];
}
int main() {
  int m;
  cin >> n >> m;
  vector<int> xx(n + 1), yy(n + 1), zz(n + 1);
  for (int i = 1; i <= n; i++) {
    scanf("%d", &xx[i]);
    yy[i] = yy[i - 1] + (xx[i] <= m);
    zz[i] = zz[i - 1] + (xx[i] < m);
  }
  for (int i = 1; i <= n + 1; i++) {
    a[i].b = -(zz[i - 1] * 2 - i + 1);
    a[i].c = yy[i - 1] * 2 - i + 1 + 300000;
    a[i].w = 1;
  }
  n++;
  CDQ(1, n);
  cout << ans << endl;
}
