#include <bits/stdc++.h>
using namespace std;
const long long N = 1e6;
long long n, m, pos = -1, a[N];
long long l, r, res = 0;
long long d[2 * N + 2];
int main() {
  scanf("%lld%lld", &n, &m);
  for (long long i = 0; i < n; i++) {
    scanf("%lld", a + i);
    if (a[i] == m) pos = i;
  }
  long long *diff = d + N;
  assert(pos >= 0);
  for (long long i = pos - 1; i >= 0; i--) {
    assert(i >= 0);
    if (a[i] < m)
      l++;
    else
      r++;
    diff[r - l]++;
  }
  diff[0]++;
  res += diff[0] + diff[1];
  assert(diff[0] >= 0 && diff[1] >= 0);
  long long l = 0, r = 0;
  for (long long i = pos + 1; i < n; i++) {
    if (a[i] < m)
      l++;
    else
      r++;
    assert(diff[l - r + 1] >= 0 && diff[l - r] >= 0);
    res += diff[l - r + 1];
    res += diff[l - r];
  }
  printf("%lld\n", res);
}
