#include <bits/stdc++.h>
using namespace std;
int n, m;
int a[200005];
int main() {
  while (~scanf("%d%d", &n, &m)) {
    map<int, int> mp;
    int sta = 0;
    for (int i = 1; i <= n; i++) {
      scanf("%d", &a[i]);
      if (a[i] == m) sta = i;
    }
    int cur = 0;
    for (int i = 1; i <= n; i++) {
      if (a[i] > m)
        cur++;
      else if (a[i] < m)
        cur--;
      if (i >= sta) mp[cur]++;
    }
    int sum = 0;
    long long ans = 0;
    for (int i = 1; i <= sta; i++) {
      ans += (mp[sum + 0] + mp[sum + 1]);
      if (a[i] > m)
        sum++;
      else if (a[i] < m)
        sum--;
    }
    printf("%lld\n", ans);
  }
  return 0;
}
