#include <bits/stdc++.h>
const int MAXN = int(2e5);
int n, k, cnt, A, tot[2 * MAXN + 5];
bool flag;
long long ans;
int read(int &x) {
  char c = getchar();
  int a = 0, b = 1;
  while ('0' > c || c > '9') b = c == '-' ? -1 : b, c = getchar();
  while ('0' <= c && c <= '9') a = a * 10 + c - '0', c = getchar();
  return x = a * b;
}
int main() {
  read(n);
  read(k);
  tot[MAXN]++;
  for (int i = 0; i < n; i++) {
    read(A);
    if (A == k) flag = true;
    if (A > k) cnt++;
    if (A < k) cnt--;
    if (!flag)
      tot[cnt + MAXN]++;
    else
      ans += tot[cnt + MAXN] + tot[cnt + MAXN - 1];
  }
  printf("%lld\n", ans);
  return 0;
}
