#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(false);
  int n, m, p = -1;
  cin >> n >> m;
  vector<int> a(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    if (a[i] == m) p = i;
  }
  vector<int> d(n, 0);
  int i1 = 0, i2 = 0;
  d[p] = 0;
  for (int i = p + 1; i < n; ++i) {
    i2 += (a[i] > m) ? 1 : -1;
    d[i] = i2;
  }
  for (int i = p - 1; i >= 0; --i) {
    i1 += (a[i] > m) ? 1 : -1;
    d[i] = i1;
  }
  long long ans = 0;
  map<int, int> h;
  for (int i = 0; i <= p; i++) h[d[i]]++;
  for (int i = p; i < n; i++) {
    ans += h[-d[i]];
    ans += h[-d[i] + 1];
  }
  h.clear();
  cout << ans;
  return 0;
}
