#include <bits/stdc++.h>
using namespace std;
int n, m;
int p[200010];
int pos;
long long ans = 0;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> m;
  for (int i = 0; i < n; i++) {
    cin >> p[i];
    if (p[i] == m) pos = i;
  }
  int cnt = 0;
  for (int i = pos + 1; i < n; i++) {
    if (p[i] > m) cnt++;
    if (p[i] < m) cnt--;
    p[i] = cnt;
  }
  cnt = 0;
  for (int i = pos - 1; i >= 0; i--) {
    if (p[i] > m) cnt++;
    if (p[i] < m) cnt--;
    p[i] = cnt;
  }
  p[pos] = 0;
  sort(p + pos + 1, p + n);
  for (int i = 0; i <= pos; i++) {
    int ri;
    ri = 1 - p[i];
    ans += (upper_bound(p + pos + 1, p + n, ri) -
            lower_bound(p + pos + 1, p + n, ri));
    ri = 0 - p[i];
    ans += (upper_bound(p + pos + 1, p + n, ri) -
            lower_bound(p + pos + 1, p + n, ri));
  }
  sort(p, p + pos + 1);
  ans += (upper_bound(p, p + pos + 1, 0) - lower_bound(p, p + pos + 1, 0));
  ans += (upper_bound(p, p + pos + 1, 1) - lower_bound(p, p + pos + 1, 1));
  cout << ans << endl;
}
