#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 10;
int a[N], n, m;
long long o[N], o2[N];
int main() {
  scanf("%d%d", &n, &m);
  int poz;
  for (int i = 1; i <= n; i++) {
    scanf("%d", &a[i]);
    if (a[i] == m) poz = i;
  }
  for (int i = 0; i <= N - 5; i++) o[i] = 0, o2[i] = 0;
  o[0] = 1;
  int sum = 0;
  for (int i = poz + 1; i <= n; i++) {
    if (a[i] > m)
      sum++;
    else
      sum--;
    if (sum >= 0)
      o[sum]++;
    else
      o2[abs(sum)]++;
  }
  long long ans = 0;
  sum = 0;
  for (int i = poz; i >= 1; i--) {
    if (a[i] > m)
      sum++;
    else if (a[i] < m)
      sum--;
    if (sum <= 0)
      ans += (o[abs(sum)] + o[abs(sum) + 1]);
    else {
      ans += o2[sum];
      if (sum == 1)
        ans += o[0];
      else
        ans += o2[sum - 1];
    }
  }
  printf("%lld", ans);
  return 0;
}
