#include <bits/stdc++.h>
using namespace std;
vector<int> a, carga;
map<int, int> cargapost;
int main() {
  if (fopen("input.txt", "r")) freopen("input.txt", "r", stdin);
  int n, m, indm;
  scanf("%d %d ", &n, &m);
  a.assign(n, 0);
  carga.assign(n, 0);
  for (int i = 0; i < n; i++) {
    scanf("%d ", &a[i]);
    if (a[i] == m) indm = i;
  }
  for (int i = indm - 1; i >= 0; i--)
    if (a[i] > m)
      carga[i] = carga[i + 1] + 1;
    else
      carga[i] = carga[i + 1] - 1;
  for (int i = indm + 1; i < n; i++)
    if (a[i] > m)
      carga[i] = carga[i - 1] + 1;
    else
      carga[i] = carga[i - 1] - 1;
  for (int i = indm + 1; i < n; i++) cargapost[carga[i]]++;
  cargapost[0]++;
  long long ans = 0;
  for (int i = 0; i < indm + 1; i++)
    ans += (cargapost[-carga[i]] + cargapost[-carga[i] + 1]);
  printf("%lld", ans);
  return 0;
}
