#include <bits/stdc++.h>
using namespace std;
const int MAX_N = 200 * 1000;
int p[MAX_N];
int n, m, poi;
long long ans;
void readInput() {
  cin >> n >> m;
  for (int i = 0; i < n; i++) {
    cin >> p[i];
    if (p[i] == m) poi = i;
  }
}
void update(vector<pair<int, int>> &vec) {
  int x = 0;
  for (int i = 1; i < (int)vec.size(); i++)
    if (vec[x].first == vec[i].first)
      vec[x].second++;
    else {
      vec[x + 1] = vec[i];
      x++;
    }
  while ((int)vec.size() - 1 > x) vec.pop_back();
}
void solve() {
  vector<pair<int, int>> left = {{0, 1}}, right = {{0, 1}};
  int tmp = 0;
  for (int i = poi - 1; i >= 0; i--) {
    if (p[i] > m)
      tmp++;
    else
      tmp--;
    left.push_back({tmp, 1});
  }
  tmp = 0;
  for (int i = poi + 1; i < n; i++) {
    if (p[i] > m)
      tmp++;
    else
      tmp--;
    right.push_back({tmp, 1});
  }
  sort(left.begin(), left.end());
  sort(right.begin(), right.end(), greater<pair<int, int>>());
  update(right);
  update(left);
  int cur = 0;
  for (auto i : left) {
    while (i.first + right[cur].first > 1 && cur < (int)right.size() - 1) cur++;
    if (i.first + right[cur].first == 1)
      ans += 1LL * right[cur].second * i.second, cur++;
    if (i.first + right[cur].first == 0)
      ans += 1LL * right[cur].second * i.second;
  }
}
int main() {
  readInput();
  solve();
  cout << ans;
}
