#include <bits/stdc++.h>
using namespace std;
int main() {
  std::ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int n, val;
  cin >> n >> val;
  vector<int> arr(n);
  map<long long int, long long int> m;
  for (int i = 0; i < n; ++i) cin >> arr[i];
  bool y = false;
  long long int cnt = 0, sum = 0;
  m[0] = 1;
  for (int i = 0; i < n; ++i) {
    if (arr[i] > val)
      sum++;
    else if (arr[i] < val)
      sum--;
    else
      y = true;
    if (y)
      cnt += m[sum] + m[sum - 1];
    else
      m[sum]++;
  }
  cout << cnt << endl;
}
