#include <bits/stdc++.h>
using namespace std;
int n, m, a[200100], pos;
long long ans;
map<int, int> cnt;
int main() {
  ios_base::sync_with_stdio(0), cin.tie(0);
  cin >> n >> m;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
    if (a[i] == m) pos = i;
  }
  int x = 0, y = 0;
  cnt[0]++;
  for (int i = pos - 1; i >= 1; i--) {
    if (a[i] > m)
      x++;
    else
      y++;
    cnt[x - y]++;
  }
  int bal = 0;
  ans += cnt[0];
  for (int i = pos + 1; i <= n; i++) {
    if (a[i] > m)
      bal++;
    else
      bal--;
    ans += cnt[-bal];
  }
  bal = 0;
  ans += cnt[1];
  for (int i = pos + 1; i <= n; i++) {
    if (a[i] > m)
      bal++;
    else
      bal--;
    ans += cnt[-bal + 1];
  }
  cout << ans << "\n";
  return 0;
}
