#include <bits/stdc++.h>
using namespace std;
map<int, int> Map;
int a[234567];
int main() {
  int n, m;
  scanf("%d%d", &n, &m);
  int vt = 0;
  for (int i = 1; i <= n; ++i) {
    scanf("%d", &a[i]);
    if (a[i] == m) vt = i;
  }
  int cnt = 0;
  long long ans = 1;
  for (int i = vt - 1; i > 0; --i) {
    if (a[i] > m)
      ++cnt;
    else
      --cnt;
    ++Map[cnt];
    if (cnt == 0 || cnt == 1) ++ans;
  }
  cnt = 0;
  for (int i = vt + 1; i <= n; ++i) {
    if (a[i] > m)
      --cnt;
    else
      ++cnt;
    for (int j = 0; j <= 1; ++j)
      if (Map.find(cnt + j) != Map.end()) ans += 1LL * Map[cnt + j];
    if (cnt == 0 || cnt == -1) ++ans;
  }
  cout << ans;
  return 0;
}
