#include <bits/stdc++.h>
using namespace std;
map<long long int, long long int> mp;
long long int n, m;
long long int arr[200007];
int main() {
  cin >> n >> m;
  long long int flag = 0, cnt = 0;
  long long int j = 0;
  for (long long int i = 1; i <= n; i++) {
    cin >> arr[i];
    if (flag == 1) {
      if (arr[i] > m) {
        cnt += 1;
      } else {
        cnt -= 1;
      }
      mp[cnt] += 1;
    }
    if (arr[i] == m) {
      mp[0] += 1;
      flag = 1;
      j = i;
    }
  }
  cnt = 0;
  long long int ans = 0;
  for (long long int i = j; i >= 1; i--) {
    if (arr[i] > m) {
      cnt += 1;
      if (mp.find(-cnt) != mp.end()) {
        ans += mp[-cnt];
      }
      if (mp.find(-cnt + 1) != mp.end()) {
        ans += mp[-cnt + 1];
      }
    } else if (arr[i] < m) {
      cnt -= 1;
      if (mp.find(-cnt) != mp.end()) {
        ans += mp[-cnt];
      }
      if (mp.find(-cnt + 1) != mp.end()) {
        ans += mp[-cnt + 1];
      }
    } else {
      cnt = 0;
      if (mp.find(cnt) != mp.end()) {
        ans += mp[cnt];
      }
      if (mp.find(cnt + 1) != mp.end()) {
        ans += mp[cnt + 1];
      }
    }
  }
  cout << ans << endl;
}
