#include <bits/stdc++.h>
using namespace std;
pair<int, int> reg(pair<int, int> x) {
  int y = min(x.first, x.second);
  x.first -= y;
  x.second -= y;
  return x;
}
int main() {
  ios::sync_with_stdio(false);
  int n, m;
  cin >> n >> m;
  int t[n];
  int midx;
  for (int i = 0; i < n; i++) {
    cin >> t[i];
    if (t[i] == m) midx = i;
  }
  map<pair<int, int>, long long> be, af;
  pair<int, int> cur = make_pair(0, 0);
  for (int i = midx + 1; i < n; i++) {
    if (t[i] > m)
      cur.second++;
    else
      cur.first++;
    cur = reg(cur);
    af[cur]++;
  }
  cur = make_pair(0, 0);
  for (int i = midx; i >= 0; i--) {
    if (t[i] > m)
      cur.second++;
    else
      cur.first++;
    cur = reg(cur);
    be[cur]++;
  }
  long long ans = be[make_pair(1, 0)] + be[make_pair(0, 0)];
  for (auto i : af) {
    pair<int, int> x = i.first;
    long long nb = i.second;
    pair<int, int> y = make_pair(x.second, x.first);
    pair<int, int> y1 = reg(make_pair(x.second + 1, x.first));
    ans += nb * (be[y] + be[y1]);
  }
  cout << ans << endl;
}
