#include<bits/stdc++.h>
#define  js  ios::sync_with_stdio(false);cin.tie(0);cout.tie(0)
using namespace std;
typedef long long ll;
const int maxn = 100010;
int qian[maxn<<1],sum,a,n,k,pos;
int main() {
    js; cin>>n>>k;
    qian[n]=1;    ll ans=0;
    for(ll i=1;i<=n;++i) {
        cin>>a;
        if(a==k)    pos=i;
        if(a>=k)    ++sum;
        else --sum;
        if(!pos) ++qian[sum+n];
        else ans+=qian[sum+n-1];
    }
    cout<<ans<<endl;
    return 0;
}