#include <bits/stdc++.h>
using namespace std;
long double const PI = acos(-1);
int const N = 2e5 + 47;
int was[2 * N];
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int n, m, p;
  cin >> n >> m;
  bool was_M = 0;
  int cnt = N;
  long long ans = 0;
  for (int i = (int)1; i <= (int)n; i++) {
    cin >> p;
    if (!was_M) was[cnt]++;
    if (p < m) cnt--;
    if (p > m) cnt++;
    if (p == m) was_M = 1;
    if (was_M) ans += was[cnt] + was[cnt - 1];
  }
  cout << ans;
  return 0;
}
