#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e5 + 10;
const int inf = 0x7fffffff;
int cmp(int a, int b) { return a < b; }
map<int, int> mp1, mp2;
int a[maxn], b[maxn];
int main() {
  int n, m;
  cin >> n >> m;
  int pos;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
    if (a[i] == m) b[i] = 0, pos = i;
    if (a[i] < m) b[i] = -1;
    if (a[i] > m) b[i] = 1;
  }
  int sum = 0;
  for (int i = pos; i <= n; i++) {
    sum += b[i];
    ++mp1[sum];
  }
  sum = 0;
  for (int i = pos; i >= 1; i--) {
    sum += b[i];
    ++mp2[sum];
  }
  unsigned long long cnt = 0;
  for (int i = -n; i <= n; i++) {
    cnt += 1ll * mp1[i] * mp2[-i];
  }
  for (int i = -(n + 1); i <= (n + 1); i++) {
    cnt += 1ll * mp1[i] * mp2[1 - i];
  }
  cout << cnt << endl;
  return 0;
}
