#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e5 + 7;
int a[maxn];
map<int, int> mp;
queue<int> q;
int main() {
  int n, k, now;
  long long ans = 0;
  cin >> n >> k;
  for (int i = 1; i <= n; i++) {
    scanf("%d", &a[i]);
    if (a[i] == k) now = i;
  }
  q.push(0);
  int d = 0, x = 0;
  for (int i = now - 1; i >= 1; i--) {
    if (a[i] > k)
      d++;
    else
      x++;
    q.push(d - x);
  }
  d = 0, x = 0;
  for (int i = now + 1; i <= n; i++) {
    if (a[i] > k)
      d++;
    else
      x++;
    mp[d - x]++;
  }
  mp[0]++;
  while (!q.empty()) {
    k = q.front();
    q.pop();
    ans += mp[-k];
    ans += mp[-(k - 1)];
  }
  cout << ans << endl;
}
