#include <bits/stdc++.h>
using namespace std;
const int MAXN = 200010;
int a[MAXN];
int main() {
  int n, m;
  while (~scanf("%d %d", &n, &m)) {
    int index, pp;
    for (int i = 1; i <= n; i++) {
      scanf("%d", &a[i]);
      if (a[i] == m) index = i;
      if (a[i] == m + 1) pp = i;
    }
    map<int, int> ma;
    ma.clear();
    int x(0), y(0);
    ma[0] = 1;
    for (int i = 1; i < index; i++) {
      if (a[i] > m)
        x++;
      else
        y++;
      int t(x - y);
      if (ma.find(t) == ma.end())
        ma[t] = 1;
      else
        ma[t]++;
    }
    long long ans(0);
    for (int i = index; i <= n; i++) {
      if (a[i] > m)
        x++;
      else if (a[i] < m)
        y++;
      if (ma.find(x - y) != ma.end()) ans += ma[x - y];
    }
    x = y = 0;
    ma.clear();
    ma[0] = 1;
    for (int i = 1; i < index; i++) {
      if (a[i] > m)
        x++;
      else
        y++;
      int t(x - y);
      if (ma.find(t) == ma.end())
        ma[t] = 1;
      else
        ma[t]++;
    }
    for (int i = index; i <= n; i++) {
      if (a[i] > m)
        x++;
      else if (a[i] < m)
        y++;
      if (ma.find(x - y - 1) != ma.end()) ans += ma[x - y - 1];
    }
    printf("%I64d\n", ans);
  }
  return 0;
}
