#include <bits/stdc++.h>
using namespace std;
int a[200010];
int s[200010];
int B[2 * 200010];
void update(int u) {
  while (u < 2 * 200010) {
    B[u]++;
    u += u & (-u);
  }
}
int calc(int u) {
  int cnt = 0;
  while (u > 0) {
    cnt += B[u];
    u -= u & (-u);
  }
  return cnt;
}
int main() {
  int n, m;
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
  for (int i = 1; i <= n; i++) {
    if (a[i] <= m)
      s[i] = s[i - 1] + 1;
    else
      s[i] = s[i - 1] - 1;
  }
  long long ans = 0;
  update(200010);
  for (int i = 1; i <= n; i++) {
    ans += calc(s[i] + 200010);
    update(s[i] + 200010);
  }
  memset(B, 0, sizeof B);
  for (int i = 1; i <= n; i++) {
    if (a[i] < m)
      s[i] = s[i - 1] + 1;
    else
      s[i] = s[i - 1] - 1;
  }
  update(200010);
  for (int i = 1; i <= n; i++) {
    ans -= calc(s[i] + 200010);
    update(s[i] + 200010);
  }
  printf("%I64d\n", ans);
  return 0;
}
