#include <bits/stdc++.h>
using namespace std;
long long N, M, a[200005], aux, mayor[200005], menor[200005], diff[3 * 200005],
    d, ans;
int main() {
  cin >> N >> M;
  for (long long i = 1; i <= N; i++) {
    cin >> a[i];
    if (a[i] == M) aux = i;
  }
  for (long long i = aux + 1; i <= N; i++) {
    mayor[i] = mayor[i - 1];
    menor[i] = menor[i - 1];
    if (a[i] > M) mayor[i]++;
    if (a[i] < M) menor[i]++;
  }
  for (long long i = aux - 1; i > 0; i--) {
    mayor[i] = mayor[i + 1];
    menor[i] = menor[i + 1];
    if (a[i] > M) mayor[i]++;
    if (a[i] < M) menor[i]++;
  }
  for (long long i = N; i > 0; i--) {
    d = mayor[i] - menor[i];
    if (i >= aux) diff[d + 200005]++;
    if (i <= aux) ans += diff[(1 - d) + 200005] + diff[(-d) + 200005];
  }
  cout << ans << "\n";
  return 0;
}
