#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e5 + 7;
int n, m, a[maxn];
map<int, int> mp, rmp;
int main() {
  scanf("%d%d", &n, &m);
  int id;
  for (int i = 1; i <= n; i++) {
    scanf("%d", &a[i]);
    if (a[i] == m) id = i;
  }
  int cnt = 0;
  for (int i = id; i >= 1; i--) {
    if (a[i] < m)
      cnt++;
    else if (a[i] > m)
      cnt--;
    mp[cnt]++;
  }
  long long ans = 0;
  cnt = 0;
  for (int i = id; i <= n; i++) {
    if (a[i] < m)
      cnt++;
    else if (a[i] > m)
      cnt--;
    ans += 1LL * mp[-cnt] + 1LL * mp[-cnt - 1];
  }
  printf("%lld\n", ans);
  return 0;
}
