#include <bits/stdc++.h>
using namespace std;
long long n, i, j, k, l, sum = 0, ind, t, a[200005] = {0}, ans = 0;
map<long long, long long> m, mm;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> k;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
    if (a[i] == k)
      ind = i, a[i] = 0;
    else if (a[i] < k)
      a[i] = -1;
    else
      a[i] = 1;
  }
  for (int i = 1; i <= n; i++) {
    a[i] += a[i - 1];
  }
  for (int i = ind; i <= n; i++) {
    mm[a[i]]++;
  }
  for (int i = 0; i < ind; i++) {
    ans += mm[a[i]] + mm[a[i] + 1];
  }
  cout << ans << '\n';
  return 0;
}
