#include <bits/stdc++.h>
using namespace std;
long long n, i, j, k, l, m, a[1040000], b[1010000];
long long nx = 0, ny = 0, x, y, w;
map<long long, long long> q;
int main() {
  cin >> n >> m;
  for (i = 1; i <= n; i++) {
    cin >> a[i];
    if (a[i] > m) {
      a[i] = 1;
    } else if (a[i] < m) {
      a[i] = -1;
    } else {
      a[i] = 0;
      l = i;
    }
  }
  for (i = 1; i <= n; i++) {
    b[i] = b[i - 1] + a[i];
  }
  for (i = 1; i <= l; i++) {
    q[b[l] - b[i - 1]]++;
  }
  long long o = q[0] + q[1], m1 = 0, m2 = 0;
  for (i = l + 1; i <= n; i++) {
    o += q[-(b[i] - b[l])] + q[-(b[i] - b[l]) + 1];
  }
  cout << o;
}
