#include <bits/stdc++.h>
using namespace std;
int a[200009];
map<long long int, long long int> b;
int main() {
  int i, j, n, m;
  cin >> n >> m;
  for (i = 1; i <= n; i++) {
    cin >> a[i];
  }
  long long int gre = 0, sma = 0, ans = 0;
  b[0] = 1;
  bool f = 0;
  j = 1;
  while (a[j] != m) {
    if (a[j] > m) {
      gre++;
    }
    if (a[j] < m) {
      sma++;
    }
    b[gre - sma]++;
    j++;
  }
  for (i = j; i <= n; i++) {
    if (a[i] > m) {
      gre++;
    }
    if (a[i] < m) {
      sma++;
    }
    ans += b[gre - sma];
    ans += b[gre - sma - 1];
  }
  cout << ans;
  return 0;
}
