#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  int i = n, j = n;
  vector<int> a(2 * n + 1), b(2 * n + 1);
  long long s = 0, x = 1, y = a[n] = b[n] = 1;
  while (n--) {
    int v;
    cin >> v;
    if (v < m)
      x += a[++i]++, y += b[++j]++;
    else if (v == m)
      x += a[++i]++, y -= b[j], ++b[--j];
    else
      x -= a[i], ++a[--i], y -= b[j], ++b[--j];
    s += x - y;
  }
  cout << s;
}
