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