#include <bits/stdc++.h>
using namespace std;
pair<int, int> t[4] = {make_pair(0, 1), make_pair(1, 0), make_pair(-1, 0),
                       make_pair(0, -1)};
class compare {
 public:
  bool operator()(pair<int, int> a, pair<int, int> b) {
    return (a.second > b.second);
  }
};
bool compare2(long long int a, long long int b) { return (a < b); }
int main() {
  int n, m1;
  cin >> n >> m1;
  int a[n + 1], k = -1;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    if (a[i] == m1) {
      k = i;
    }
  }
  long long int count = 0;
  if (k == -1) {
    cout << 0 << endl;
    ;
  } else {
    long long int lessm = 0, greatm = 0;
    map<long long int, long long int> m;
    for (int i = k; i < n; i++) {
      if (a[i] <= m1)
        lessm++;
      else
        greatm++;
      long long int diff = lessm - greatm;
      m[diff]++;
      if (diff >= 0 && diff <= 1) count++;
    }
    lessm = 0;
    greatm = 0;
    for (int i = k - 1; i >= 0; i--) {
      if (a[i] <= m1)
        lessm++;
      else
        greatm++;
      long long int diff = lessm - greatm;
      long long int p = -1 * diff;
      if (p < 0) {
        count += m[p];
        count += m[p + 1];
      } else if (p > 0) {
        count += m[p];
        count += m[p + 1];
      } else {
        count += m[p];
        count += m[p + 1];
      }
    }
    cout << count << endl;
    ;
  }
}
