#include <bits/stdc++.h>
using namespace std;
mt19937 rng(time(0));
uniform_int_distribution<int> uid(-1e9, 1e9);
signed main() {
  ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  int n, m;
  cin >> n >> m;
  vector<int> v(n);
  for (auto& i : v) cin >> i;
  map<int, int> mp, mp1;
  long long res = 0, s = 0, x = 0, s1 = 0, x1 = 0;
  mp[0] = 1;
  mp1[0] = 1;
  for (auto& i : v) {
    if (i < m)
      x -= mp[--s]++;
    else
      x += mp[s++], ++mp[s];
    if (i <= m)
      x1 -= mp1[--s1]++;
    else
      x1 += mp1[s1++], ++mp1[s1];
    res += x - x1;
  }
  cout << res;
}
