#include <bits/stdc++.h>
using namespace std;
vector<int> v(200005), a(200005);
int ng, ns, in;
long long ans;
map<int, int> mp;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int n, m;
  cin >> n >> m;
  for (int i = 1; i <= n; ++i) {
    cin >> v[i];
    if (v[i] == m) in = i;
    if (v[i] > m)
      ++ng;
    else if (v[i] < m)
      ++ns;
    a[i] = ng - ns;
  }
  mp[0] = 1;
  for (int i = 1; i <= n; ++i) {
    if (i < in) {
      mp[a[i]]++;
    } else {
      ans += mp[a[i]];
      ans += mp[a[i] - 1];
    }
  }
  cout << ans;
  return 0;
}
