#include #include #include #include #include using namespace std; int a[500009]; int x[500009]; int b[500009]; int dp[500009]; int main() { int n,m; while(scanf("%d%d",&n,&m)!=EOF) { int tol=0;int which; for(int i=1;i<=n;i++) { scanf("%d",&x[i]); if(x[i]==m)which=i; } dp[which]=40000; memset(a,0,sizeof(a)); memset(b,0,sizeof(b)); for(int i=which-1;i>=1;i--) { if(x[i]>x[which])dp[i]=dp[i+1]-1; else dp[i]=dp[i+1]+1; a[dp[i]]++; } for(int i=which+1;i<=n;i++) { if(x[i]>x[which])dp[i]=dp[i-1]-1; else dp[i]=dp[i-1]+1; b[dp[i]]++; } int ans=0; a[40000]++;b[40000]++; for(int i=0;i<=80000;i++) { ans+=a[i]*b[80000-i]; } printf("%d\n",ans); } return 0; }