#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, median;
  cin >> n >> median;
  int arr[n];
  for (int i = 0; i < n; i++) cin >> arr[i];
  map<int, int> m;
  long long ans = 0;
  m[0] = 1;
  int i = 0;
  int counter = 0;
  for (; i < n; i++) {
    if (arr[i] == median) break;
    if (arr[i] > median) {
      counter++;
    } else
      counter--;
    m[counter]++;
  }
  for (; i < n; i++) {
    if (arr[i] == median) {
    } else if (arr[i] > median) {
      counter++;
    } else
      counter--;
    ans += m[counter];
    ans += m[counter - 1];
  }
  cout << ans << endl;
}
