#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  int n, m;
  cin >> n >> m;
  vector<int> v(n);
  for (int &i : v) cin >> i;
  int id;
  for (int i = 0; i < n; i++)
    if (v[i] == m) {
      id = i;
      break;
    }
  for (int &i : v) {
    if (i < m)
      i = -1;
    else if (i > m)
      i = 1;
    else if (i == m)
      i = 0;
  }
  long long ans = 0;
  map<int, int> freq[2];
  int sum = 0;
  for (int i = id; i >= 0; i--) {
    int k = (id - i + 1) % 2;
    sum += v[i];
    freq[k][sum]++;
  }
  sum = 0;
  for (int i = id; i < n; i++) {
    int k = (i - id + 1) % 2;
    sum += v[i];
    ans += freq[k][-sum];
    ans += freq[(k + 1) % 2][-sum + 1];
  }
  cout << ans << endl;
  exit(0);
}
