#include <bits/stdc++.h>
using namespace std;
string alpha = "abcdefghijklmnopqrstuvwxyz";
string Alpha = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
string glas = "aeiou";
long long int Mod = 1000 * 1000 * 1000 + 7;
long long int INF = 1000000000000000000;
int main() {
  iostream::sync_with_stdio(false);
  cin.tie(0);
  long long int n, m;
  cin >> n >> m;
  vector<long long int> v(n);
  long long int pos;
  for (long long int i = 0; i < n; i++) {
    cin >> v[i];
    if (v[i] > m)
      v[i] = 1;
    else if (v[i] < m)
      v[i] = -1;
    else
      pos = i, v[i] = 0;
  }
  long long int sum = 0;
  vector<long long int> low, up;
  for (long long int i = pos; i >= 0; i--) sum += v[i], low.push_back(sum);
  sum = 0;
  for (long long int i = pos; i < n; i++) sum += v[i], up.push_back(sum);
  sort(low.begin(), low.end());
  sort(up.begin(), up.end());
  vector<long long int> upp(2 * n + 5);
  for (long long int i = 0; i < up.size(); i++) {
    long long int curr = up[i] + n;
    upp[curr]++;
  }
  long long int ans = 0;
  for (long long int i = 0; i < low.size(); i++) {
    for (long long int j = (0 - low[i]) + n; j < (2 - low[i]) + n; j++) {
      ans += upp[j];
    }
  }
  cout << ans;
}
