#include <bits/stdc++.h>
using namespace std;
const int N = 4e5 + 7;
const int M = 1e5 + 7;
const int inf = 0x3f3f3f3f;
const long long INF = 0x3f3f3f3f3f3f3f3f;
const int mod = 1e9 + 7;
int n, m, a[N], b[N];
long long val[N];
void modify(int x, int v) {
  for (int i = x; i < N; i += i & -i) val[i] += v;
}
long long sum(int x) {
  long long ans = 0;
  for (int i = x; i; i -= i & -i) ans += val[i];
  return ans;
}
long long cal(int m) {
  memset(val, 0, sizeof(val));
  for (int i = 1; i <= n; i++) b[i] = (a[i] <= m ? 1 : -1);
  for (int i = 1; i <= n; i++) b[i] += b[i - 1];
  modify(n + 1, 1);
  long long ans = 0;
  for (int i = 1; i <= n; i++) {
    ans += sum(b[i] + n + 1);
    modify(b[i] + n + 1, 1);
  }
  return ans;
}
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= n; i++) {
    scanf("%d", &a[i]);
  }
  printf("%lld\n", cal(m) - cal(m - 1));
  return 0;
}
