#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 10;
int a[N];
int sum[N << 1];
int main() {
  long long total;
  int sum1, sum0, sum_1, presum, sufsum;
  int n, m, pos, temp;
  cin >> n >> m;
  pos = -1;
  for (int i = 0; i < n; i++) {
    cin >> temp;
    if (temp == m) {
      pos = i;
      a[i] = 0;
    } else if (temp > m) {
      a[i] = 1;
    } else {
      a[i] = -1;
    }
  }
  presum = 0;
  for (int i = 0; i < N; i++) sum[i] = 0;
  for (int i = pos; i < n; i++) {
    presum += a[i];
    sum[N + presum]++;
  }
  sufsum = 0;
  total = 0;
  for (int i = pos; i >= 0; i--) {
    sufsum += a[i];
    total += sum[N - sufsum] + sum[N - sufsum + 1];
  }
  cout << total;
  return 0;
}
