#include <bits/stdc++.h>
using namespace std;
template <typename T>
using V = vector<T>;
template <typename T>
using VV = vector<V<T>>;
template <typename T>
istream& operator>>(istream& cin, V<T>& arr) {
  for (T& val : arr) {
    cin >> val;
  }
  return cin;
}
template <typename T>
ostream& operator<<(ostream& cout, V<T>& arr) {
  for (T& val : arr) {
    cout << val << ' ';
  }
  return cout;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  long long n, m;
  cin >> n >> m;
  vector<long long> v(n + 1);
  long long idx = 0;
  for (long long i = 1; i <= n; i++) {
    cin >> v[i];
    if (v[i] == m) idx = i;
  }
  vector<long long> diff(n + 1);
  map<long long, long long> cnt;
  for (long long i = 1; i <= n; i++) {
    diff[i] = diff[i - 1];
    if (v[i] > m)
      diff[i]++;
    else if (v[i] < m)
      diff[i]--;
    if (i >= idx) cnt[diff[i]]++;
  }
  long long ans = 0;
  for (long long i = 1; i <= idx; i++) {
    ans += cnt[diff[i - 1]] + cnt[diff[i - 1] + 1];
  }
  cout << ans;
  return 0;
}
