#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  vector<int> arr(n);
  int idx = -1;
  for (int i = 0; i < n; i++) {
    cin >> arr[i];
    if (arr[i] == m) idx = i;
  }
  if (idx == -1) {
    cout << 0 << endl;
    return 0;
  }
  map<int, int> mp;
  int c = 0;
  for (int i = idx + 1; i < n; i++) {
    arr[i] < m ? c-- : c++;
    mp[c]++;
  }
  int sum = 0;
  long long ans = 1 + mp[0] + mp[1];
  for (int i = idx - 1; i >= 0; i--) {
    sum += arr[i] > m ? 1 : -1;
    if (sum == 0 || sum == 1) ans++;
    if (mp.find(-sum) != mp.end()) ans += mp[-sum];
    if (mp.find(-sum + 1) != mp.end()) ans += mp[-sum + 1];
  }
  cout << ans;
}
