#include <bits/stdc++.h>
using namespace std;
const int maxn = 200010;
int n, k, a[maxn], sum[maxn], lc;
long long ans;
map<int, int> num;
int main() {
  scanf("%d%d", &n, &k);
  for (int i = 1; i <= n; i++) {
    scanf("%d", &a[i]);
    if (a[i] < k)
      a[i] = -1;
    else if (a[i] == k)
      a[i] = -1, lc = i;
    else if (a[i] > k)
      a[i] = 1;
  }
  for (int i = 1; i <= n; i++) sum[i] = sum[i - 1] + a[i];
  for (int i = lc; i <= n; i++) num[sum[i]]++;
  for (int i = 1; i <= lc; i++) ans += num[sum[i - 1]] + num[sum[i - 1] - 1];
  printf("%lld\n", ans);
  return 0;
}
