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