#include <bits/stdc++.h>
using namespace std;
const int MAXN = 2e5 + 5;
struct Segment {
  vector<int> tree;
  int size;
  Segment() {}
  Segment(int N) : size(N + 1) { tree.resize(4 * (N + 1), 0); }
  int update(int idx, int val, int node, int nl, int nr) {
    if (idx < nl || idx > nr) return tree[node];
    if (nl == nr) return tree[node] += val;
    int mid = (nl + nr) >> 1;
    return tree[node] = update(idx, val, node * 2, nl, mid) +
                        update(idx, val, node * 2 + 1, mid + 1, nr);
  }
  void update(int idx, int val) { update(idx, val, 1, 0, size - 1); }
  int query(int val, int node, int nl, int nr) {
    if (nl == nr) return nl;
    int mid = (nl + nr) >> 1;
    if (tree[node * 2] >= val)
      return query(val, node * 2, nl, mid);
    else
      return query(val - tree[node * 2], node * 2 + 1, mid + 1, nr);
  }
  int query(int val) { return query(val, 1, 0, size - 1); }
};
int n, m, idx;
int arr[MAXN];
int l[MAXN], r[MAXN];
map<int, int> odd, even;
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 0; i < n; i++) {
    scanf("%d", &arr[i]);
    if (arr[i] == m) idx = i;
  }
  for (int i = idx - 1; i >= 0; i--) {
    l[i] = l[i + 1];
    if (arr[i] < m)
      l[i]--;
    else
      l[i]++;
  }
  for (int i = idx; i < n; i++) {
    r[i] = r[i - 1];
    if (arr[i] > m)
      r[i]++;
    else if (arr[i] < m)
      r[i]--;
    if (i & 1)
      odd[r[i]]++;
    else
      even[r[i]]++;
  }
  long long ans = 0;
  l[idx] = 0;
  for (int i = idx; i >= 0; i--) {
    if (i & 1)
      ans += (long long)even[-l[i] + 1] + odd[-l[i]];
    else
      ans += (long long)odd[-l[i] + 1] + even[-l[i]];
  }
  printf("%lld\n", ans);
  return 0;
}
