#include <bits/stdc++.h>
using namespace std;
int cnt[400005];
int main() {
  int n, m;
  scanf("%d%d", &n, &m);
  int sum = n;
  cnt[n] = 1;
  bool f = 0;
  long long ans = 0;
  for (int i = 1; i <= n; i++) {
    int x;
    scanf("%d", &x);
    if (x < m) sum--;
    if (x > m) sum++;
    if (x == m) f = 1;
    if (f) {
      ans += cnt[sum] + cnt[sum - 1];
    } else {
      cnt[sum]++;
    }
  }
  printf("%lld", ans);
  return 0;
}
