#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 50;
const long long oo = 1e18;
const long long mod = 1e9 + 7;
long long a[N];
map<long long, long long> mp[2];
int main() {
  long long n, m;
  cin >> n >> m;
  long long idx = 0;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
    if (a[i] == m) idx = i;
  }
  long long ans = 1;
  long long b = 0, s = 0, len = 0;
  for (int i = idx - 1; i >= 1; i--) {
    len++;
    if (a[i] < m)
      s++;
    else if (a[i] > m)
      b++;
    if (b - s == 1 || b - s == 0) ans++;
    mp[len % 2][b - s]++;
  }
  b = 0;
  s = 0;
  len = 0;
  for (int i = idx + 1; i <= n; i++) {
    len++;
    if (a[i] < m)
      s++;
    else
      b++;
    long long dif = s - b;
    ans += mp[(len % 2)][dif];
    if (!dif) ans++;
    if (dif <= 0) {
      ans += mp[!(len % 2)][dif + 1];
      if (dif == -1 && (len % 2)) ans++;
    } else if (dif > 0) {
      ans += mp[!(len % 2)][dif + 1];
      if (dif == 1 && !(len % 2)) ans++;
    }
  }
  cout << ans << endl;
}
