#include <bits/stdc++.h>
using namespace std;
const int N = int(2e5) + 10;
const int MOD = int(1e9) + 7;
const int INF = int(2e9) + 5;
const long long INF64 = 1e18;
int a[N];
map<int, int> cnt;
void solve() {
  int n, m;
  cin >> n >> m;
  int index = -1;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
    if (a[i] == m) index = i;
  }
  int currVal = 0;
  cnt[0]++;
  for (int l = index - 1; l > 0; l--) {
    currVal = currVal + (a[l] < m ? 1 : -1);
    cnt[currVal]++;
  }
  long long ans = cnt[0] + cnt[-1];
  currVal = 0;
  for (int r = index + 1; r <= n; r++) {
    currVal = currVal + (a[r] > m ? 1 : -1);
    ans += (cnt[currVal] + cnt[currVal - 1]);
  }
  cout << ans << endl;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int t;
  t = 1;
  while (t--) solve();
  return 0;
}
