#include <bits/stdc++.h>
using namespace std;
using ll = int64_t;
const int MAX = 2e5;
int32_t main() {
  ios::sync_with_stdio(false), cin.tie(nullptr);
  int n, m;
  cin >> n >> m;
  vector<int> v(n);
  for (int &it : v) cin >> it;
  map<int, int> cnt;
  cnt[0] = 1;
  ll ans = 0;
  int current = 0;
  bool found = false;
  for (int i = 0; i < n; i++) {
    if (v[i] < m)
      current--;
    else if (v[i] > m)
      current++;
    if (v[i] == m) found = true;
    if (found)
      ans += cnt[current] + cnt[current - 1];
    else
      cnt[current]++;
  }
  cout << ans;
  return 0;
}
