#include <bits/stdc++.h>
int dr[] = {2, 2, -2, -2, 1, -1, 1, -1};
int dc[] = {1, -1, 1, -1, 2, 2, -2, -2};
int dr1[] = {0, 0, 1, 1, 1, -1, -1, -1};
int dc1[] = {1, -1, 1, 0, -1, 0, 1, -1};
int dr2[] = {0, 0, 1, -1};
int dc2[] = {1, -1, 0, 0};
using namespace std;
long long a[400005];
long long b[400005], tr[400005];
void update(long long x, long long val) {
  while (x < 400005) {
    tr[x] += val;
    x += x & (-x);
  }
}
long long query(long long x) {
  long long s = 0;
  while (x > 0) {
    s += tr[x];
    x -= x & (-x);
  }
  return s;
}
long long get(long long x, long long n) {
  memset(tr, 0, sizeof(tr));
  long long i, j = 0;
  long long m = 200001;
  long long s = 0;
  update(m, 1);
  long long ans = 0;
  for (i = 1; i <= n; i++) {
    if (a[i] < x)
      s--;
    else
      s++;
    ans += query(s + m - 1);
    update(s + m, 1);
  }
  return ans;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  long long tc, i, j, n, m, l, r;
  long long cn = 0;
  while (cin >> n >> m) {
    long long pos, ans = 0;
    for (i = 1; i <= n; i++) cin >> a[i];
    cout << get(m, n) - get(m + 1, n) << endl;
  }
  return 0;
}
