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