#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  int arr[n];
  for (int i = 0; i < n; i++) cin >> arr[i];
  unordered_map<int, long long> mp;
  mp[0] = 1;
  int sum = 0;
  int i = 0;
  while (i < n && arr[i] != m) {
    if (arr[i] < m)
      sum--;
    else
      sum++;
    mp[sum]++;
    i++;
  }
  long long ans = mp[sum] + mp[sum - 1];
  i++;
  while (i < n) {
    if (arr[i] < m)
      sum--;
    else
      sum++;
    ans += mp[sum] + mp[sum - 1];
    i++;
  }
  cout << ans;
}
