#include <bits/stdc++.h>
using namespace std;
const long long P = (1000 * 1000 * 1000) + 7;
const int arrn = 2e5 + 3;
int n, m;
vector<int> in(arrn, 0);
long long comp(int m) {
  vector<int> temp;
  int count[2 * arrn] = {};
  temp.push_back(0);
  for (int i = 0; i < n; i++) {
    if (in[i] < m)
      temp.push_back(1);
    else
      temp.push_back(-1);
  }
  for (int i = 0; i < n; i++) temp[i + 1] += temp[i];
  count[0]++;
  int prev = 1;
  long long out = 0;
  for (int i = 0; i < n; i++) {
    int tempcount;
    if (temp[i + 1] < temp[i]) {
      if (temp[i] < 0)
        tempcount = count[arrn + temp[i]];
      else
        tempcount = count[temp[i]];
      prev = prev - tempcount;
      prev++;
    } else {
      if (temp[i + 1] < 0)
        tempcount = count[arrn + temp[i + 1]];
      else
        tempcount = count[temp[i + 1]];
      prev = prev + tempcount;
      prev++;
    }
    if (temp[i + 1] < 0)
      count[arrn + temp[i + 1]]++;
    else
      count[temp[i + 1]]++;
    out += (prev - 1);
  }
  return out;
}
void solve() {
  cin >> n >> m;
  for (int i = 0; i < n; i++) cin >> in[i];
  cout << comp(m + 1) - comp(m);
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ;
  int T;
  T = 1;
  while (T--) {
    solve();
  }
  return 0;
}
