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