#include <bits/stdc++.h>
using namespace std;
long long n, i, j, k, l, sum = 0, flag = 0, t, a[200008], b[200007], ans = 0;
string s;
int BIT[2][400050];
void update(int id, long long first, long long val) {
  first += 200005;
  for (; first <= 400050; first += (first & -first)) BIT[id][first] += val;
}
long long query(int id, long long first) {
  first += 200005;
  long long res = 0;
  for (; first > 0; first -= (first & -first)) res += BIT[id][first];
  return res;
}
long long solve(int k) {
  memset(BIT, 0, sizeof BIT);
  b[0] = 0;
  long long ans = 0;
  for (int i = 1; i <= n; i++) {
    b[i] = (a[i] >= k ? 1 : -1);
    b[i] += b[i - 1];
  }
  update(0, 0, 1);
  for (int i = 1; i <= n; i++) {
    ans += query(!(i & 1), b[i]) + query((i & 1), b[i] - 1);
    update(i & 1, b[i], 1);
  }
  return ans;
}
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> k;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
  }
  cout << solve(k) - solve(k + 1) << '\n';
  return 0;
}
