#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 50;
const long long oo = 1e18;
const long long mod = 1e9 + 7;
int a[N], sum[2 * N];
int main() {
  int n, m;
  cin >> n >> m;
  for (int i = 0; i < n; i++) cin >> a[i];
  int cur = n;
  long long ans = 0;
  sum[cur] = 1;
  long long q = 0;
  for (int i = 0; i < n; i++) {
    if (a[i] < m) {
      cur--;
      q -= sum[cur];
    } else {
      q += sum[cur];
      cur++;
    }
    ans += q;
    sum[cur]++;
  }
  memset(sum, 0, sizeof(sum));
  cur = n;
  sum[cur] = 1;
  q = 0;
  for (int i = 0; i < n; i++) {
    if (a[i] < m + 1) {
      cur--;
      q -= sum[cur];
    } else {
      q += sum[cur];
      cur++;
    }
    ans -= q;
    sum[cur]++;
  }
  cout << ans << endl;
}
