#include <bits/stdc++.h>
using namespace std;
template <class T>
inline void MIN(T &a, T b) {
  if (a > b) a = b;
}
template <class T>
inline void MAX(T &a, T b) {
  if (a < b) a = b;
}
const int N = 2e5 + 5;
int n, m, a[N], f[2 * N];
void inc(int idx) {
  idx += N;
  while (idx < 2 * N) {
    f[idx]++;
    idx += idx & -idx;
  }
}
int query(int idx) {
  idx += N;
  int ret = 0;
  while (idx > 0) {
    ret += f[idx];
    idx -= idx & -idx;
  }
  return ret;
}
long long solve(int k) {
  memset(f, 0, sizeof(f));
  inc(0);
  int cur = 0;
  long long ans = 0;
  for (int i = 0; i < n; i++) {
    cur += a[i] <= k ? 1 : -1;
    ans += query(cur);
    inc(cur);
  }
  return ans;
}
int main() {
  scanf("%d %d", &n, &m);
  for (int i = 0; i < n; i++) {
    scanf("%d", a + i);
  }
  cout << solve(m) - solve(m - 1) << endl;
}
