#include <bits/stdc++.h>
using namespace std;
int Set(int mask, int pos) { return mask = mask | (1 << pos); }
bool check(int mask, int pos) { return (bool)(mask & (1 << pos)); }
int arr[1000005];
int main() {
  ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  int n, m, idx;
  cin >> n >> m;
  for (int i = 0; i < n; i++) {
    cin >> arr[i];
    if (arr[i] == m) {
      idx = i;
    }
  }
  map<int, int> mp;
  long long ans = 1;
  int greater_m = 0, smaller_m = 0;
  for (int i = idx + 1; i < n; i++) {
    (arr[i] > m) ? greater_m++ : smaller_m++;
    mp[smaller_m - greater_m]++;
    if (smaller_m - greater_m == 0 || smaller_m - greater_m == -1) ans++;
  }
  greater_m = 0, smaller_m = 0;
  for (int i = idx - 1; i >= 0; i--) {
    (arr[i] > m) ? greater_m++ : smaller_m++;
    int diff = smaller_m - greater_m;
    ans += (long long)mp[-diff];
    ans += (long long)mp[-diff - 1];
    if (diff == 0 || diff == -1) ans++;
  }
  cout << ans << endl;
  return 0;
}
