#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 1;
long long int gcd(long long int a, long long int b) {
  if (b == 0) return a;
  return gcd(b, a % b);
}
long long int add(long long int x, long long int y) {
  x += y;
  while (x >= 1000000007) x -= 1000000007;
  while (x < 0) x += 1000000007;
  return x;
}
long long int mul(long long int x, long long int y) {
  return (x * 1ll * y) % 1000000007;
}
long long int binpow(long long int x, long long int y) {
  long long int z = 1;
  while (y) {
    if (y & 1) {
      z = mul(z, x);
    }
    x = mul(x, x);
    y >>= 1;
  }
  return z;
}
long long int inv(long long int x) { return binpow(x, 1000000007 - 2); }
long long int divide(long long int x, long long int y) {
  return mul(x, inv(y));
}
long long int fact[N];
void precalc() {
  fact[0] = 1;
  for (long long int i = 1; i < N; i++) {
    fact[i] = mul(fact[i - 1], i);
  }
}
long long int C(long long int n, long long int k) {
  return divide(fact[n], mul(fact[k], fact[n - k]));
}
long long int d = 0;
long long int depth[N];
void position(vector<long long int> &a, long long int s, long long int e,
              long long int d) {
  if (s < 0 || e < 0 || s > e) {
    return;
  }
  long long int mx = -1;
  long long int idx1 = -1;
  for (long long int i = s; i <= e; i++) {
    if (a[i] > mx) {
      mx = a[i];
      idx1 = i;
    }
  }
  depth[idx1] = d;
  position(a, s, idx1 - 1, d + 1);
  position(a, idx1 + 1, e, d + 1);
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long int tc;
  tc = 1;
  while (tc--) {
    long long int n, m;
    cin >> n >> m;
    long long int a[n];
    for (long long int i = 0; i < n; i++) {
      cin >> a[i];
    }
    long long int occur = -1;
    for (long long int i = 0; i < n; i++) {
      if (a[i] == m) {
        occur = i;
        break;
      }
    }
    long long int ans = 0;
    map<long long int, long long int> val;
    long long int dif = 0;
    val[0]++;
    for (long long int i = occur + 1; i < n; i++) {
      if (a[i] > m) {
        dif++;
      } else {
        dif--;
      }
      val[dif]++;
    }
    ans = ans + val[0] + val[1];
    dif = 0;
    for (long long int j = occur - 1; j >= 0; j--) {
      if (a[j] < m) {
        dif--;
      } else {
        dif++;
      }
      ans = ans + val[0 - dif] + val[1 - dif];
    }
    cout << ans << endl;
  }
  return 0;
}
