#include <bits/stdc++.h>
using namespace std;
const double pi = acos(-1.0);
const long long MAX = 2e9 + 7;
const long long mod = 1e9 + 7;
const long long maxn = 2e5 + 7;
int n, m;
int s[maxn];
map<long long, long long> mp;
int main() {
  cin >> n >> m;
  int id;
  for (int i = 1; i <= n; i++) {
    cin >> s[i];
    if (m == s[i]) id = i;
  }
  int l = id;
  int r = id;
  long long num = 1;
  int a = 0, b = 0;
  r = id;
  a = 0;
  b = 0;
  while (r < n) {
    r++;
    if (s[r] > m)
      b++;
    else
      a++;
    mp[a - b]++;
    if (b - a == 0 || b - a == 1) {
      num++;
    }
  }
  l = id;
  a = 0;
  b = 0;
  while (l > 1) {
    l--;
    if (s[l] > m)
      b++;
    else
      a++;
    int c = b - a;
    num += mp[c - 1];
    num += mp[c];
    if (b - a == 0 || b - a == 1) num++;
  }
  cout << num << endl;
  return 0;
}
