#include <bits/stdc++.h>
using namespace std;
const int NMAX = 200010;
int n, m;
int num[NMAX];
map<int, int> mp;
long long ans;
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= n; i++) scanf("%d", &num[i]);
  int cnt = 0, pos;
  for (int i = 1; i <= n; i++)
    if (num[i] == m) pos = i;
  for (int i = pos; i <= n; i++) {
    if (num[i] > m) cnt += 1;
    if (num[i] < m) cnt -= 1;
    mp[cnt] += 1;
  }
  cnt = 0;
  for (int i = pos; i >= 1; i--) {
    if (num[i] < m) cnt -= 1;
    if (num[i] > m) cnt += 1;
    ans += mp[-cnt];
    ans += mp[-cnt + 1];
  }
  printf("%I64d\n", ans);
  return 0;
}
