#include <bits/stdc++.h>
using namespace std;
int s[400008];
void add(int first) {
  for (int i = first; i < 400008; i += i & -i) {
    s[i]++;
  }
}
int query(int first) {
  int ret = 0;
  for (int i = first; i > 0; i -= i & -i) {
    ret += s[i];
  }
  return ret;
}
int main() {
  int n, m;
  scanf("%d %d", &n, &m);
  long long ans = 0;
  int now = 0;
  int a[200005];
  vector<int> v;
  v.push_back(200000);
  for (int i = 0; i < n; i++) {
    scanf("%d", &a[i]);
    if (a[i] > m) now++;
    if (a[i] == m) {
      for (auto it : v) add(it);
      v.clear();
    }
    ans += query(i - 2 * now + 200001);
    v.push_back(i - 2 * now + 200001);
  }
  v.clear();
  v.push_back(200002);
  memset(s, 0, sizeof(s));
  now = 0;
  for (int i = 0; i < n; i++) {
    if (a[i] < m) now++;
    if (a[i] == m) {
      for (auto it : v) add(it);
      v.clear();
    }
    ans -= query(2 * now - i + 200001);
    v.push_back(2 * now - i + 200001);
  }
  printf("%lld\n", ans);
}
