#include <bits/stdc++.h>
using namespace std;
int i, n, m, cnt, j, t;
int a[200010], l[200010], r[200010];
long long Ans;
map<int, int> L, R;
int main() {
  scanf("%d%d", &n, &m);
  for (i = 1; i <= n; i++) scanf("%d", &a[i]);
  for (i = 1; i <= n; i++)
    if (a[i] == m) {
      for (j = 1; j < i; j++)
        if (a[j] < m)
          a[j] = -1;
        else
          a[j] = 1;
      for (j = i + 1; j <= n; j++)
        if (a[j] < m)
          a[j] = -1;
        else
          a[j] = 1;
      t = i;
      break;
    }
  L[0]++;
  R[0]++;
  l[0]++;
  r[0]++;
  for (i = t - 1; i; i--) {
    cnt += a[i];
    L[cnt]++;
    if (L[cnt] == 1) l[++l[0]] = cnt;
  }
  cnt = 0;
  for (i = t + 1; i <= n; i++) {
    cnt += a[i];
    R[cnt]++;
    if (R[cnt] == 1) r[++r[0]] = cnt;
  }
  for (i = 1; i <= l[0]; i++) {
    if (R[-l[i]]) Ans += (long long)L[l[i]] * R[-l[i]];
    if (R[1 - l[i]]) Ans += (long long)L[l[i]] * R[1 - l[i]];
  }
  cout << Ans << endl;
  return 0;
}
