#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  int a[n];
  int index;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    if (a[i] == m) index = i;
  }
  int sum = 0;
  unordered_map<int, int> HashTable;
  HashTable[0] = 1;
  long long res = 0;
  for (int i = 0; i < n; i++) {
    if (a[i] < m)
      sum++;
    else if (a[i] > m)
      sum--;
    if (i >= index)
      res += HashTable[sum] + HashTable[sum + 1];
    else
      HashTable[sum]++;
  }
  cout << res << endl;
}
