#include <bits/stdc++.h>
using namespace std;
signed main() {
  long long int t = 1;
  while (t--) {
    long long int n, m;
    cin >> n >> m;
    vector<long long int> p(n);
    for (long long int i = 0; i < n; i++) cin >> p[i];
    ;
    map<long long int, long long int> mp;
    long long int sum = 0, ans = 0;
    mp[0]++;
    bool has = false;
    for (long long int i = 0; i < n; i++) {
      if (p[i] > m)
        sum++;
      else if (p[i] < m)
        sum--;
      if (p[i] == m) has = true;
      if (has)
        ans += (mp[sum] + mp[sum - 1]);
      else
        mp[sum]++;
    }
    cout << ans << '\n';
  }
}
