#include <bits/stdc++.h>
using namespace std;
const int inf = 0x3f3f3f3f;
const long long mod = 1e9 + 7;
const int maxn = 1e6 + 5;
int a[maxn];
long long c[maxn];
int lb(int x) { return x & (-x); }
void add(int x) {
  for (int i = x; i <= 400005; i += lb(i)) c[i]++;
}
long long get(int x) {
  long long ans = 0;
  for (int i = x; i >= 1; i -= lb(i)) ans += c[i];
  return ans;
}
int main() {
  int n, m;
  while (cin >> n >> m) {
    for (int i = 1; i <= n; ++i) cin >> a[i];
    long long x = 0, y = 0;
    memset(c, 0, sizeof(c));
    int now = 200001;
    for (int i = 1; i <= n; ++i) {
      now += (a[i] >= m ? 1 : -1);
      x += get(now - 1);
      if (now >= 200002) x++;
      add(now);
    }
    memset(c, 0, sizeof(c));
    now = 200001;
    for (int i = 1; i <= n; ++i) {
      now += (a[i] >= m + 1 ? 1 : -1);
      y += get(now - 1);
      if (now >= 200002) y++;
      add(now);
    }
    cout << x - y << endl;
  }
}
