#include <bits/stdc++.h>
using namespace std;
map<long long, long long> memo;
signed main() {
  long long N, M;
  cin >> N >> M;
  vector<long long> v(N);
  for (long long i = 0; i < N; ++i) {
    cin >> v[i];
  }
  long long pos;
  for (pos = 0; pos < N; ++pos) {
    if (v[pos] == M) break;
  }
  long long smallr = 0, greatr = 0;
  ++memo[0];
  for (long long i = pos - 1; i >= 0; --i) {
    if (v[i] < M) ++smallr;
    if (v[i] > M) ++greatr;
    ++memo[greatr - smallr];
  }
  smallr = 0, greatr = 0;
  long long ans = memo[0] + memo[1];
  for (long long i = pos + 1; i < N; ++i) {
    if (v[i] < M) ++smallr;
    if (v[i] > M) ++greatr;
    ans += memo[smallr - greatr];
    ans += memo[smallr - greatr + 1];
  }
  cout << ans << endl;
}
