#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e5 + 7;
int a[maxn * 2], b[2 * maxn];
struct node {
  int c[maxn * 2], n;
  void init(int _n) {
    n = _n;
    for (int i = 0; i <= n; i++) c[i] = 0;
  }
  void add(int st) {
    for (int i = st; i <= n; i += i & -i) c[i]++;
  }
  int sum(int st) {
    int res = 0;
    for (int i = st; i > 0; i -= i & -i) res += c[i];
    return res;
  }
} tmp;
unsigned long long solved(int n, int m) {
  for (int i = 1; i <= n; i++) b[i] = (a[i] <= m ? 1 : -1);
  for (int i = 1; i <= n; i++) b[i] += b[i - 1];
  tmp.init(n * 2 + 1);
  tmp.add(n + 1);
  unsigned long long res = 0;
  for (int i = 1; i <= n; i++) {
    res += tmp.sum(n + 1 + b[i]);
    tmp.add(b[i] + n + 1);
  }
  return res;
}
int main() {
  int n, m;
  scanf("%d %d", &n, &m);
  for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
  printf("%I64d\n", solved(n, m) - solved(n, m - 1));
  return 0;
}
