#include <bits/stdc++.h>
using namespace std;
const double eps = 1e-8;
const double pi = acos(-1.0);
const long long INF = 0x3f3f3f3f3f3f3f3f;
const int inf = 0x3f3f3f3f;
const int N = 2e5 + 5;
int n, m;
int a[N];
vector<int> e[N];
int dir[4][2] = {{1, 0}, {-1, 0}, {0, 1}, {0, -1}};
void INIT() {}
void solve() {
  INIT();
  int pos;
  for (int i = 1; i <= n; i++) {
    cin >> (a[i]);
    if (a[i] == m) pos = i;
  }
  map<int, int> ma;
  int num = 0;
  for (int i = pos; i >= 1; i--) {
    if (a[i] > m) {
      num--;
    }
    if (a[i] < m) {
      num++;
    }
    ma[num]++;
  }
  num = 0;
  long long ans = 0;
  for (int i = pos; i <= n; i++) {
    if (a[i] > m) {
      num--;
    }
    if (a[i] < m) {
      num++;
    }
    ans += ma[-num] + ma[-1 - num];
  }
  cout << (ans) << '\n';
}
int main() {
  ios::sync_with_stdio(false);
  while (cin >> n >> m) {
    solve();
  }
  return 0;
}
