#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e5 + 50;
int bit[maxn << 1], n, m, a[maxn], b[maxn];
void add(int x) {
  for (int i = x; i <= 2 * n + 1; i += i & -i) {
    bit[i]++;
  }
}
int sum(int x) {
  int res = 0;
  for (int i = x; i > 0; i -= i & -i) {
    res += bit[i];
  }
  return res;
}
long long solve(int n, int m) {
  for (int i = 1; i <= n; i++) {
    b[i] = a[i] <= m ? 1 : -1;
    b[i] += b[i - 1];
  }
  memset(bit, 0, sizeof(bit));
  long long res = 0;
  add(n + 1);
  for (int i = 1; i <= n; i++) {
    res += sum(b[i] + n + 1);
    add(b[i] + n + 1);
  }
  return res;
}
int main(int argc, char const *argv[]) {
  scanf("%d %d", &n, &m);
  for (int i = 1; i <= n; i++) {
    scanf("%d", &a[i]);
  }
  printf("%I64d\n", solve(n, m) - solve(n, m - 1));
  return 0;
}
