#include <bits/stdc++.h>
using namespace std;
int tree[2][400090], m, n, a[400090], pre[400090];
int query(int f, int idx) {
  idx += 2e5 + 1;
  int s = 0;
  while (idx > 0) {
    s += tree[f][idx];
    idx -= idx & (-idx);
  }
  return s;
}
void update(int f, int idx, int val) {
  idx += 2e5 + 1;
  while (idx < 400090) {
    tree[f][idx] += val;
    idx += idx & (-idx);
  }
}
long long int solve(int f) {
  long long int ans = 0;
  update(f, pre[0], 1);
  for (int i = 1; i <= n; i++) {
    pre[i] = pre[i - 1] + ((a[i] >= (m + f)) ? 1 : -1);
    ans += query(f, pre[i] - 1);
    update(f, pre[i], 1);
  }
  return ans;
}
int main() {
  int i, j;
  cin >> n >> m;
  for (i = 1; i <= n; i++) {
    cin >> a[i];
  }
  long long int ans = solve(0) - solve(1);
  cout << ans;
  ;
  return 0;
}
