#include <bits/stdc++.h>
using namespace std;
void cline() { cout << '\n'; }
template <typename T, typename... V>
void cline(T t, V... v) {
  cout << t;
  if (sizeof...(v)) cout << ' ';
  cline(v...);
}
void cspc() { cout << ' '; }
template <typename T, typename... V>
void cspc(T t, V... v) {
  cout << t;
  if (sizeof...(v)) cout << ' ';
  cspc(v...);
}
const long long N = 2e5 + 4;
long long state[2 * N][2];
int32_t main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  memset(state, 0, sizeof(state));
  long long n, m;
  cin >> n >> m;
  long long ind = -1;
  long long a[n];
  for (long long i = 0; i < n; i++) {
    cin >> a[i];
    if (m == a[i]) ind = i;
  }
  long long oki = 0, cnt = 0;
  for (long long i = 0; i < n; i++) {
    if (a[i] < m)
      oki--;
    else if (a[i] > m)
      oki++;
    if (i >= ind) state[N + oki][i & 1]++;
  }
  oki = 0;
  for (long long i = 0; i <= ind; ++i) {
    if (i % 2 == 1) {
      cnt += state[N + oki + 1][0];
      cnt += state[N + oki][1];
    } else {
      cnt += state[N + oki][0];
      cnt += state[N + oki + 1][1];
    }
    if (a[i] < m)
      oki--;
    else
      oki++;
  }
  cspc(cnt);
  return 0;
}
