#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1e9 + 7;
const long long INF = 1e18;
const string nl = "\n";
int32_t main() {
  ios::sync_with_stdio(0);
  cin.tie(nullptr);
  long long n, k;
  cin >> n >> k;
  vector<long long> a(n);
  for (auto& i : a) {
    cin >> i;
  }
  vector<long long> pref(n);
  long long sum = 0, ans = 0;
  bool ok = 0;
  map<long long, long long> cnt;
  cnt[0] = 1;
  for (long long i = 0; i < n; ++i) {
    if (a[i] > k) {
      ++sum;
    } else if (a[i] < k) {
      --sum;
    }
    if (a[i] == k) {
      ok = 1;
    }
    if (ok) {
      ans += cnt[sum] + cnt[sum - 1];
    } else {
      ++cnt[sum];
    }
  }
  cout << ans << nl;
}
