#include <bits/stdc++.h>
using namespace std;
const bool print = false;
const long long mod = 1e9 + 7;
int bit[400005];
int num[200005];
int greaterStatus[200005];
void initialise(int n) {
  for (int i = (1); i <= (n); i++) {
    bit[i] = 0;
  }
}
void pointUpdate(int index, int n) {
  for (int i = index; i <= n; i += i & -i) {
    bit[i]++;
  }
}
int rangeSum(int index, int n) {
  int sum = 0;
  for (int i = index; i > 0; i -= i & -i) {
    sum += bit[i];
  }
  return sum;
}
long long findMed(int n, int m, int N) {
  initialise(N);
  for (int i = (0); i <= (n); i++) {
    greaterStatus[i] = 0;
  }
  pointUpdate(n + 1, N);
  for (int i = (1); i <= (n); i++) {
    if (num[i] <= m) {
      greaterStatus[i] = greaterStatus[i - 1] + 1;
    } else {
      greaterStatus[i] = greaterStatus[i - 1] - 1;
    }
  }
  long long ans = 0;
  for (int i = (1); i <= (n); i++) {
    int x = greaterStatus[i] + n + 1;
    ans += rangeSum(x, N);
    pointUpdate(x, N);
  }
  return ans;
}
int main() {
  int n, m;
  cin >> n >> m;
  int N = 2 * n + 1;
  for (int i = (1); i <= (n); i++) {
    cin >> num[i];
  }
  long long val = findMed(n, m, N) - findMed(n, m - 1, N);
  cout << val << "\n";
}
