#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> a(n);
  map<long long int, long long int> m;
  long long int x, ans = 0, sum = 0;
  for (int i = 0; i < n; ++i) {
    cin >> x;
    if (x > val)
      a[i] = 1;
    else if (x < val)
      a[i] = -1;
  }
  m[0] = 1;
  bool y = false;
  for (int i = 0; i < n; ++i) {
    sum += a[i];
    if (a[i] == 0) y = true;
    if (y)
      ans += m[sum] + m[sum - 1];
    else
      m[sum]++;
  }
  cout << ans << "\n";
}
