#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e5 + 5;
long long a[maxn];
int main() {
  long long n, m, pos;
  while (~scanf("%lld%lld", &n, &m)) {
    memset(a, 0, sizeof(a));
    map<long long, long long> mp;
    for (int i = 0; i < n; i++) {
      scanf("%lld", &a[i]);
      if (a[i] == m) pos = i;
    }
    long long cnt = 0;
    long long ans = 0;
    for (long long i = pos; i < n; i++) {
      if (a[i] > m)
        cnt++;
      else if (a[i] < m)
        cnt--;
      mp[cnt]++;
    }
    cnt = 0;
    for (long long i = pos; i >= 0; i--) {
      if (a[i] > m)
        cnt++;
      else if (a[i] < m)
        cnt--;
      ans += mp[-cnt];
      ans += mp[1 - cnt];
    }
    printf("%lld\n", ans);
  }
  return 0;
}
