#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  map<int, int> mp;
  int pref = 0;
  bool was = 0;
  long long ans = 0;
  for (int i = 0; i < n; ++i) {
    int pn;
    cin >> pn;
    pref += (pn <= m ? -1 : 1);
    if (pn == m) was = 1;
    if (!was) {
      mp[pref]++;
    } else {
      ans += mp[pref + 1] + mp[pref];
      ans += (pref == -1 || pref == 0);
    }
  }
  cout << ans;
}
