#include <bits/stdc++.h>
using namespace std;
const int maxn = 4e5 + 200;
int a[maxn], c[maxn], b[maxn];
int n;
int sum(int x) {
  int ans = 0;
  while (x > 0) {
    ans += c[x];
    x -= (x & (-x));
  }
  return ans;
}
void add(int x) {
  while (x < maxn) {
    c[x] += 1;
    x += x & (-x);
  }
}
long long solve(int m) {
  memset(c, 0, sizeof(c));
  for (int i = 1; i <= n; i++) {
    b[i] = a[i] <= m ? 1 : -1;
    b[i] += b[i - 1];
  }
  add(n + 1);
  long long ans = 0;
  for (int i = 1; i <= n; i++) {
    ans += sum(b[i] + n + 1);
    add(b[i] + n + 1);
  }
  return ans;
}
int main() {
  int m;
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
  printf("%lld\n", solve(m) - solve(m - 1));
  return 0;
}
