#include<cstdio> #include<cstdlib> #include<algorithm> #include<cstring> #include<vector> #define MAXN 100000+10 #define a(x) a[x+MAXN] #define b(x) b[x+MAXN] using namespace std; int a[MAXN<<1],b[MAXN<<1]; int n,m,p; int s[MAXN]; int main() { scanf("%d%d",&n,&m); for(int i=1;i<=n;i++){ scanf("%d",&s[i]); if(s[i]==m){ p=i; } } int fe=0,bi=0; a(0)++; for(int i=p-1;i>=1;i--){ if(s[i]<m)fe++; else bi++; a(fe-bi)++; } fe=0,bi=0; b(0)++; for(int i=p+1;i<=n;i++){ if(s[i]<m)fe++; else bi++; b(fe-bi)++; } int ans=0; for(int i=-n;i<=n;i++){ ans+=a(i)*b(-i); } printf("%d ",ans); return 0; }