#include <bits/stdc++.h>
using namespace std;
const int INF = 0x3f3f3f3f;
const int maxn = 200000 + 5;
const int MOD = 998244353;
int a[maxn], sum[maxn];
map<int, int> mp;
int main() {
  int n, m, pos = 0;
  scanf("%d %d", &n, &m);
  mp[0]++;
  for (int i = 1; i <= n; i++) {
    scanf("%d", &a[i]);
    sum[i] = sum[i - 1];
    if (a[i] > m)
      sum[i]++;
    else if (a[i] < m)
      sum[i]--;
    else
      pos = i;
    if (pos == 0) mp[sum[i]]++;
  }
  long long ans = 0;
  for (int i = pos; i <= n; i++) {
    ans += mp[sum[i]] + mp[sum[i] - 1];
  }
  cout << ans << endl;
}
