#include <bits/stdc++.h>
using namespace std;
int n, m, p;
int sum;
long long cnt[400005];
int main() {
  scanf("%d%d", &n, &m);
  long long ans = 0;
  int sta = 0;
  cnt[200000] = 1;
  for (int i = 1; i <= n; i++) {
    int now, k;
    scanf("%d", &k);
    if (k == m) {
      now = 0;
      p = i;
      sta = 1;
    } else if (k < m)
      now = -1;
    else
      now = 1;
    sum += now;
    if (sta > 0) ans += cnt[sum + 200000] + cnt[sum - 1 + 200000];
    if (sta == 0) cnt[sum + 200000]++;
  }
  cout << ans;
  return 0;
}
