#include <bits/stdc++.h>
using namespace std;
int n, m;
int a[200005];
long long find(int m) {
  pair<int, int> rec[n + 1];
  rec[0] = make_pair(0, 0);
  for (int i = 1; i <= n; i++) {
    rec[i] = rec[i - 1];
    if (a[i] >= m)
      rec[i].first++;
    else if (a[i] < m)
      rec[i].second++;
  }
  map<int, int> mp;
  map<int, int>::iterator itr;
  mp[0]++;
  long long ans = 0, add = 0;
  for (int i = 1; i <= n; i++) {
    int x = rec[i].first - rec[i].second;
    if (a[i] >= m) {
      add += mp[x - 1];
      ans += add;
    } else {
      add -= mp[x];
      ans += add;
    }
    mp[x]++;
  }
  return ans;
}
int main() {
  cin >> n >> m;
  for (int i = 1; i <= n; i++) cin >> a[i];
  cout << abs(find(m + 1) - find(m)) << endl;
}
