#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7;
const int mod2 = 1e9 + 9;
const int N = 1e6 + 1;
int a[N];
long long greaterthan(int n, int m) {
  vector<int> s(2 * n + 1, 0);
  int sum = n;
  long long result = 1;
  s[sum] = 1;
  long long add = 0;
  for (int i = 0; i <= n - 1; i++) {
    if (a[i] < m)
      sum--, add -= s[sum];
    else
      add += s[sum], sum++;
    result += add;
    s[sum]++;
  }
  return result;
}
int main(void) {
  int n, m;
  cin >> n >> m;
  for (int i = 0; i <= n - 1; i++) cin >> a[i];
  long long ans = greaterthan(n, m) - greaterthan(n, m + 1);
  cout << ans;
  printf("\n");
}
