#include <bits/stdc++.h>
using namespace std;
int p[200005];
int d[200005];
int main() {
  memset(p, 0, sizeof(p));
  memset(d, 0, sizeof(d));
  int n, m;
  int ii;
  scanf("%d %d", &n, &m);
  unordered_map<int, int> t1(100000), t2(100000);
  int ds = 0;
  int pds = 0;
  for (int i = 0; i < n; i++) {
    scanf("%d", &p[i]);
    if (p[i] == m) {
      ii = i;
    }
  }
  for (int i = 0; i < n; i++) {
    if (p[i] < m) {
      d[i] = 1;
    } else if (p[i] > m) {
      d[i] = -1;
    } else {
      d[i] = 0;
    }
    if (i >= ii) {
      int l = i - ii + 1;
      ds += d[i];
      if (l & 1) {
        t1[ds]++;
      } else {
        t2[ds]++;
      }
    } else {
      pds += d[i];
    }
  }
  long long ans = 0;
  for (int i = 0; i <= ii; i++) {
    int l1 = ii - i;
    if (l1 & 1) {
      ans += t1[-1 - pds];
      ans += t2[-pds];
    } else {
      ans += t1[-pds];
      ans += t2[-1 - pds];
    }
    pds -= d[i];
  }
  printf("%lld\n", ans);
  return (0);
}
