#include <bits/stdc++.h>
using namespace std;
template <class T>
T modpower(T a, T b, T MOD) {
  T ans = 1;
  while (b != 0) {
    if (b % 2 == 1) ans = (ans * a) % MOD;
    a = (a * a) % MOD;
    b /= 2;
  }
  return ans;
}
void init() {
  int n, m;
  cin >> n >> m;
  int x, d = 0;
  long long int ans = 0;
  map<int, int> ma;
  bool fg = false;
  ma[0] = 1;
  for (int i = 0; i < n; i++) {
    cin >> x;
    if (x == m) fg = true;
    if (x < m) {
      d--;
    } else if (x > m) {
      d++;
    }
    if (fg) {
      ans += (ma[d] + ma[d - 1]);
    } else {
      ma[d]++;
    }
  }
  cout << ans;
}
int main() {
  clock_t time1 = clock();
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  init();
  clock_t time2 = clock();
  cerr << "Time: " << (double)(time2 - time1) / CLOCKS_PER_SEC * 100000
       << " seconds" << endl;
  return 0;
}
