#include <bits/stdc++.h>
inline long long MAX2(long long a, long long int b) {
  return (a) > (b) ? (a) : (b);
}
inline long long MAX3(long long a, long long b, long long c) {
  return (a) > (b) ? ((a) > (c) ? (a) : (c)) : ((b) > (c) ? (b) : (c));
}
inline long long MIN2(long long a, long long b) {
  return (a) < (b) ? (a) : (b);
}
inline long long MIN3(long long a, long long b, long long c) {
  return (a) < (b) ? ((a) < (c) ? (a) : (c)) : ((b) < (c) ? (b) : (c));
}
using namespace std;
int main() {
  int i;
  long long n, m;
  long long p[200005];
  cin >> n >> m;
  map<long long, long long> left, right;
  map<long long, long long>::iterator it, it1;
  long long mpos;
  for (i = 0; i < n; i++) {
    cin >> p[i];
    if (p[i] == m) mpos = i;
  }
  long long less = 0, more = 0;
  for (i = mpos - 1; i >= 0; i--) {
    if (p[i] < m)
      less++;
    else
      more++;
    left[less - more]++;
  }
  less = 0, more = 0;
  for (i = mpos + 1; i < n; i++) {
    if (p[i] < m)
      less++;
    else
      more++;
    right[less - more]++;
  }
  long long ans = 1;
  for (i = 0; i >= -1; i--) {
    if (left.find(i) != left.end()) ans += left[i];
    if (right.find(i) != right.end()) ans += right[i];
  }
  for (it = right.begin(); it != right.end(); it++) {
    for (i = 0; i >= -1; i--) {
      it1 = left.find(-it->first + i);
      if (it1 != left.end()) ans += it->second * it1->second;
    }
  }
  cout << ans;
}
