#include <bits/stdc++.h>
using namespace std;
const int MN = 2e5 + 100, inf = 1e9 + 100, mod = 1e9 + 7;
long long n, m, a[MN], t[MN], z[4 * MN], plc;
int32_t main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> m;
  for (long long i = 0; i < n; i++) {
    cin >> a[i];
    if (a[i] == m) plc = i;
  }
  for (long long i = plc - 1; i >= 0; i--) {
    if (a[i] > m) {
      z[i + MN] = z[i + 1 + MN] - 1;
    } else {
      z[i + MN] = z[i + 1 + MN] + 1;
    }
  }
  t[0]++;
  for (long long i = plc + 1; i < n; i++) {
    if (a[i] > m) {
      z[i + MN] = z[i - 1 + MN] - 1;
    } else {
      z[i + MN] = z[i - 1 + MN] + 1;
    }
    t[z[i + MN]]++;
  }
  long long ans = 0;
  for (long long i = 0; i <= plc; i++) {
    ans += t[-z[i + MN]];
    ans += t[-1 - z[i + MN]];
  }
  cout << ans << endl;
}
