#include <bits/stdc++.h>
using namespace std;
const int maxn = 1000010;
int N, M, a[maxn], sum[maxn];
long long ans;
long long solve(int num) {
  memset(sum, 0, sizeof(sum));
  int now = N;
  long long res = 0, delta = 0;
  sum[now] = 1;
  for (int i = 1; i <= N; i++) {
    if (a[i] >= num)
      delta += sum[now], now++;
    else
      now--, delta -= sum[now];
    res += delta;
    sum[now]++;
  }
  return res;
}
int main() {
  scanf("%d%d", &N, &M);
  for (int i = 1; i <= N; i++) scanf("%d", &a[i]);
  printf("%I64d\n", solve(M) - solve(M + 1));
  return 0;
}
