#include <bits/stdc++.h>
using namespace std;
ostream& operator<<(ostream& out, pair<int, int>& o) {
  out << "(" << o.first << ", " << o.second << ") ";
  return out;
}
template <class Int>
ostream& operator<<(ostream& out, vector<Int>& o) {
  for (auto it : o) out << it << " ";
  return out;
}
template <class Int>
istream& operator>>(istream& in, vector<Int>& i) {
  for (auto& it : i) in >> it;
  return in;
}
int main() {
  cin.tie(0);
  cin.sync_with_stdio(0);
  int n, m;
  cin >> n >> m;
  vector<int> v(n);
  cin >> v;
  map<int, int> Big;
  int root = 0;
  for (int i = 0; i < n; i++)
    if (v[i] == m) root = i;
  int cur = 0;
  Big[0] = 1;
  Big[1] = 0;
  for (int i = root + 1; i < n; i++) {
    cur += v[i] > v[root] ? 1 : -1;
    if (Big.count(cur))
      Big[cur] += 1;
    else
      Big[cur] = 1;
  }
  long long ans = Big[0] + Big[1];
  cur = 0;
  for (int i = root - 1; i >= 0; i--) {
    cur += v[i] > v[root] ? -1 : 1;
    if (Big.count(cur)) ans += Big[cur];
    if (Big.count(cur + 1)) ans += Big[cur + 1];
  }
  cout << ans << endl;
}
