#include <bits/stdc++.h>
#define pb push_back
#define FOR(i, a, b) for(int i = int(a); i <= int(b); i++)
#define FORD(i, a, b) for(int i = int(a); i >= int(b); i--)
#define REP(i, r) for(int i = 0; i < r; i++)
#define FAST ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define READFILE freopen("input.txt", "r", stdin)
#define WRITEFILE freopen("output.txt", "w", stdout);
#define ll long long
#define ii pair<int, int>
#define fi first
#define se second
using namespace std;

const int MAX=2e5+66;

int n,x,a[MAX], sum, Ans;
map<int,int> cnt;
bool Found;

void Solve()
{
	cnt[0]=1;
	FOR(i,1,n){
		if (a[i]<x) sum--;
		if (a[i]>x) sum++;
		if (a[i]==x) Found=true;
		if (Found) Ans+=cnt[sum]+cnt[sum-1];
		else cnt[sum]++;
	}
	cout << Ans;
}

int main()
{
    #ifndef ONLINE_JUDGE
        READFILE;
    #endif
    FAST;

 	cin >> n >> x;
 	FOR(i,1,n) cin >> a[i];
 	Solve();
    return 0;
}


#include<iostream>
#include<algorithm>
#include<stdio.h>
#include<string.h>
#include<cmath>
#include<set>
#define N 200010
using namespace std;
long long i,n,m,flag,q[N],lef[N],righ[N];
int main()
{
	scanf("%lld%lld",&m,&n);
	for(i=0;i<m;i++){
		scanf("%lld",&q[i]);
		if(n==q[i]) {
			flag=i;
			q[i]=0;
		}else if(q[i]>n) {
			q[i]=1;
		}else if(q[i]<n) {
			q[i]=-1;
		}
	}
	long long count=0;
	long long qw_l=0;
	for(i=flag-1;i>=0;i--){
		count+=q[i];
		lef[qw_l++]=count;
	}
	lef[qw_l++]=0;
	sort(lef,lef+qw_l);
	count=0;long long qw_r=0;
	for(i=flag+1;i<m;i++){
		count+=q[i];
		righ[qw_r++]=count;
	}
	righ[qw_r++]=0;
	sort(righ,righ+qw_r);
	long long ans=0;
	for(i=0;i<qw_l;i++){
		if(binary_search(righ,righ+qw_r,-lef[i])){
			ans+=upper_bound(righ,righ+qw_r,-lef[i])-lower_bound(righ,righ+qw_r,-lef[i]);
		}
		if(binary_search(righ,righ+qw_r,1-lef[i])){
			ans+=upper_bound(righ,righ+qw_r,1-lef[i])-lower_bound(righ,righ+qw_r,1-lef[i]);
		}
	}
	printf("%lld\n",ans);
	return 0;
}


#include<iostream>
#include<algorithm>
#include<stdio.h>
#include<string.h>
#include<cmath>
#include<set>
#define N 200010
using namespace std;
int i,n,m,flag,q[N],lef[N],righ[N];
int main()
{
	scanf("%d%d",&m,&n);
	for(i=0;i<m;i++){
		scanf("%d",&q[i]);
		if(n==q[i]) {
			flag=i;
			q[i]=0;
		}else if(q[i]>n) {
			q[i]=1;
		}else if(q[i]<n) {
			q[i]=-1;
		}
	}
	int count=0;
	int qw_l=0;
	for(i=flag-1;i>=0;i--){
		count+=q[i];
		lef[qw_l++]=count;
	}
	lef[qw_l++]=0;
	sort(lef,lef+qw_l);
	count=0;int qw_r=0;
	for(i=flag+1;i<m;i++){
		count+=q[i];
		righ[qw_r++]=count;
	}
	righ[qw_r++]=0;
	sort(righ,righ+qw_r);
	int ans=0;
	for(i=0;i<qw_l;i++){
		if(binary_search(righ,righ+qw_r,-lef[i])){
			ans+=upper_bound(righ,righ+qw_r,-lef[i])-lower_bound(righ,righ+qw_r,-lef[i]);
		}
		if(binary_search(righ,righ+qw_r,1-lef[i])){
			ans+=upper_bound(righ,righ+qw_r,1-lef[i])-lower_bound(righ,righ+qw_r,1-lef[i]);
		}
	}
	printf("%d\n",ans);
	return 0;
}


#include<iostream>
#include<algorithm>
#include<stdio.h>
#include<string.h>
#include<cmath>
#include<set>
#define N 200010
using namespace std;
long long i,n,m,flag,q[N],lef[N],righ[N];
int main()
{
	scanf("%lld%lld",&m,&n);
	for(i=0;i<m;i++){
		scanf("%lld",&q[i]);
		if(n==q[i]) {
			flag=i;
			q[i]=0;
		}else if(q[i]>n) {
			q[i]=1;
		}else if(q[i]<n) {
			q[i]=-1;
		}
	}
	long long count=0;
	long long qw_l=0;
	for(i=flag-1;i>=0;i--){
		count+=q[i];
		lef[qw_l++]=count;
	}
	lef[qw_l++]=0;
	sort(lef,lef+qw_l);
	count=0;long long qw_r=0;
	for(i=flag+1;i<m;i++){
		count+=q[i];
		righ[qw_r++]=count;
	}
	righ[qw_r++]=0;
	sort(righ,righ+qw_r);
	int ans=0;
	for(i=0;i<qw_l;i++){
		if(binary_search(righ,righ+qw_r,-lef[i])){
			ans+=upper_bound(righ,righ+qw_r,-lef[i])-lower_bound(righ,righ+qw_r,-lef[i]);
		}
		if(binary_search(righ,righ+qw_r,1-lef[i])){
			ans+=upper_bound(righ,righ+qw_r,1-lef[i])-lower_bound(righ,righ+qw_r,1-lef[i]);
		}
	}
	printf("%lld\n",ans);
	return 0;
}


#include<iostream>
#include<algorithm>
#include<stdio.h>
#include<string.h>
#include<cmath>
#include<set>
#define N 200010
using namespace std;
long long i,n,m,flag,q[N],lef[N],righ[N];
long long main()
{
	scanf("%lld%lld",&m,&n);
	for(i=0;i<m;i++){
		scanf("%lld",&q[i]);
		if(n==q[i]) {
			flag=i;
			q[i]=0;
		}else if(q[i]>n) {
			q[i]=1;
		}else if(q[i]<n) {
			q[i]=-1;
		}
	}
	long long count=0;
	long long qw_l=0;
	for(i=flag-1;i>=0;i--){
		count+=q[i];
		lef[qw_l++]=count;
	}
	lef[qw_l++]=0;
	sort(lef,lef+qw_l);
	count=0;long long qw_r=0;
	for(i=flag+1;i<m;i++){
		count+=q[i];
		righ[qw_r++]=count;
	}
	righ[qw_r++]=0;
	sort(righ,righ+qw_r);
	int ans=0;
	for(i=0;i<qw_l;i++){
		if(binary_search(righ,righ+qw_r,-lef[i])){
			ans+=upper_bound(righ,righ+qw_r,-lef[i])-lower_bound(righ,righ+qw_r,-lef[i]);
		}
		if(binary_search(righ,righ+qw_r,1-lef[i])){
			ans+=upper_bound(righ,righ+qw_r,1-lef[i])-lower_bound(righ,righ+qw_r,1-lef[i]);
		}
	}
	printf("%lld\n",ans);
	return 0;
}


#include<bits/stdc++.h>
#define ll long long
#define pb push_back
#define II pair<int, int>
#define x first
#define y second
#define mp make_pair
using namespace std;
const int N = 1e5 + 69;
int n, m, a[N], id;
ll res;
map<int, int> cnt;
int main()
{
//	freopen("1005E.inp", "r", stdin);
//	freopen(".out", "w", stdout);
	ios_base :: sync_with_stdio(0); cin.tie(0); cout.tie(0);
	cin >> n >> m;
	for(int i = 1; i <= n; i ++){
		cin >> a[i];
		if(a[i] == m) id = i;
	}
	int tmp = 0;
	cnt[0] ++;
	for(int i = id - 1; i >= 1; i --){
		if(a[i] < a[id]) tmp ++;
			else tmp --;
		cnt[tmp] ++;
	}
	tmp = 0;
	for(int i = id; i <= n; i ++){
		if(a[i] < a[id]) tmp ++;
			else tmp --;
		res += cnt[- tmp] + cnt[- 1 - tmp];
	}
	cout << res;
}


#include<bits/stdc++.h>
#define ll long long
#define pb push_back
#define II pair<int, int>
#define x first
#define y second
#define mp make_pair
using namespace std;
const int N = 1e5 + 69;
int n, m, a[N], id;
ll res;
map<int, int> cnt;
int main()
{
//	freopen("1005E.inp", "r", stdin);
//	freopen(".out", "w", stdout);
	ios_base :: sync_with_stdio(0); cin.tie(0); cout.tie(0);
	cin >> n >> m;
	for(int i = 1; i <= n; i ++){
		cin >> a[i];
		if(a[i] == m) id = i;
	}
	int tmp = 0;
	cnt[0] ++;
	for(int i = id - 1; i >= 1; i --){
		if(a[i] < a[id]) tmp ++;
			else tmp --;
		cnt[tmp] ++;
	}
	tmp = 0;
	res += cnt[0] + cnt[-1];
	for(int i = id + 1; i <= n; i ++){
		if(a[i] < a[id]) tmp ++;
			else tmp --;
		res += cnt[- tmp] + cnt[- 1 - tmp];
	}
	cout << res;
}


#include<bits/stdc++.h>
#define ll long long
#define pb push_back
#define II pair<int, int>
#define x first
#define y second
#define mp make_pair
using namespace std;
const int N = 2 * 1e5 + 69;
int n, m, a[N], id;
ll res;
map<int, int> cnt;
int main()
{
//	freopen("1005E.inp", "r", stdin);
//	freopen(".out", "w", stdout);
	ios_base :: sync_with_stdio(0); cin.tie(0); cout.tie(0);
	cin >> n >> m;
	for(int i = 1; i <= n; i ++){
		cin >> a[i];
		if(a[i] == m) id = i;
	}
	int tmp = 0;
	cnt[0] ++;
	for(int i = id - 1; i >= 1; i --){
		if(a[i] < a[id]) tmp ++;
			else tmp --;
		cnt[tmp] ++;
	}
	tmp = 0;
	res += cnt[0] + cnt[-1];
	for(int i = id + 1; i <= n; i ++){
		if(a[i] < a[id]) tmp ++;
			else tmp --;
		res += cnt[- tmp] + cnt[- 1 - tmp];
	}
	cout << res;
}


#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <list>
#include <cstdlib>
#include <iterator>
#include <cmath>
#include <iomanip>
#include <bitset>
#include <cctype>
using namespace std;

#define lson (l , mid , rt << 1)
#define rson (mid + 1 , r , rt << 1 | 1)
#define debug(x) cerr << #x << " = " << x << "\n";
#define pb push_back
#define pq priority_queue

#define Pll pair<ll,ll>
#define Pii pair<int,int>

#define fi first
#define se second

#define OKC ios::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define FT(A,B,C) for(int A=B;A <= C;++A)  //用来压行

typedef long long ll;
typedef unsigned long long ull;

const ll mos = 0x7FFFFFFF;  //2147483647
const ll nmos = 0x80000000;  //-2147483648

/*-----------------show time----------------*/
const int maxn = 2e5+9;
int a[maxn],b[maxn],s[maxn];
int n,m;
map<int ,int >q1,q2;
int main(){
    scanf("%d%d", &n, &m);
    int id;
    int le = 2*n+5,ri = -2*n-5;
    for(int i=1; i<=n; i++){
        scanf("%d", &a[i]);
        if(a[i]>m)b[i] = 1;
        else if(a[i]<m) b[i] = -1;
        else b[i] = 0;
        if(a[i]==m)id = i;
    }
    for(int i=id+1; i<=n; i++){//right 2
        s[i] = s[i-1] + b[i];
        if(!q2.count(s[i]))q2[s[i]]=0;
        q2[s[i]]++;
    }
    for(int i=id-1; i>=1; i--){//left 1;
        s[i] = s[i+1] + b[i];
        if(!q1.count(s[i]))q1[s[i]]=0;
        q1[s[i]]++;
        le = min(le,s[i]);
        ri = max(ri,s[i]);
    }
    ll ans = 0ll;
    if(q1.count(0))ans += q1[0];
    if(q2.count(0))ans += q2[0];
    if(q2.count(1))ans += q2[1];
    for(int i=le;i<=ri;i++){
        if(!q1.count(i))continue;
        if(q2.count(-i))ans += 1ll*q1[i] * q2[-i];
        if(q2.count(-i+1))ans += 1ll*q1[i] * q2[-i+1];
    }
    printf("%I64d\n",ans+1);
    return 0;
}
//


#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <list>
#include <cstdlib>
#include <iterator>
#include <cmath>
#include <iomanip>
#include <bitset>
#include <cctype>
using namespace std;

#define lson (l , mid , rt << 1)
#define rson (mid + 1 , r , rt << 1 | 1)
#define debug(x) cerr << #x << " = " << x << "\n";
#define pb push_back
#define pq priority_queue

#define Pll pair<ll,ll>
#define Pii pair<int,int>

#define fi first
#define se second

#define OKC ios::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define FT(A,B,C) for(int A=B;A <= C;++A)  //用来压行

typedef long long ll;
typedef unsigned long long ull;

const ll mos = 0x7FFFFFFF;  //2147483647
const ll nmos = 0x80000000;  //-2147483648

/*-----------------show time----------------*/
const int maxn = 2e5+9;
int a[maxn],b[maxn],s[maxn];
int n,m;
map<int ,int >q1,q2;
int main(){
    scanf("%d%d", &n, &m);
    int id;
    int le = 2*n,ri = -2*n;
    for(int i=1; i<=n; i++){
        scanf("%d", &a[i]);
        if(a[i]>m)b[i] = 1;
        else if(a[i]<m) b[i] = -1;
        else b[i] = 0;
        if(a[i]==m)id = i;
    }
    for(int i=id+1; i<=n; i++){//right 2
        s[i] = s[i-1] + b[i];
        if(!q2.count(s[i]))q2[s[i]]=0;
        q2[s[i]]++;
    }
    for(int i=id-1; i>=1; i--){//left 1;
        s[i] = s[i+1] + b[i];
        if(!q1.count(s[i]))q1[s[i]]=0;
        q1[s[i]]++;
        le = min(le,s[i]);
        ri = max(ri,s[i]);
    }
    ll ans = 0;
    if(q1.count(0))ans += q1[0];
    if(q2.count(0))ans += q2[0];
    if(q2.count(1))ans += q2[1];
    for(int i=le;i<=ri;i++){
        if(!q1.count(i))continue;
        if(q2.count(-i))ans += q1[i] * q2[-i];
        if(q2.count(-i+1))ans += q1[i] * q2[-i+1];
    }
    printf("%I64d\n",ans+1);
    return 0;
}
//


#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <list>
#include <cstdlib>
#include <iterator>
#include <cmath>
#include <iomanip>
#include <bitset>
#include <cctype>
using namespace std;

#define lson (l , mid , rt << 1)
#define rson (mid + 1 , r , rt << 1 | 1)
#define debug(x) cerr << #x << " = " << x << "\n";
#define pb push_back
#define pq priority_queue

#define Pll pair<ll,ll>
#define Pii pair<int,int>

#define fi first
#define se second

#define OKC ios::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define FT(A,B,C) for(int A=B;A <= C;++A)  //用来压行
#define REP(i , j , k)  for(int i = j ; i <  k ; ++i)
typedef long long ll;
typedef unsigned long long ull;

const ll mos = 0x7FFFFFFF;  //2147483647
const ll nmos = 0x80000000;  //-2147483648

template<typename T>
inline T read(T&x){
    x=0;int f=0;char ch=getchar();
    while (ch<'0'||ch>'9') f|=(ch=='-'),ch=getchar();
    while (ch>='0'&&ch<='9') x=x*10+ch-'0',ch=getchar();
    return x=f?-x:x;
}
/*-----------------show time----------------*/
map<int,int >c;
int n,m,sum;
ll ans = 0;
int main(){
    scanf("%d%d", &n, &m);
    int flag = 0;
    c[0] = 1;
    for(int i=1; i<=n; i++){
        int x;
        scanf("%d", &x);

        if(x==m){
            flag = 1;
        }
        else if(x > m)sum++;
        else if(x < m)sum--;

        if(flag){
            if(c.count(sum))ans += c[sum];
            if(c.count(sum-1))ans += c[sum-1];
        }
        else {
            if(!c.count(sum))c[sum] = 0;
            c[sum] ++;
        }
    }
    printf("%I64d\n",ans);

    return 0;
}


#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <list>
#include <cstdlib>
#include <iterator>
#include <cmath>
#include <iomanip>
#include <bitset>
#include <cctype>
using namespace std;

#define lson (l , mid , rt << 1)
#define rson (mid + 1 , r , rt << 1 | 1)
#define debug(x) cerr << #x << " = " << x << "\n";
#define pb push_back
#define pq priority_queue

#define Pll pair<ll,ll>
#define Pii pair<int,int>

#define fi first
#define se second

#define OKC ios::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define FT(A,B,C) for(int A=B;A <= C;++A)  //用来压行

typedef long long ll;
typedef unsigned long long ull;

const ll mos = 0x7FFFFFFF;  //2147483647
const ll nmos = 0x80000000;  //-2147483648

/*-----------------show time----------------*/
const int maxn = 2e5+9;
int a[maxn],b[maxn],s[maxn];
int n,m;
map<int ,int >q1,q2;
int main(){
    scanf("%d%d", &n, &m);
    int id;
    int le = 2*n,ri = -2*n;
    for(int i=1; i<=n; i++){
        scanf("%d", &a[i]);
        if(a[i]>m)b[i] = 1;
        else if(a[i]<m) b[i] = -1;
        else b[i] = 0;
        if(a[i]==m)id = i;
    }
    for(int i=id+1; i<=n; i++){//right 2
        s[i] = s[i-1] + b[i];
        if(!q2.count(s[i]))q2[s[i]]=0;
        q2[s[i]]++;
    }
    for(int i=id-1; i>=1; i--){//left 1;
        s[i] = s[i+1] + b[i];
        if(!q1.count(s[i]))q1[s[i]]=0;
        q1[s[i]]++;
        le = min(le,s[i]);
        ri = max(ri,s[i]);
    }
    ll ans = 0ll;
    if(q1.count(0))ans += q1[0];
    if(q2.count(0))ans += q2[0];
    if(q2.count(1))ans += q2[1];
    for(int i=le;i<=ri;i++){
        if(!q1.count(i))continue;
        if(q2.count(-i))ans += 1ll*q1[i] * q2[-i];
        if(q2.count(-i+1))ans += 1ll*q1[i] * q2[-i+1];
    }
    printf("%I64d\n",ans+1);
    return 0;
}
//


#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <list>
#include <cstdlib>
#include <iterator>
#include <cmath>
#include <iomanip>
#include <bitset>
#include <cctype>
using namespace std;

#define lson (l , mid , rt << 1)
#define rson (mid + 1 , r , rt << 1 | 1)
#define debug(x) cerr << #x << " = " << x << "\n";
#define pb push_back
#define pq priority_queue

#define Pll pair<ll,ll>
#define Pii pair<int,int>

#define fi first
#define se second

#define OKC ios::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define FT(A,B,C) for(int A=B;A <= C;++A)  //用来压行

typedef long long ll;
typedef unsigned long long ull;

const ll mos = 0x7FFFFFFF;  //2147483647
const ll nmos = 0x80000000;  //-2147483648

/*-----------------show time----------------*/
const int maxn = 2e5+9;
int a[maxn],b[maxn],s[maxn];
int n,m;
map<int ,int >q1,q2;
int main(){
    scanf("%d%d", &n, &m);
    int id;
    int le = 2*n+5,ri = -2*n-5;
    int le2 = 2*n+5,ri2 = -2*n-5;
    for(int i=1; i<=n; i++){
        scanf("%d", &a[i]);
        if(a[i]>m)b[i] = 1;
        else if(a[i]<m) b[i] = -1;
        else b[i] = 0;
        if(a[i]==m)id = i;
    }
    for(int i=id+1; i<=n; i++){//right 2
        s[i] = s[i-1] + b[i];
        if(!q2.count(s[i]))q2[s[i]]=0;
        q2[s[i]]++;
        le2 = min(le2,s[i]);
        ri2 = max(ri2,s[i]);
    }
    for(int i=id-1; i>=1; i--){//left 1;
        s[i] = s[i+1] + b[i];
        if(!q1.count(s[i]))q1[s[i]]=0;
        q1[s[i]]++;
        le = min(le,s[i]);
        ri = max(ri,s[i]);
    }
    ll ans = 0ll;
        if(q1.count(0))ans += q1[0];
        if(q1.count(1))ans += q1[1];
        if(q2.count(0))ans += q2[0];
        if(q2.count(1))ans += q2[1];
        for(int i=le;i<=ri;i++){
            if(!q1.count(i))continue;
            if(q2.count(-i))ans += 1ll*q1[i] * q2[-i];
            if(q2.count(-i+1))ans += 1ll*q1[i] * q2[-i+1];
        }
        for(int i=le2;i<=ri2;i++){
            if(!q2.count(i))continue;
            if(q1.count(-i))ans += 1ll*q1[i] * q2[-i];
            if(q1.count(-i+1))ans += 1ll*q1[i] * q2[-i+1];
        }

    printf("%I64d\n",ans+1);
    return 0;
}
//


#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <list>
#include <cstdlib>
#include <iterator>
#include <cmath>
#include <iomanip>
#include <bitset>
#include <cctype>
using namespace std;

#define lson (l , mid , rt << 1)
#define rson (mid + 1 , r , rt << 1 | 1)
#define debug(x) cerr << #x << " = " << x << "\n";
#define pb push_back
#define pq priority_queue

#define Pll pair<ll,ll>
#define Pii pair<int,int>

#define fi first
#define se second

#define OKC ios::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define FT(A,B,C) for(int A=B;A <= C;++A)  //用来压行

typedef long long ll;
typedef unsigned long long ull;

const ll mos = 0x7FFFFFFF;  //2147483647
const ll nmos = 0x80000000;  //-2147483648

/*-----------------show time----------------*/
const int maxn = 2e5+9;
int a[maxn],b[maxn],s[maxn];
int n,m;
map<int ,int >q1,q2;
int main(){
    scanf("%d%d", &n, &m);
    int id;
    int le = 2*n+5,ri = -2*n-5;
    for(int i=1; i<=n; i++){
        scanf("%d", &a[i]);
        if(a[i]>m)b[i] = 1;
        else if(a[i]<m) b[i] = -1;
        else b[i] = 0;
        if(a[i]==m)id = i;
    }
    for(int i=id+1; i<=n; i++){//right 2
        s[i] = s[i-1] + b[i];
        if(!q2.count(s[i]))q2[s[i]]=0;
        q2[s[i]]++;
    }
    for(int i=id-1; i>=1; i--){//left 1;
        s[i] = s[i+1] + b[i];
        if(!q1.count(s[i]))q1[s[i]]=0;
        q1[s[i]]++;
        le = min(le,s[i]);
        ri = max(ri,s[i]);
    }
    ll ans = 0ll;
    if(id!=1){
        if(q1.count(0))ans += q1[0];
        if(q2.count(0))ans += q2[0];
        if(q2.count(1))ans += q2[1];
        for(int i=le;i<=ri;i++){
            if(!q1.count(i))continue;
            if(q2.count(-i))ans += 1ll*q1[i] * q2[-i];
            if(q2.count(-i+1))ans += 1ll*q1[i] * q2[-i+1];
        }
    }
    else{
        if(q2.count(0))ans += q2[0];
        if(q2.count(1))ans += q2[1];
    }
    printf("%I64d\n",ans+1);
    return 0;
}
//


#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <list>
#include <cstdlib>
#include <iterator>
#include <cmath>
#include <iomanip>
#include <bitset>
#include <cctype>
using namespace std;

#define lson (l , mid , rt << 1)
#define rson (mid + 1 , r , rt << 1 | 1)
#define debug(x) cerr << #x << " = " << x << "\n";
#define pb push_back
#define pq priority_queue

#define Pll pair<ll,ll>
#define Pii pair<int,int>

#define fi first
#define se second

#define OKC ios::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define FT(A,B,C) for(int A=B;A <= C;++A)  //用来压行

typedef long long ll;
typedef unsigned long long ull;

const ll mos = 0x7FFFFFFF;  //2147483647
const ll nmos = 0x80000000;  //-2147483648

/*-----------------show time----------------*/
const int maxn = 2e5+9;
int a[maxn],b[maxn],s[maxn];
int n,m;
map<int ,int >q1,q2;
int main(){
    scanf("%d%d", &n, &m);
    int id;
    int le = 2*n+5,ri = -2*n-5;
    int le2 = 2*n+5,ri2 = -2*n-5;
    for(int i=1; i<=n; i++){
        scanf("%d", &a[i]);
        if(a[i]>m)b[i] = 1;
        else if(a[i]<m) b[i] = -1;
        else b[i] = 0;
        if(a[i]==m)id = i;
    }
    for(int i=id+1; i<=n; i++){//right 2
        s[i] = s[i-1] + b[i];
        if(!q2.count(s[i]))q2[s[i]]=0;
        q2[s[i]]++;
        le2 = min(le2,s[i]);
        ri2 = max(ri2,s[i]);
    }
    for(int i=id-1; i>=1; i--){//left 1;
        s[i] = s[i+1] + b[i];
        if(!q1.count(s[i]))q1[s[i]]=0;
        q1[s[i]]++;
        le = min(le,s[i]);
        ri = max(ri,s[i]);
    }
    ll ans = 0ll;
        if(q1.count(0))ans += q1[0];
        if(q1.count(1))ans += q1[1];
        if(q2.count(0))ans += q2[0];
        if(q2.count(1))ans += q2[1];
        for(int i=le;i<=ri;i++){
            if(!q1.count(i))continue;
            if(q2.count(-i))ans += 1ll*q1[i] * q2[-i];
            if(q2.count(-i+1))ans += 1ll*q1[i] * q2[-i+1];
        }

    printf("%I64d\n",ans+1);
    return 0;
}
//


#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

const int INF = 1234567899;
const double EPS = 1e-6;

const int MAXN = 2e5 + 5;

int n, m;
int a[MAXN];
ll t[2 * MAXN];

ll get(int p) {
	ll ret = 0;
	while (p > 0) ret += t[p], p -= p & -p;
	return ret;
}

void upd(int p, int q) {
	while (p <= q) t[p]++, p += p & -p;
}

int solve(int p) {
	memset(t, 0, sizeof t);
	ll ret = 0;
	int c = n + 2;
	upd(c, 2 * n + 3);

	for (int i = 0; i < n; ++i) {
		if (a[i] < p) c--;
		else c++;
		ret += get(c - 1);
		upd(c, 2 * n + 3);
	}

	return ret;
}

int main() {
	ios::sync_with_stdio(0); cout << fixed << setprecision(6);

	cin >> n >> m;

	for (int i = 0; i < n; ++i) {
		cin >> a[i];
	}

	cout << solve(m) - solve(m + 1) << endl;

	return 0;
}


#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

const int INF = 1234567899;
const double EPS = 1e-6;

const int MAXN = 2e5 + 5;

int a[MAXN];
int g[MAXN];
int s[MAXN];

int main() {
	ios::sync_with_stdio(0); cout << fixed << setprecision(6);

	int n, m; cin >> n >> m;

	int p = 0;

	for (int i = 1; i <= n; ++i) {
		cin >> a[i];
		if (a[i] == m) {
			p = i;
		}
	}

	for (int i = 1; i <= n; ++i) {
		g[i] += g[i - 1];
		s[i] += s[i - 1];

		if (a[i] > m) {
			g[i]++;
		} else if (a[i] < m) {
			s[i]++;
		}
	}

	int ans = 1;

	for (int i = 2; i <= n; ++i) {
		int medp = i / 2;
		int d = (i - 1) / 2;
		int le = d;
		int ri = d + (i % 2 == 0);

		for (int j = max(0, p - i + 1); j + i - 1 <= n; j++) {
			int b = j;
			int e = j + i - 1;

			int gr = g[e] - g[b - 1];
			int sm = s[e] - s[b - 1];

			if (le == sm && ri == gr) ++ans;
		}
	}

	cout << ans << endl;

	return 0;
}


#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

const int INF = 1234567899;
const double EPS = 1e-6;

const int MAXN = 2e5 + 5;

int n, m;
int a[MAXN];
ll t[2 * MAXN];

ll get(int p) {
	ll ret = 0;
	while (p > 0) ret += t[p], p -= p & -p;
	return ret;
}

void upd(int p, int q) {
	while (p <= q) t[p]++, p += p & -p;
}

ll solve(int p) {
	memset(t, 0, sizeof t);
	ll ret = 0;
	int c = n + 2;
	upd(c, 2 * n + 3);

	for (int i = 0; i < n; ++i) {
		if (a[i] < p) c--;
		else c++;
		ret += get(c - 1);
		upd(c, 2 * n + 3);
	}

	return ret;
}

int main() {
	ios::sync_with_stdio(0); cout << fixed << setprecision(6);

	cin >> n >> m;

	for (int i = 0; i < n; ++i) {
		cin >> a[i];
	}

	cout << solve(m) - solve(m + 1) << endl;

	return 0;
}


#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

const int INF = 1234567899;
const double EPS = 1e-6;

const int MAXN = 2e5 + 1;

ll a[MAXN];
ll g[MAXN];
ll s[MAXN];

int main() {
	ll n, m; scanf("%lld %lld", &n, &m);

	ll p = 0;

	for (ll i = 1; i <= n; ++i) {
		scanf("%lld", &a[i]);
		if (a[i] == m) {
			p = i;
		}
	}

	for (ll i = 1; i <= n; ++i) {
		g[i] += g[i - 1];
		s[i] += s[i - 1];

		if (a[i] > m) {
			g[i]++;
		} else if (a[i] < m) {
			s[i]++;
		}
	}

	ll ans = 1;

	for (ll i = 2; i <= n; ++i) {
		ll medp = i / 2;
		ll d = (i - 1) / 2;
		ll le = d;
		ll ri = d + (i % 2 == 0);

		for (ll j = max(0LL, p - i + 1); j + i - 1 <= n && j + i - 1 <= p + i - 1; j++) {
			ll b = j;
			ll e = j + i - 1;

			ll gr = g[e] - g[b - 1];
			ll sm = s[e] - s[b - 1];

			if (le == sm && ri == gr) ++ans;
		}
	}

	printf("%lld\n", ans);

	return 0;
}


#include <iostream>
#include <cstdio>
#include <map>
using namespace std;

int main() {
	int n, m;
	map<int, int> c;
	int sum = 0;
	cin >> n >> m;
	int pi;
	bool flag = false;
	map<int, int>::iterator it;
	int ans = 0;
	c[0] = 1;
	c[1] = 0;
	for (int i = 0; i < n; i++) {
		scanf("%d", &pi);
		if (pi < m) sum++;
		if (pi > m) sum--;
		if (pi == m) {
			flag = true;
		}
		if (!flag) {
			it = c.find(sum);
			if (it != c.end()) {
				c[sum]++;
			} else {
				c[sum] = 1;
			}
		}

		if (flag) {
			it = c.find(sum);
			if (it != c.end()) {
				ans += c[sum];
			}
			it = c.find(sum + 1);
			if (it != c.end()) {
				ans += c[sum];
			}
		}
	}
	cout << ans << endl;
	return 0;
}


#include <iostream>
#include <cstdio>
#include <map>
using namespace std;

int main() {
	int n, m;
	map<int, int> c;
	int sum = 0;
	cin >> n >> m;
	int pi;
	bool flag = false;
	map<int, int>::iterator it;
	long long int ans = 0;
	c[0] = 1;
	for (int i = 0; i < n; i++) {
		scanf("%d", &pi);
		if (pi < m) sum++;
		if (pi > m) sum--;
		if (pi == m) {
			flag = true;
		}
		if (!flag) {
			it = c.find(sum);
			if (it != c.end()) {
				c[sum]++;
			} else {
				c[sum] = 1;
			}
		}

		if (flag) {
			it = c.find(sum);
			if (it != c.end()) {
				ans += c[sum];
			}
			it = c.find(sum + 1);
			if (it != c.end()) {
				ans += c[sum+1];
			}
		}
	}
	cout << ans << endl;
	return 0;
}


#include <iostream>
#include <cstdio>
#include <map>
using namespace std;

int main() {
	int n, m;
	map<int, int> c;
	int sum = 0;
	cin >> n >> m;
	int pi;
	bool flag = false;
	map<int, int>::iterator it;
	int ans = 0;
	c[0] = 1;
	for (int i = 0; i < n; i++) {
		scanf("%d", &pi);
		if (pi < m) sum++;
		if (pi > m) sum--;
		if (pi == m) {
			flag = true;
		}
		if (!flag) {
			it = c.find(sum);
			if (it != c.end()) {
				c[sum]++;
			} else {
				c[sum] = 1;
			}
		}

		if (flag) {
			it = c.find(sum);
			if (it != c.end()) {
				ans += c[sum];
			}
			it = c.find(sum + 1);
			if (it != c.end()) {
				ans += c[sum+1];
			}
		}
	}
	cout << ans << endl;
	return 0;
}


#include <bits/stdc++.h>
using namespace std;

const int N  = 2e5 + 10;
int n, m, pos, ans = 0;
int a[N], cnt[N << 1];
int main() {
    scanf("%d%d", &n, &m);
    for (int i = 1; i <= n; i++) {
        scanf("%d", a + i);
        if (a[i] == m) pos = i;
    }
    for (int i = pos, l = 0, r = 0; i >= 1; i--) {
        if (m < a[i]) r++;
        if (m > a[i]) l++;
        cnt[r - l + N]++;
    }
    for (int i = pos, l = 0, r = 0; i <= n; i++) {
        if (m < a[i]) r++;
        if (m > a[i]) l++;
        ans += cnt[l - r + N];
        if ((l + r) & 1) ans += cnt[l - r + 1 + N];
    }
    cout<<ans<<endl;
}


#include <bits/stdc++.h>
using namespace std;

const int N  = 2e5 + 10;
int n, m, pos;
long long ans = 0;
int a[N], cnt[N << 1];
int main() {
    scanf("%d%d", &n, &m);
    for (int i = 1; i <= n; i++) {
        scanf("%d", a + i);
        if (a[i] == m) pos = i;
    }
    for (int i = pos, l = 0, r = 0; i >= 1; i--) {
        if (m < a[i]) r++;
        if (m > a[i]) l++;
        cnt[r - l + N]++;
    }
    for (int i = pos, l = 0, r = 0; i <= n; i++) {
        if (m < a[i]) r++;
        if (m > a[i]) l++;
        ans += cnt[l - r + N];
        ans += cnt[l - r + 1 + N];
    }
    cout<<ans<<endl;
}


#include <bits/stdc++.h>
using namespace std;

const int N  = 2e5 + 10;
int n, m, pos, ans = 0;
int a[N], cnt[N << 1];
int main() {
    scanf("%d%d", &n, &m);
    for (int i = 1; i <= n; i++) {
        scanf("%d", a + i);
        if (a[i] == m) pos = i;
    }
    for (int i = pos, l = 0, r = 0; i >= 1; i--) {
        if (m < a[i]) r++;
        if (m > a[i]) l++;
        cnt[r - l + N]++;
    }
    for (int i = pos, l = 0, r = 0; i <= n; i++) {
        if (m < a[i]) r++;
        if (m > a[i]) l++;
        ans += cnt[l - r + N];
        ans += cnt[l - r + 1 + N];
    }
    cout<<ans<<endl;
}


#include <bits/stdc++.h>
using namespace std;
const int maxn=200007;
int a[200007];
int lgao[maxn],ldi[maxn];
int main(){
	int n,m;
	scanf("%d%d",&n,&m);
	int pos=0;
	for(int i=1;i<=n;i++){
		scanf("%d",&a[i]);
		if(a[i]==m) pos=i;
	}
	int ans=0;
	int cnt=0;
	for(int i=pos;i>=1;i--){
		if(a[i]<m) cnt--;
		else if(a[i]>m)cnt++;
		if(cnt>0) lgao[cnt]++;
		else if(cnt<0) ldi[-cnt]++;
		else lgao[0]++,ldi[0]++;
	}
	cnt=0;
	for(int i=pos;i<=n;i++){
		if(a[i]<m) cnt--;
		else if(a[i]>m)cnt++;
		if(cnt>0){
			ans+=ldi[cnt];
			ans+=ldi[cnt-1];
		}
		else if(cnt<0) ans+=lgao[-cnt],ans+=lgao[-cnt+1];
		else{
			ans+=lgao[0];
			ans+=lgao[1];
		}
	}
	cout<<ans<<endl;
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
const int maxn=200007;
int a[200007];
int lgao[maxn],ldi[maxn];
int main(){
	int n,m;
	scanf("%d%d",&n,&m);
	int pos=0;
	for(int i=1;i<=n;i++){
		scanf("%d",&a[i]);
		if(a[i]==m) pos=i;
	}
	long long ans=0;
	int cnt=0;
	for(int i=pos;i>=1;i--){
		if(a[i]<m) cnt--;
		else if(a[i]>m)cnt++;
		if(cnt>0) lgao[cnt]++;
		else if(cnt<0) ldi[-cnt]++;
		else lgao[0]++,ldi[0]++;
	}
	cnt=0;
	for(int i=pos;i<=n;i++){
		if(a[i]<m) cnt--;
		else if(a[i]>m)cnt++;
		if(cnt>0){
			ans+=ldi[cnt];
			ans+=ldi[cnt-1];
		}
		else if(cnt<0) ans+=lgao[-cnt],ans+=lgao[-cnt+1];
		else{
			ans+=lgao[0];
			ans+=lgao[1];
		}
	}
	cout<<ans<<endl;
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
const int maxn=200007;
int a[200007];
int lgao[maxn],ldi[maxn];
int main(){
	int n,m;
	scanf("%d%d",&n,&m);
	int pos=0;
	for(int i=1;i<=n;i++){
		scanf("%d",&a[i]);
		if(a[i]==m) pos=i;
	}
	int ans=0;
	int cnt=0;
	for(int i=pos;i>=1;i--){
		if(a[i]<m) cnt--;
		else if(a[i]>m)cnt++;
		if(cnt>0) lgao[cnt]++;
		else if(cnt<0) ldi[-cnt]++;
		else lgao[0]++,ldi[0]++;
	}
	cnt=0;
	for(int i=pos;i<=n;i++){
		if(a[i]<m) cnt--;
		else if(a[i]>m)cnt++;
		if(cnt>0){
			ans+=ldi[cnt];
			if(cnt==1) ans+=ldi[0];
		}
		else if(cnt<0) ans+=lgao[-cnt];
		else{
			ans+=lgao[0];
			ans+=lgao[1];
		}
	}
	cout<<ans<<endl;
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
const int maxn=200007;
int a[200007];
int lgao[maxn],ldi[maxn],rgao[maxn],rdi[maxn];
int main(){
	int n,m;
	scanf("%d%d",&n,&m);
	int pos=0;
	for(int i=1;i<=n;i++){
		scanf("%d",&a[i]);
		if(a[i]==m) pos=i;
	}
	int ans=0;
	int cnt=0;
	for(int i=pos;i>=1;i--){
		if(a[i]<m) cnt--;
		else if(a[i]>m)cnt++;
		if(cnt>0) lgao[cnt]++;
		else if(cnt<0) ldi[-cnt]++;
		else lgao[0]++,ldi[0]++;
	}
	cnt=0;
	for(int i=pos;i<=n;i++){
		if(a[i]<m) cnt--;
		else if(a[i]>m)cnt++;
		if(cnt>0){
			ans+=ldi[cnt];
			if(cnt==1) ans+=ldi[0];
		}
		else if(cnt<0) ans+=lgao[-cnt];
		else ans+=lgao[0];
	}
	cout<<ans<<endl;
	return 0;
}


#include <iostream>
#include <stdio.h>
#include <math.h>
const int maxn=2e5;
using namespace std;
long long p[200005],s[200005],d[400005];
long long n,m,vt,kq;
void nhap()
{
    ios_base::sync_with_stdio(0);
    //freopen("A.INP","r",stdin);
    //freopen("A.OUT","w",stdout);
    cin >> n >> m;
    for (int i=1;i <= n;++i)
    {
        cin >> p[i];
        if (p[i]==m)vt=i;
    }
}
void xl()
{
    s[vt]=0;
    for (int i=vt-1;i >= 1;--i)
        if (p[i] < p[vt])s[i]=-1;
    else s[i]=1;
    ++d[maxn];
    for (int i=vt-1;i >= 1;--i)
    {
        s[i]=s[i+1]+s[i];
        ++d[s[i]+maxn];
    }
    for (int i=vt+1;i <= n;++i)
        if (p[i] < p[vt])s[i]=-1;
    else s[i]=1;
    for (int i=vt+1;i <= n;++i)
    {
        s[i]=s[i-1]+s[i];
        kq+=d[s[i]*-1+maxn];
        kq+=d[s[i]*-1+maxn+1];
    }
    kq+=d[1+maxn];
    kq+=d[maxn];
    cout << kq;
}
int main()
{
    nhap();
    xl();
    return 0;
}


#include <iostream>
#include <stdio.h>
#include <math.h>
const int maxn=2e5;
using namespace std;
int p[200005],s[200005],d[400005];
int n,m,vt,kq;
void nhap()
{
    ios_base::sync_with_stdio(0);
    //freopen("A.INP","r",stdin);
    //freopen("A.OUT","w",stdout);
    cin >> n >> m;
    for (int i=1;i <= n;++i)
    {
        cin >> p[i];
        if (p[i]==m)vt=i;
    }
}
void xl()
{
    s[vt]=0;
    for (int i=vt-1;i >= 1;--i)
        if (p[i] < p[vt])s[i]=-1;
    else s[i]=1;
    ++d[maxn];
    for (int i=vt-1;i >= 1;--i)
    {
        s[i]=s[i+1]+s[i];
        ++d[s[i]+maxn];
    }
    for (int i=vt+1;i <= n;++i)
        if (p[i] < p[vt])s[i]=-1;
    else s[i]=1;
    for (int i=vt+1;i <= n;++i)
    {
        s[i]=s[i-1]+s[i];
        kq+=d[s[i]*-1+maxn];
        if (s[i] != 0)kq+=d[s[i]*-1+maxn+1];
    }
    kq+=d[maxn];
    cout << kq;
}
int main()
{
    nhap();
    xl();
    return 0;
}


#include <iostream>
#include <stdio.h>
#include <math.h>
const int maxn=2e5;
using namespace std;
int p[200005],s[200005],d[400005];
int n,m,vt,kq;
void nhap()
{
    ios_base::sync_with_stdio(0);
    //freopen("A.INP","r",stdin);
    //freopen("A.OUT","w",stdout);
    cin >> n >> m;
    for (int i=1;i <= n;++i)
    {
        cin >> p[i];
        if (p[i]==m)vt=i;
    }
}
void xl()
{
    s[vt]=0;
    for (int i=vt-1;i >= 1;--i)
        if (p[i] < p[vt])s[i]=-1;
    else s[i]=1;
    ++d[maxn];
    for (int i=vt-1;i >= 1;--i)
    {
        s[i]=s[i+1]+s[i];
        ++d[s[i]+maxn];
    }
    for (int i=vt+1;i <= n;++i)
        if (p[i] < p[vt])s[i]=-1;
    else s[i]=1;
    for (int i=vt+1;i <= n;++i)
    {
        s[i]=s[i-1]+s[i];
        kq+=d[s[i]*-1+maxn];
        kq+=d[s[i]*-1+maxn+1];
    }
    kq+=d[maxn];
    cout << kq;
}
int main()
{
    nhap();
    xl();
    return 0;
}


#include <iostream>
#include <stdio.h>
#include <math.h>
const int maxn=2e5;
using namespace std;
int p[200005],s[200005],d[400005];
int n,m,vt,kq;
void nhap()
{
    ios_base::sync_with_stdio(0);
    //freopen("A.INP","r",stdin);
    //freopen("A.OUT","w",stdout);
    cin >> n >> m;
    for (int i=1;i <= n;++i)
    {
        cin >> p[i];
        if (p[i]==m)vt=i;
    }
}
void xl()
{
    s[vt]=0;
    for (int i=vt-1;i >= 1;--i)
        if (p[i] < p[vt])s[i]=-1;
    else s[i]=1;
    ++d[maxn];
    for (int i=vt-1;i >= 1;--i)
    {
        s[i]=s[i+1]+s[i];
        ++d[s[i]+maxn];
    }
    for (int i=vt+1;i <= n;++i)
        if (p[i] < p[vt])s[i]=-1;
    else s[i]=1;
    for (int i=vt+1;i <= n;++i)
    {
        s[i]=s[i-1]+s[i];
        kq+=d[s[i]*-1+maxn];
        kq+=d[s[i]*-1+maxn+1];
    }
    kq+=d[1+maxn];
    kq+=d[maxn];
    cout << kq;
}
int main()
{
    nhap();
    xl();
    return 0;
}


//
//  E1 - Median on Segments (Permutations Edition).cpp
//  CF
//  谢谢大佬们分享思路
//  Created by Terry on 2018/7/11.
//  Copyright ? 2018年 Terry. All rights reserved.
//
//  n个数字 不重复 给你一个m
//  然后问你有多少个区间的中位数是m
//  奇数区间选中间那个
//  偶数区间选中间偏左那个
//  因为是一个区间
//  肯定包含m这个数字
//  然后我们从m右边开始 记录从m到右边的每个数字这段区间比他大小的数字有多少个 用map记录一下
//  比如说
//  5 4
//  2 4 5 3 1
//  则
//  从4开始
//  2 4             5           3           1
//    mp[0] = 1    mp[1] = 1    mp[0] = 2   mp[-1] = 1;
// 4:mp[0] = 1   从4到4这个区间比4大的数或者小的数一共有0个
// 5:mp[1] = 1   从4到5这个区间比4大的数有一个 则 mp[1] = 1  然后我们就可以从左边去匹配啦
// 3:mp[0] = 2   从4到3这个区间 比4大的数有一个 比4小的数有一个 所以mp[0]++ mp[0]=2
// 1:mp[-1] = 1  从4到1这个区间 比4大的有一个 比4小的有一个 所以mp[-1] = 1 因为我们不是要去凑中位数嘛

// 然后去从4开始去找左边 然后去匹配右边的map
// 4的话  4到4 比4大小的数一共有0个 则 ans += mp[0] ans = 2
//        mp[0] = 2  [4,4] [4,5,3]
//       然后ans += mp[1] 因为还有区间的个数是偶数的情况 偶数的意思就是 比m大的数比 比m小的数 多1
//          ans = 3
// 2     4到2 比4小的数有一个
//      ans += mp[- * -1] = mp[1]  因为左边比4小的数有一个 所以去4的右边找一个从4开始的区间比4大的数字只有一个的区间  ans = 4
//      然后去考虑偶数
//      ans += mp[-1*-1 + 1] = mp[2]
//      ans = 4
#include <stdio.h>
#include <map>
using namespace std;
typedef long long ll;
int n, m;
const int maxn = 2e5 + 5;
map<int, int>mp;
int pos, a[maxn];
int main() {
    scanf("%d%d", &n, &m);
    for(int i = 1; i <= n; i++)
	{
        scanf("%d", &a[i]);
        if(a[i] == m) pos = i;
    }
    int cnt = 0;
    for(int i = pos; i <= n; i++)
	{
        if(a[i] > m) cnt++;
        else if(a[i] < m) cnt--;
        mp[cnt]++;//记录右边比m大小的情况  从pos 到 i 这一段比m大小的情况
    }
    ll  ans = 0;
    cnt=0;
    for(int i = pos; i >= 1; i--)
	{
        if(a[i] > m) cnt++;
        else if(a[i] < m) cnt--;
        ans += mp[-cnt];//奇数取最中间
        ans += mp[-cnt + 1];//偶数去中间靠左的
    }
    printf("%lld\n", ans);//注意会爆int
    return 0;
}


#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <queue>
#include <stack>
#include <math.h>
#include <map>
using namespace std;
int a[200005],b[200005];
map<int,int> mp;
int main()
{
	int n,m;
	while(~scanf("%d %d",&n,&m))
	{
		int j=0;
		for(int i=1;i<=n;i++)
		{
			scanf("%d",&a[i]);
			if(a[i]==m)
			j=i;
		}
		int num=0;
		for(int i=j;i>0;i--)
		{
			if(m<a[i])
			{
				num--;
				mp[i]=num;
			}
			else if(m>a[i])
			{
				num++;
				mp[i]=num;
			}
		}
		num=0;
		for(int i=j+1;i<=n;i++)
		{
			if(m<a[i])
			{
				num--;
				mp[i]=num;
			}
			else if(m>a[i])
			{
				num++;
				mp[i]=num;
			}
		}
		mp[j]=0;
		int sum=0;
		for(int i=j;i>=1;i--)
		{
			for(int k=j;k<=n;k++)
			{
				if(mp[k]+mp[i]==-1||mp[k]+mp[i]==0)
				sum++;
			}
		}
		printf("%d\n",sum);
	}
}


#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <queue>
#include <stack>
#include <math.h>
using namespace std;
int a[200005],b[200005],vis[400010];
int main()
{
	int n,m;
	while(~scanf("%d %d",&n,&m))
	{
		memset(vis,-1,sizeof(vis));
		int j=0;
		for(int i=1;i<=n;i++)
		{
			scanf("%d",&a[i]);
			if(a[i]==m)
			j=i;
		}
		int num=0;
		for(int i=j-1;i>0;i--)
		{
			if(m<a[i])
			{
				num--;
				b[i]=num;
			}
			else if(m>a[i])
			{
				num++;
				b[i]=num;
			}
		}
		num=0;
		for(int i=j+1;i<=n;i++)
		{
			if(m<a[i])
			{
				num--;
				b[i]=num;
			}
			else if(m>a[i])
			{
				num++;
				b[i]=num;
			}
		}
		b[j]=0;
		int sum=0;
		num=0;
		for(int i=j;i>=1;i--)
		{
			if(vis[b[i]+200005]!=-1)
			{
				num+=vis[b[i]+200005];
				continue;
			}
			for(int k=j;k<=n;k++)
			{
				if(b[k]+b[i]==-1||b[k]+b[i]==0)
				{
					sum++;
				}
			}
			vis[b[i]+200005]=sum;
			num+=sum;
			sum=0;
		}
		printf("%d\n",num);
	}
}


#include <bits/stdc++.h>
using namespace std;

//#define USACO
#define ll long long
#define x first
#define y second
#define all(x) (x).begin(), (x).end()
#define fill(x, y) memset(x, y, sizeof(x))
#define out_range_map(x,y) ((x) < 0 || (y) < 0 || (i) == N || (j) == M)
#define optimizar_io ios_base::sync_with_stdio(false);cin.tie(NULL);
//streambuf *cin_backup = cin.rdbuf(), *cout_backup = cout.rdbuf();
#ifdef USACO
ifstream f_in("case.in");
ofstream f_out("case.out");
#endif // USACO

const ll LN = (ll)2e5 + 10, LK = 10, INF = (ll)(1e18), MOD = (ll)(1e9) + 7;
int N, K, num[LN], sum[2 * LN], cont, ans;
int *bucket = &sum[LN];

int main()
{

	optimizar_io

		cin >> N >> K;

	for (int i = 0; i < N; i++)
		cin >> num[i];

	for (int i = 0; i < N; i++)
	{
		if (num[i] == K)
		{
			int cont = 0;
			for (int j = i; j >= 0; j--)
			{
				if (num[j] > num[i])
					cont--;
				if (num[j] < num[i])
					cont++;
				bucket[cont]++;
			}
			cont = 0;
			for (int j = i; j < N; j++)
			{
				if (num[j] > num[i])
					cont--;
				if (num[j] < num[i])
					cont++;
				ans += bucket[cont*-1] + bucket[cont*-1 - 1];
			}
		}
	}

	cout << ans;

	return 0;
}


#include <bits/stdc++.h>
using namespace std;

//#define USACO
#define ll long long
#define x first
#define y second
#define all(x) (x).begin(), (x).end()
#define fill(x, y) memset(x, y, sizeof(x))
#define out_range_map(x,y) ((x) < 0 || (y) < 0 || (i) == N || (j) == M)
#define optimizar_io ios_base::sync_with_stdio(false);cin.tie(NULL);
//streambuf *cin_backup = cin.rdbuf(), *cout_backup = cout.rdbuf();
#ifdef USACO
ifstream f_in("case.in");
ofstream f_out("case.out");
#endif // USACO

const ll LN = (ll)2e5 + 100, LK = 10, INF = (ll)(1e18), MOD = (ll)(1e9) + 7;
int N, K, num[LN], sum[2 * LN], cont, ans;
int *bucket = &sum[LN];

int main()
{

	optimizar_io

		cin >> N >> K;

	for (int i = 0; i < N; i++)
		cin >> num[i];

	for (int i = 0; i < N; i++)
	{
		if (num[i] == K)
		{
			int cont = 0;
			for (int j = i; j >= 0; j--)
			{
				if (num[j] > num[i])
					cont--;
				if (num[j] < num[i])
					cont++;
				bucket[cont]++;
			}
			cont = 0;
			for (int j = i; j < N; j++)
			{
				if (num[j] > num[i])
					cont--;
				if (num[j] < num[i])
					cont++;
				ans += bucket[cont*-1] + bucket[cont*-1 - 1];
			}
		}
	}

	cout << ans;

	return 0;
}


#include <bits/stdc++.h>
using namespace std;

//#define USACO
#define ll long long
#define x first
#define y second
#define all(x) (x).begin(), (x).end()
#define fill(x, y) memset(x, y, sizeof(x))
#define out_range_map(x,y) ((x) < 0 || (y) < 0 || (i) == N || (j) == M)
#define optimizar_io ios_base::sync_with_stdio(false);cin.tie(NULL);
//streambuf *cin_backup = cin.rdbuf(), *cout_backup = cout.rdbuf();
#ifdef USACO
ifstream f_in("case.in");
ofstream f_out("case.out");
#endif // USACO

const ll LN = (ll)2e5 + 100, LK = 10, INF = (ll)(1e18), MOD = (ll)(1e9) + 7;
ll N, K, num[LN], sum[2 * LN], cont, ans;
ll *bucket = &sum[LN];

int main()
{

	optimizar_io

		cin >> N >> K;

	for (ll i = 0; i < N; i++)
		cin >> num[i];

	for (ll i = 0; i < N; i++)
	{
		if (num[i] == K)
		{
			ll cont = 0;
			for (ll j = i; j >= 0; j--)
			{
				if (num[j] > num[i])
					cont--;
				if (num[j] < num[i])
					cont++;
				bucket[cont]++;
			}
			cont = 0;
			for (ll j = i; j < N; j++)
			{
				if (num[j] > num[i])
					cont--;
				if (num[j] < num[i])
					cont++;
				ans += bucket[cont*-1] + bucket[cont*-1 - 1];
			}
		}
	}

	cout << ans;

	return 0;
}


#include <bits/stdc++.h>

using namespace std;

#define MAXN 200001
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int n, m, a[MAXN];
  cin >> n >> m;
  map <int, int> s[2];
  int mi = 0;
  for (int i = 0; i < n; ++i) {
    cin >> a[i];
    if (a[i]==m) mi = i;
  }
  int l = 0, h = 0;
  for (int i = mi; i >= 0; --i) {
    l += a[i]<m;
    h += a[i]>m;
    s[0][h-l]++;
  }
  l = h = 0;
  for (int i = mi; i < n; ++i) {
    l += a[i]<m;
    h += a[i]>m;
    s[1][h-l]++;
  }
  long long ans = 0;
  for (auto &ss : s[0]) {
    ans += (long long)ss.second*s[1][-ss.first];
    ans += (long long)ss.second*s[1][-ss.first+1];
  }
  cout << ans << endl;
  return 0;
}


#include <bits/stdc++.h>

using namespace std;

#define MAXN 200001
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int n, m, a[MAXN];
  cin >> n >> m;
  multiset <int> s[2];
  int mi = 0;
  for (int i = 0; i < n; ++i) {
    cin >> a[i];
    if (a[i]==m) mi = i;
  }
  int l = 0, h = 0, ans = 0;
  for (int i = mi; i >= 0; --i) {
    l += a[i]<m;
    h += a[i]>m;
    s[0].insert(h-l);
  }
  l = h = 0;
  for (int i = mi; i < n; ++i) {
    l += a[i]<m;
    h += a[i]>m;
    s[1].insert(h-l);
  }
  for (auto &cc : s[0]) {
    ans += s[1].count(-cc);
    ans += s[1].count(-cc+1);
  }
  cout << ans << endl;
  return 0;
}


#include <bits/stdc++.h>

using namespace std;

#define MAXN 200001
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int n, m, a[MAXN];
  cin >> n >> m;
  map <int, int> s[2];
  int mi = 0;
  for (int i = 0; i < n; ++i) {
    cin >> a[i];
    if (a[i]==m) mi = i;
  }
  int l = 0, h = 0;
  for (int i = mi; i >= 0; --i) {
    l += a[i]<m;
    h += a[i]>m;
    s[0][h-l]++;
  }
  l = h = 0;
  for (int i = mi; i < n; ++i) {
    l += a[i]<m;
    h += a[i]>m;
    s[1][h-l]++;
  }
  long long ans = 0;
  for (auto &ss : s[0]) {
    ans += ss.second*s[1][-ss.first];
    ans += ss.second*s[1][-ss.first+1];
  }
  cout << ans << endl;
  return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{

    int i, j, k, l, a, c, b=0,ans=0,right_one=0,right_zero=0,right_minus=0,left_one=0,left_zero=0,left_minus=0;

    int n;
    cin>>n>>c;
    int vec[200100];

    for(i=0;i<n;i++){
        cin>>vec[i];
        if(vec[i]==c) l=i;

    }

    for(i=0;i<l;i++){
        if(vec[i]<c) b--;
        if(vec[i]>c) b++;
        if(b==0||b==1) ans++;
        if(b==1)left_one++;
        if(b==0)left_zero++;
        if(b==-1)left_minus++;
    }
    b=0;

    for(i=l+1;i<n;i++){
        if(vec[i]<c) b--;
        if(vec[i]>c) b++;
        if(b==0||b==1) ans++;
        if(b==1)right_one++;
        if(b==0)right_zero++;
        if(b==-1)right_minus++;
    }

    ans=ans+(right_one*left_minus)+(right_minus*left_one)+(right_zero*left_zero)+(right_zero*left_one)+(left_zero*right_one);
    cout<<ans+1;

    return 0;
}


#include<bits/stdc++.h>
using namespace std;

map<long long , long long> mai;

int main()
{

    long long  i, j, k=0, l, a, c, b=0,ans=0,right_one=0,right_zero=0,right_minus=0,left_one=0,left_zero=0,left_minus=0;

    long  n;
    cin>>n>>c;
    long  vec[200100];

    for(i=0;i<n;i++){
        cin>>vec[i];
        if(vec[i]==c) l=i;

    }

    for(i=l-1;i>=0;i--){
        if(vec[i]<c) b--;
        if(vec[i]>c) b++;
        if(b==0||b==1) {ans++;}

        mai[b]++;
    }
    b=0;

    for(i=l+1;i<n;i++){
        if(vec[i]<c) b--;
        if(vec[i]>c) b++;
        if(b==0||b==1) {ans++;}

        ans=ans+mai[-b];

        ans=ans+mai[1-b];
    }

    cout<<ans+1;

    return 0;
}


#include<bits/stdc++.h>
using namespace std;

map<int, int> mai;

int main()
{

    int i, j, k=0, l, a, c, b=0,ans=0,right_one=0,right_zero=0,right_minus=0,left_one=0,left_zero=0,left_minus=0;

    int n;
    cin>>n>>c;
    int vec[200100];

    for(i=0;i<n;i++){
        cin>>vec[i];
        if(vec[i]==c) l=i;

    }

    for(i=l-1;i>=0;i--){
        if(vec[i]<c) b--;
        if(vec[i]>c) b++;
        if(b==0||b==1) {ans++;}

        mai[b]++;
    }
    b=0;

    for(i=l+1;i<n;i++){
        if(vec[i]<c) b--;
        if(vec[i]>c) b++;
        if(b==0||b==1) {ans++;}

        ans=ans+mai[-b];

        ans=ans+mai[1-b];
    }

    cout<<ans+1;

    return 0;
}


#include<cstdio>
#include<sstream>
#include<cstdlib>
#include<cctype>
#include<cmath>
#include<algorithm>
#include<set>
#include<queue>
#include<stack>
#include<list>
#include<iostream>
#include<fstream>
#include<numeric>
#include<string>
#include<vector>
#include<cstring>
#include<map>
#include<iterator>
#define xx first
#define yy second
#define modulo 1000000007
#define loop(i,a,b)  for(int i=a;i<b;i++)
#define loope(i,a,b)  for(int i=a;i<=b;i++)
#define checkfile freopen("input.txt", "r", stdin)
#define ms(a,b) memset(a, b, sizeof(a))

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<int, int> pll;

typedef pair<int, pii> piii;
typedef vector<int> vi;
typedef vector<int> vl;
typedef vector<pii> vii;
typedef vector<piii> viii;

int sa[200010];
int la[200010];
int num[200010];

int main(){
    int n, m;
    cin>>n>>m;

    int pos = 0;
    for(int i = 0; i<n; i++){
        cin>>num[i];
        if(num[i] == m)
            pos = i;
    }

    int cont = 1;
    int sm = 0, lr = 0;
    for(int i = pos+1; i<n; i++){
        if(m < num[i]) lr++;
        else if(m > num[i]) sm++;

        if(lr == sm || sm+1==lr)
            cont++;

        if(lr > sm){
            sa[lr-sm]++;
            sa[lr-sm-1]++;
        }
        else{
            la[sm-lr]++;
            la[sm-lr+1]++;
        }
    }

    sm = 0, lr = 0;
    for(int i = pos - 1; i>=0; i--){
        if(m < num[i]) lr++;
        else if(m > num[i]) sm++;

        if(lr == sm || sm+1==lr)
            cont++;

        if(lr > sm){
            cont += la[lr-sm];

        }
        else{
            if(lr - sm == 0)
                cont += sa[0]+la[0];
            else
                cont += sa[sm-lr];

        }
    }

    cout<<cont<<endl;

}


#include<cstdio>
#include<sstream>
#include<cstdlib>
#include<cctype>
#include<cmath>
#include<algorithm>
#include<set>
#include<queue>
#include<stack>
#include<list>
#include<iostream>
#include<fstream>
#include<numeric>
#include<string>
#include<vector>
#include<cstring>
#include<map>
#include<iterator>
#define xx first
#define yy second
#define modulo 1000000007
#define loop(i,a,b)  for(int i=a;i<b;i++)
#define loope(i,a,b)  for(int i=a;i<=b;i++)
#define checkfile freopen("input.txt", "r", stdin)
#define ms(a,b) memset(a, b, sizeof(a))

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<int, int> pll;

typedef pair<int, pii> piii;
typedef vector<int> vi;
typedef vector<int> vl;
typedef vector<pii> vii;
typedef vector<piii> viii;

int sa[200010];
int la[200010];
int num[200010];

int main(){
    int n, m;
    cin>>n>>m;

    int pos = 0;
    for(int i = 0; i<n; i++){
        cin>>num[i];
        if(num[i] == m)
            pos = i;
    }

    ll cont = 1;
    int sm = 0, lr = 0;
    for(int i = pos+1; i<n; i++){
        if(m < num[i]) lr++;
        else if(m > num[i]) sm++;

        if(lr == sm || sm+1==lr)
            cont++;

        if(lr > sm){
            sa[lr-sm]++;
            sa[lr-sm-1]++;
        }
        else{
            la[sm-lr]++;
            la[sm-lr+1]++;
        }
    }

    sm = 0, lr = 0;
    for(int i = pos - 1; i>=0; i--){
        if(m < num[i]) lr++;
        else if(m > num[i]) sm++;

        if(lr == sm || sm+1==lr)
            cont++;

        if(lr > sm){
            cont += la[lr-sm];

        }
        else{
            if(lr - sm == 0)
                cont += sa[0]+la[0];
            else
                cont += sa[sm-lr];

        }
    }

    cout<<cont<<endl;

}


#include<cstdio>
#include<sstream>
#include<cstdlib>
#include<cctype>
#include<cmath>
#include<algorithm>
#include<set>
#include<queue>
#include<stack>
#include<list>
#include<iostream>
#include<fstream>
#include<numeric>
#include<string>
#include<vector>
#include<cstring>
#include<map>
#include<iterator>
#define xx first
#define yy second
#define modulo 1000000007
#define loop(i,a,b)  for(int i=a;i<b;i++)
#define loope(i,a,b)  for(int i=a;i<=b;i++)
#define checkfile freopen("input.txt", "r", stdin)
#define ms(a,b) memset(a, b, sizeof(a))

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<int, int> pll;

typedef pair<int, pii> piii;
typedef vector<int> vi;
typedef vector<int> vl;
typedef vector<pii> vii;
typedef vector<piii> viii;

int sa[200010];
int la[200010];
int num[200010];

int main(){
    int n, m;
    cin>>n>>m;

    int pos = 0;
    for(int i = 0; i<n; i++){
        cin>>num[i];
        if(num[i] == m)
            pos = i;
    }

    int cont = 1;
    int sm = 0, lr = 0;
    for(int i = pos+1; i<n; i++){
        if(m < num[i]) lr++;
        else if(m > num[i]) sm++;

        if(lr == sm || sm+1==lr)
            cont++;

        if(lr > sm){
            sa[lr-sm]++;
            sa[lr-sm-1]++;
        }
        else{
            la[sm-lr]++;
            la[sm-lr+1]++;
        }
    }

    sm = 0, lr = 0;
    for(int i = pos - 1; i>=0; i--){
        if(m < num[i]) lr++;
        else if(m > num[i]) sm++;

        if(lr == sm || sm+1==lr)
            cont++;

        if(lr > sm){
            cont += la[lr-sm];

        }
        else{
            if(lr - sm == 0)
                cont += sa[0]+la[0];
            else
                cont += sa[sm-lr];

        }
        cout<<num[i]<<" "<<cont<<endl;
    }

    cout<<cont<<endl;

}


#include<bits/stdc++.h>

using namespace std;

#define ll long long
#define pb push_back
#define mp make_pair
#define pll pair<ll,ll>
int arr[200000+100];
int m[2*(200000+100)];
int p[200000+50];
int main(void)
{
  int n, x;
  int idx = -1;
  cin>>n>>x;

  for(int i=1; i<=n; i++)
  {
    cin>>arr[i];
    if(arr[i]==x)
      idx = i;
  }

  int pre = 0;
  p[0]=0;
  for(int i=1; i<=n; i++)
  {
      pre += (arr[i] > x ? 1 : -1 );
      if(i==idx)
        pre++;
      if(i>idx)
        m[pre+200000]++;
      p[i] = pre;
  }

  int ans = 0 ;

  for(int i=1; i<idx; i++)
  {
    int temp = p[i-1];
    ans += m[temp+200000];
    ans += m[temp+1+200000];
  }
  //cout<<ans<<endl;
  int s,b;
  s = 0;
  b = 0;
  ans++;
  for(int i = idx-1; i>0; i--)
  {
    if(arr[i]>x)
      b++;
    else
      s++;
    if(s==b)
      ans++;
    if(b==(s+1))
      ans++;
  }
  s = 0;
  b = 0;
  for(int i=idx+1; i<=n; i++)
  {
    if(arr[i]>x)
      b++;
    else
      s++;
    if(s==b)
      ans++;
    if(b==(s-1))
      ans++;
  }
  cout<<ans<<endl;

  return 0;
}


#include<bits/stdc++.h>

using namespace std;
const int N = 2*(1e5) + 50 ;
#define ll long long
#define pb push_back
#define mp make_pair
#define pll pair<ll,ll>
int arr[N] = {0};
map<int,int> m;
int p[N] = {0};
int main(void)
{
  int n, x;
  int idx = -1;
  cin>>n>>x;

  for(int i=1; i<=n; i++)
  {
    cin>>arr[i];
    if(arr[i]==x)
      idx = i;
  }

  int pre = 0;
  p[0]=0;
  for(int i=1; i<=n; i++)
  {
      pre += (arr[i] > x ? 1 : -1 );
      if(i==idx)
        pre++;
      if(i>idx)
        m[pre]++;
      p[i] = pre;
  }

  int ans = 0 ;

  for(int i=1; i<idx; i++)
  {
    int temp = p[i-1];
    ans += m[temp];
    ans += m[temp+1];
  }
  //cout<<ans<<endl;
  int s,b;
  s = 0;
  b = 0;
  ans++;
  for(int i = idx-1; i>0; i--)
  {
    if(arr[i]>x)
      b++;
    else
      s++;
    if(s==b)
      ans++;
    if(b==(s+1))
      ans++;
  }
  s = 0;
  b = 0;
  for(int i=idx+1; i<=n; i++)
  {
    if(arr[i]>x)
      b++;
    else
      s++;
    if(s==b)
      ans++;
    if(b==(s+1))
      ans++;
  }
  cout<<ans<<endl;

  return 0;
}


#include<bits/stdc++.h>

using namespace std;

#define ll long long
#define pb push_back
#define mp make_pair
#define pll pair<ll,ll>

int main(void)
{
  int n, x, idx=-1;
  cin>>n>>x;
  int arr[n+1];
  int p[n+1];
  for(int i=1; i<=n; i++)
  {
    cin>>arr[i];
    if(arr[i]==x)
      idx = i;
  }
  map<int,int> m;
  int pre = 0;
  p[0]=0;
  for(int i=1; i<=n; i++)
  {
      pre += arr[i] > x ? 1 : -1 ;
      if(i==idx)
        pre++;
      if(i>idx)
        m[pre]++;
      p[i] = pre;
  }

  int ans = 0 ;

  for(int i=1; i<idx; i++)
  {
    int temp = p[i-1];
    ans += m[temp];
    ans += m[temp+1];
  }

  vector<int> v;

  for(int i = idx; i>0; i--)
  {
    v.pb(arr[i]);
    sort(v.begin(), v.end());
    int sz = v.size();
    if(sz%2 == 0)
    {
      if(v[sz/2 - 1] == x)
        ans++;
    }
    else
    {
      if(v[(sz-1)/2]==x)
        ans++;
    }
  }
  v.clear();

  v.pb(arr[idx]);
  for(int i=idx+1; i<=n; i++)
  {
    v.pb(arr[i]);
    sort(v.begin(), v.end());
    int sz = v.size();
    if(sz%2 == 0)
    {
      if(v[sz/2 - 1] == x)
        ans++;
    }
    else
    {
      if(v[(sz-1)/2]==x)
        ans++;
    }
  }
  cout<<ans<<endl;

  return 0;
}


#include<bits/stdc++.h>

using namespace std;

#define ll long long
#define pb push_back
#define mp make_pair
#define pll pair<ll,ll>
int arr[200000+100];
int m[2*(200000+100)];
int p[200000+50];
int main(void)
{
  int n, x;
  int idx = -1;
  cin>>n>>x;

  for(int i=1; i<=n; i++)
  {
    cin>>arr[i];
    if(arr[i]==x)
      idx = i;
  }
  if(x==1)
  {
    if(idx!=1 && idx!=n)
      cout<<"2"<<endl;
    else
      cout<<"1\n";
    return 0;
  }
//  map<int,int> m;
  int pre = 0;
  p[0]=0;
  for(int i=1; i<=n; i++)
  {
      pre += (arr[i] > x ? 1 : -1 );
      if(i==idx)
        pre++;
      if(i>idx)
        m[pre+200000]++;
      p[i] = pre;
  }

  int ans = 0 ;

  for(int i=1; i<idx; i++)
  {
    int temp = p[i-1];
    ans += m[temp+200000];
    ans += m[temp+1+200000];
  }

  vector<int> v;

  for(int i = idx; i>0; i--)
  {
    v.pb(arr[i]);
    sort(v.begin(), v.end());
    int sz = v.size();
    if(sz%2 == 0)
    {
      if(v[sz/2 - 1] == x)
        ans++;
    }
    else
    {
      if(v[(sz-1)/2]==x)
        ans++;
    }
  }
  v.clear();

  v.pb(arr[idx]);
  for(int i=idx+1; i<=n; i++)
  {
    v.pb(arr[i]);
    sort(v.begin(), v.end());
    int sz = v.size();
    if(sz%2 == 0)
    {
      if(v[sz/2 - 1] == x)
        ans++;
    }
    else
    {
      if(v[(sz-1)/2]==x)
        ans++;
    }
  }
  cout<<ans<<endl;

  return 0;
}


#include<bits/stdc++.h>

using namespace std;
const int N = 2*(1e5) + 50 ;
#define ll long long
#define pb push_back
#define mp make_pair
#define pll pair<ll,ll>
int arr[N] = {0};
int m[2*N] = {0];
int p[N] = {0};
int main(void)
{
  int n, x;
  int idx = -1;
  cin>>n>>x;

  for(int i=1; i<=n; i++)
  {
    cin>>arr[i];
    if(arr[i]==x)
      idx = i;
  }

  int pre = 0;
  p[0]=0;
  for(int i=1; i<=n; i++)
  {
      pre += (arr[i] > x ? 1 : -1 );
      if(i==idx)
        pre++;
      if(i>idx)
        m[pre+200001]++;
      p[i] = pre;
  }

  int ans = 0 ;

  for(int i=1; i<idx; i++)
  {
    int temp = p[i-1];
    ans += m[temp+200000];
    ans += m[temp+1+200000];
  }
  //cout<<ans<<endl;
  int s,b;
  s = 0;
  b = 0;
  ans++;
  for(int i = idx-1; i>0; i--)
  {
    if(arr[i]>x)
      b++;
    else
      s++;
    if(s==b)
      ans++;
    if(b==(s+1))
      ans++;
  }
  s = 0;
  b = 0;
  for(int i=idx+1; i<=n; i++)
  {
    if(arr[i]>x)
      b++;
    else
      s++;
    if(s==b)
      ans++;
    if(b==(s+1))
      ans++;
  }
  cout<<ans<<endl;

  return 0;
}


#include<bits/stdc++.h>

using namespace std;

#define ll long long
#define pb push_back
#define mp make_pair
#define pll pair<ll,ll>
int arr[200000+100];
int m[2*(200000+100)];
  int p[200000+100+1];
int main(void)
{
  int n, x;
  int idx = -1;
  cin>>n>>x;

  for(int i=1; i<=n; i++)
  {
    cin>>arr[i];
    if(arr[i]==x)
      idx = i;
  }
//  map<int,int> m;
  int pre = 0;
  p[0]=0;
  for(int i=1; i<=n; i++)
  {
      pre += arr[i] > x ? 1 : -1 ;
      if(i==idx)
        pre++;
      if(i>idx)
        m[pre+200000]++;
      p[i] = pre;
  }

  int ans = 0 ;

  for(int i=1; i<idx; i++)
  {
    int temp = p[i-1];
    ans += m[temp+200000];
    ans += m[temp+1];
  }

  vector<int> v;

  for(int i = idx; i>0; i--)
  {
    v.pb(arr[i]);
    sort(v.begin(), v.end());
    int sz = v.size();
    if(sz%2 == 0)
    {
      if(v[sz/2 - 1] == x)
        ans++;
    }
    else
    {
      if(v[(sz-1)/2]==x)
        ans++;
    }
  }
  v.clear();

  v.pb(arr[idx]);
  for(int i=idx+1; i<=n; i++)
  {
    v.pb(arr[i]);
    sort(v.begin(), v.end());
    int sz = v.size();
    if(sz%2 == 0)
    {
      if(v[sz/2 - 1] == x)
        ans++;
    }
    else
    {
      if(v[(sz-1)/2]==x)
        ans++;
    }
  }
  cout<<ans<<endl;

  return 0;
}


#include<bits/stdc++.h>

using namespace std;

#define ll long long
#define pb push_back
#define mp make_pair
#define pll pair<ll,ll>
int arr[200000+100];
int m[2*(200000+100)];
int p[200000+50];
int main(void)
{
  int n, x;
  int idx = -1;
  cin>>n>>x;

  for(int i=1; i<=n; i++)
  {
    cin>>arr[i];
    if(arr[i]==x)
      idx = i;
  }

  int pre = 0;
  p[0]=0;
  for(int i=1; i<=n; i++)
  {
      pre += (arr[i] > x ? 1 : -1 );
      if(i==idx)
        pre++;
      if(i>idx)
        m[pre+200000]++;
      p[i] = pre;
  }

  int ans = 0 ;

  for(int i=1; i<idx; i++)
  {
    int temp = p[i-1];
    ans += m[temp+200000];
    ans += m[temp+1+200000];
  }
  //cout<<ans<<endl;
  int s,b;
  s = 0;
  b = 0;
  ans++;
  for(int i = idx-1; i>0; i--)
  {
    if(arr[i]>x)
      b++;
    else
      s++;
    if(s==b)
      ans++;
    if(b==(s+1))
      ans++;
  }
  s = 0;
  b = 0;
  for(int i=idx+1; i<=n; i++)
  {
    if(arr[i]>x)
      b++;
    else
      s++;
    if(s==b)
      ans++;
    if(b==(s+1))
      ans++;
  }
  cout<<ans<<endl;

  return 0;
}


#include<bits/stdc++.h>

using namespace std;

#define ll long long
#define pb push_back
#define mp make_pair
#define pll pair<ll,ll>
int arr[200000+100];
int m[2*(200000+100)];
int p[200000+50];
int main(void)
{
  int n, x;
  int idx = -1;
  cin>>n>>x;

  for(int i=1; i<=n; i++)
  {
    cin>>arr[i];
    if(arr[i]==x)
      idx = i;
  }
//  map<int,int> m;
  int pre = 0;
  p[0]=0;
  for(int i=1; i<=n; i++)
  {
      pre += arr[i] > x ? 1 : -1 ;
      if(i==idx)
        pre++;
      if(i>idx)
        m[pre+200000]++;
      p[i] = pre;
  }

  int ans = 0 ;

  for(int i=1; i<idx; i++)
  {
    int temp = p[i-1];
    ans += m[temp+200000];
    ans += m[temp+1+200000];
  }

  vector<int> v;

  for(int i = idx; i>0; i--)
  {
    v.pb(arr[i]);
    sort(v.begin(), v.end());
    int sz = v.size();
    if(sz%2 == 0)
    {
      if(v[sz/2 - 1] == x)
        ans++;
    }
    else
    {
      if(v[(sz-1)/2]==x)
        ans++;
    }
  }
  v.clear();

  v.pb(arr[idx]);
  for(int i=idx+1; i<=n; i++)
  {
    v.pb(arr[i]);
    sort(v.begin(), v.end());
    int sz = v.size();
    if(sz%2 == 0)
    {
      if(v[sz/2 - 1] == x)
        ans++;
    }
    else
    {
      if(v[(sz-1)/2]==x)
        ans++;
    }
  }
  cout<<ans<<endl;

  return 0;
}


#include<bits/stdc++.h>

using namespace std;

#define ll long long
#define pb push_back
#define mp make_pair
#define pll pair<ll,ll>
int arr[200000+100];
int m[2*(200000+100)];
int p[200000+50];
int main(void)
{
  int n, x;
  int idx = -1;
  cin>>n>>x;

  for(int i=1; i<=n; i++)
  {
    cin>>arr[i];
    if(arr[i]==x)
      idx = i;
  }
  if(x==1)
  {
    if(idx!=1 && idx!=n)
      cout<<"3"<<endl;
    else
      cout<<"2\n";
    return 0;
  }
//  map<int,int> m;
  int pre = 0;
  p[0]=0;
  for(int i=1; i<=n; i++)
  {
      pre += (arr[i] > x ? 1 : -1 );
      if(i==idx)
        pre++;
      if(i>idx)
        m[pre+200000]++;
      p[i] = pre;
  }

  int ans = 0 ;

  for(int i=1; i<idx; i++)
  {
    int temp = p[i-1];
    ans += m[temp+200000];
    ans += m[temp+1+200000];
  }

  vector<int> v;

  for(int i = idx; i>0; i--)
  {
    v.pb(arr[i]);
    sort(v.begin(), v.end());
    int sz = v.size();
    if(sz%2 == 0)
    {
      if(v[sz/2 - 1] == x)
        ans++;
    }
    else
    {
      if(v[(sz-1)/2]==x)
        ans++;
    }
  }
  v.clear();

  v.pb(arr[idx]);
  for(int i=idx+1; i<=n; i++)
  {
    v.pb(arr[i]);
    sort(v.begin(), v.end());
    int sz = v.size();
    if(sz%2 == 0)
    {
      if(v[sz/2 - 1] == x)
        ans++;
    }
    else
    {
      if(v[(sz-1)/2]==x)
        ans++;
    }
  }
  cout<<ans<<endl;

  return 0;
}


#include<bits/stdc++.h>

using namespace std;

#define ll long long
#define pb push_back
#define mp make_pair
#define pll pair<ll,ll>
int arr[200000+100];
int m[2*(200000+100)];
int main(void)
{
  int n, x;
  int idx = -1;
  cin>>n>>x;

  int p[n+1];
  for(int i=1; i<=n; i++)
  {
    cin>>arr[i];
    if(arr[i]==x)
      idx = i;
  }
//  map<int,int> m;
  int pre = 0;
  p[0]=0;
  for(int i=1; i<=n; i++)
  {
      pre += arr[i] > x ? 1 : -1 ;
      if(i==idx)
        pre++;
      if(i>idx)
        m[pre+200000]++;
      p[i] = pre;
  }

  int ans = 0 ;

  for(int i=1; i<idx; i++)
  {
    int temp = p[i-1];
    ans += m[temp+200000];
    ans += m[temp+1+200000];
  }

  vector<int> v;

  for(int i = idx; i>0; i--)
  {
    v.pb(arr[i]);
    sort(v.begin(), v.end());
    int sz = v.size();
    if(sz%2 == 0)
    {
      if(v[sz/2 - 1] == x)
        ans++;
    }
    else
    {
      if(v[(sz-1)/2]==x)
        ans++;
    }
  }
  v.clear();

  v.pb(arr[idx]);
  for(int i=idx+1; i<=n; i++)
  {
    v.pb(arr[i]);
    sort(v.begin(), v.end());
    int sz = v.size();
    if(sz%2 == 0)
    {
      if(v[sz/2 - 1] == x)
        ans++;
    }
    else
    {
      if(v[(sz-1)/2]==x)
        ans++;
    }
  }
  cout<<ans<<endl;

  return 0;
}


#include<bits/stdc++.h>

using namespace std;

#define ll long long
#define pb push_back
#define mp make_pair
#define pll pair<ll,ll>
int arr[200000+100];
int m[2*(200000+100)];
int p[200000+50];
int main(void)
{
  int n, x;
  int idx = -1;
  cin>>n>>x;

  for(int i=1; i<=n; i++)
  {
    cin>>arr[i];
    if(arr[i]==x)
      idx = i;
  }
  if(x==1)
  {
    cout<<"1"<<endl;
    return 0;
  }
//  map<int,int> m;
  int pre = 0;
  p[0]=0;
  for(int i=1; i<=n; i++)
  {
      pre += (arr[i] > x ? 1 : -1 );
      if(i==idx)
        pre++;
      if(i>idx)
        m[pre+200000]++;
      p[i] = pre;
  }

  int ans = 0 ;

  for(int i=1; i<idx; i++)
  {
    int temp = p[i-1];
    ans += m[temp+200000];
    ans += m[temp+1+200000];
  }

  vector<int> v;

  for(int i = idx; i>0; i--)
  {
    v.pb(arr[i]);
    sort(v.begin(), v.end());
    int sz = v.size();
    if(sz%2 == 0)
    {
      if(v[sz/2 - 1] == x)
        ans++;
    }
    else
    {
      if(v[(sz-1)/2]==x)
        ans++;
    }
  }
  v.clear();

  v.pb(arr[idx]);
  for(int i=idx+1; i<=n; i++)
  {
    v.pb(arr[i]);
    sort(v.begin(), v.end());
    int sz = v.size();
    if(sz%2 == 0)
    {
      if(v[sz/2 - 1] == x)
        ans++;
    }
    else
    {
      if(v[(sz-1)/2]==x)
        ans++;
    }
  }
  cout<<ans<<endl;

  return 0;
}


#include<bits/stdc++.h>

using namespace std;
const int N = 2*(1e5) + 50 ;
#define ll long long
#define pb push_back
#define mp make_pair
#define pll pair<ll,ll>
int arr[N] = {0};
int m[2*N] = {0};
int p[N] = {0};
int main(void)
{
  int n, x;
  int idx = -1;
  cin>>n>>x;

  for(int i=1; i<=n; i++)
  {
    cin>>arr[i];
    if(arr[i]==x)
      idx = i;
  }

  int pre = 0;
  p[0]=0;
  for(int i=1; i<=n; i++)
  {
      pre += (arr[i] > x ? 1 : -1 );
      if(i==idx)
        pre++;
      if(i>idx)
        m[pre+200001]++;
      p[i] = pre;
  }

  int ans = 0 ;

  for(int i=1; i<idx; i++)
  {
    int temp = p[i-1];
    ans += m[temp+200000];
    ans += m[temp+1+200000];
  }
  //cout<<ans<<endl;
  int s,b;
  s = 0;
  b = 0;
  ans++;
  for(int i = idx-1; i>0; i--)
  {
    if(arr[i]>x)
      b++;
    else
      s++;
    if(s==b)
      ans++;
    if(b==(s+1))
      ans++;
  }
  s = 0;
  b = 0;
  for(int i=idx+1; i<=n; i++)
  {
    if(arr[i]>x)
      b++;
    else
      s++;
    if(s==b)
      ans++;
    if(b==(s+1))
      ans++;
  }
  cout<<ans<<endl;

  return 0;
}


#include<bits/stdc++.h>

using namespace std;
const int N = 2*(1e5) + 50 ;
#define ll long long
#define pb push_back
#define mp make_pair
#define pll pair<ll,ll>
ll arr[N] = {0};
map<ll,ll> m;
ll p[N] = {0};
int main(void)
{
  ll n, x;
  ll idx = -1;
  cin>>n>>x;

  for(int i=1; i<=n; i++)
  {
    cin>>arr[i];
    if(arr[i]==x)
      idx = i;
  }

  ll pre = 0;
  p[0]=0;
  for(int i=1; i<=n; i++)
  {
      pre += (arr[i] > x ? 1 : -1 );
      if(i==idx)
        pre++;
      if(i>idx)
        m[pre]++;
      p[i] = pre;
  }

  ll ans = 0 ;

  for(int i=1; i<idx; i++)
  {
    int temp = p[i-1];
    ans += m[temp];
    ans += m[temp+1];
  }
  //cout<<ans<<endl;
  ll s,b;
  s = 0;
  b = 0;
  ans++;
  for(int i = idx-1; i>0; i--)
  {
    if(arr[i]>x)
      b++;
    else
      s++;
    if(s==b)
      ans++;
    if(b==(s+1))
      ans++;
  }
  s = 0;
  b = 0;
  for(int i=idx+1; i<=n; i++)
  {
    if(arr[i]>x)
      b++;
    else
      s++;
    if(s==b)
      ans++;
    if(b==(s+1))
      ans++;
  }
  cout<<ans<<endl;

  return 0;
}


#include<bits/stdc++.h>

using namespace std;

#define ll long long
#define pb push_back
#define mp make_pair
#define pll pair<ll,ll>
int arr[200000+100];
int m[200000+100];
int main(void)
{
  int n, x, idx=-1;
  cin>>n>>x;

  int p[n+1];
  for(int i=1; i<=n; i++)
  {
    cin>>arr[i];
    if(arr[i]==x)
      idx = i;
  }
//  map<int,int> m;
  int pre = 0;
  p[0]=0;
  for(int i=1; i<=n; i++)
  {
      pre += arr[i] > x ? 1 : -1 ;
      if(i==idx)
        pre++;
      if(i>idx)
        m[pre]++;
      p[i] = pre;
  }

  int ans = 0 ;

  for(int i=1; i<idx; i++)
  {
    int temp = p[i-1];
    ans += m[temp];
    ans += m[temp+1];
  }

  vector<int> v;

  for(int i = idx; i>0; i--)
  {
    v.pb(arr[i]);
    sort(v.begin(), v.end());
    int sz = v.size();
    if(sz%2 == 0)
    {
      if(v[sz/2 - 1] == x)
        ans++;
    }
    else
    {
      if(v[(sz-1)/2]==x)
        ans++;
    }
  }
  v.clear();

  v.pb(arr[idx]);
  for(int i=idx+1; i<=n; i++)
  {
    v.pb(arr[i]);
    sort(v.begin(), v.end());
    int sz = v.size();
    if(sz%2 == 0)
    {
      if(v[sz/2 - 1] == x)
        ans++;
    }
    else
    {
      if(v[(sz-1)/2]==x)
        ans++;
    }
  }
  cout<<ans<<endl;

  return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define mk make_pair
#define pi pair < int , int >
#define PI 2*acos(0.0)
#define pp pair < ll , ll >
#define inf 1e18
#define mod 1000000007
#define pb push_back
#define si1(a) scanf("%d",&a)
#define si2(a,b) scanf("%d%d",&a,&b)
#define si3(a,b,c) scanf("%d%d%d",&a,&b,&c)
#define sl1(a) scanf("%lld",&a)
#define sl2(a,b) scanf("%lld%lld",&a,&b)
#define sl3(a,b,c) scanf("%lld%lld%lld",&a,&b,&c)
#define ff first
#define ss second
#define ll long long int
#define mod 1000000007
map < ll , ll > mp;

ll arr[200005];

int main()
{
    ios_base::sync_with_stdio(0);
    ll i,j=-1,k,m,n,c=0,x,y,one=0,two=0;
    //..x0ll n;
cin>>n>>x;
for(i=0;i<n;i++)
{
    cin>>arr[i];
    if(arr[i]==x)
        j=i;
}

y=j;
mp[0]++;
y++;
while(y<n)
{
    if(arr[y]>x)
        one++;
    else
        two++;
    mp[one-two]++;
  // cout<<y<<" "<<(one-two)<<"\n";
y++;
}
y=j;
c=mp[0];
c+=mp[1];
y--;
one =0;
two =0;
//cout<<c<<"\n";
while(y>=0)
{
    if(arr[y]>x)
        one++;
    else
        two++;

        c+=mp[two-one];
        //cout<<y<<" "<<(two-one)<<" "<<mp[two-one]<<"\n";
     if(one-two>0)
     {
         ll k=one-two-1;
         c+=mp[-1LL*k];
     }
     else
     {
     ll k=two-one+1;
          c+=mp[k];
     }
y--;
}
cout<<c<<"\n";

    return 0;
}
/*
for(j=0;j<n;j++)
{
}
for(t=0;t<tt;t++)
{}
for(i=0;i<n;i++)
{
    for(j=0;j<n;j++)
    {
    }
}

*/


#include <bits/stdc++.h>
using namespace std;
#define mk make_pair
#define pi pair < int , int >
#define PI 2*acos(0.0)
#define pp pair < ll , ll >
#define inf 1e18
#define mod 1000000007
#define pb push_back
#define si1(a) scanf("%d",&a)
#define si2(a,b) scanf("%d%d",&a,&b)
#define si3(a,b,c) scanf("%d%d%d",&a,&b,&c)
#define sl1(a) scanf("%lld",&a)
#define sl2(a,b) scanf("%lld%lld",&a,&b)
#define sl3(a,b,c) scanf("%lld%lld%lld",&a,&b,&c)
#define ff first
#define ss second
#define ll long long int
#define mod 1000000007
map < ll , ll > mp;

ll arr[120005];

int main()
{
    ios_base::sync_with_stdio(0);
    ll i,j,k,m,n,c=0,x,y,one=0,two=0;
    //..x0ll n;
cin>>n>>x;
for(i=0;i<n;i++)
{
    cin>>arr[i];
    if(arr[i]==x)
        j=i;
}
y=j;
mp[0]++;
y++;
while(y<n)
{
    if(arr[y]>x)
        one++;
    else
        two++;
    mp[one-two]++;
  // cout<<y<<" "<<(one-two)<<"\n";
y++;
}
y=j;
c=mp[0];
c+=mp[1];
y--;
one =0;
two =0;
//cout<<c<<"\n";
while(y>=0)
{
    if(arr[y]>x)
        one++;
    else
        two++;

        c+=mp[two-one];
        //cout<<y<<" "<<(two-one)<<" "<<mp[two-one]<<"\n";
     if(one-two>0)
     {
         ll k=one-two-1;
         c+=mp[-1LL*k];
     }
     else
     {
     ll k=two-one+1;
          c+=mp[k];
     }
y--;
}
cout<<c<<"\n";

    return 0;
}
/*
for(j=0;j<n;j++)
{
}
for(t=0;t<tt;t++)
{}
for(i=0;i<n;i++)
{
    for(j=0;j<n;j++)
    {
    }
}

*/


#include <bits/stdc++.h>
using namespace std;
#define mk make_pair
#define pi pair < int , int >
#define PI 2*acos(0.0)
#define pp pair < ll , ll >
#define inf 1e18
#define mod 1000000007
#define pb push_back
#define si1(a) scanf("%d",&a)
#define si2(a,b) scanf("%d%d",&a,&b)
#define si3(a,b,c) scanf("%d%d%d",&a,&b,&c)
#define sl1(a) scanf("%lld",&a)
#define sl2(a,b) scanf("%lld%lld",&a,&b)
#define sl3(a,b,c) scanf("%lld%lld%lld",&a,&b,&c)
#define ff first
#define ss second
#define ll long long int
#define mod 1000000007
map < ll , ll > mp;

ll arr[120005];

int main()
{
    ios_base::sync_with_stdio(0);
    ll i,j,k,m,n,c=0,x,y,one=0,two=0;
    //..x0ll n;
cin>>n>>x;
for(i=0;i<n;i++)
{
    cin>>arr[i];
    if(arr[i]==x)
        j=i;
}
y=j;
mp[0]++;
y++;
while(y<n)
{
    if(arr[y]>x)
        one++;
    else
        two++;
    mp[one-two]++;
  // cout<<y<<" "<<(one-two)<<"\n";
y++;
}
y=j;
c=mp[0];
c+=mp[1];
y--;
one =0;
two =0;
//cout<<c<<"\n";
while(y>=0)
{
    if(arr[y]>x)
        one++;
    else
        two++;

        c+=mp[two-one];
        //cout<<y<<" "<<(two-one)<<" "<<mp[two-one]<<"\n";
        if(two-one==-1)
        {
            c+=mp[0];
          //  cout<<y<<"*\n";
        }
        else if(two-one==0)
        {
            c+=mp[1];
        }
y--;
}
cout<<c<<"\n";

    return 0;
}
/*
for(j=0;j<n;j++)
{
}
for(t=0;t<tt;t++)
{}
for(i=0;i<n;i++)
{
    for(j=0;j<n;j++)
    {
    }
}

*/


#include <bits/stdc++.h>
#define int long long
using namespace std;
const int N=2e5+5;
int n,m,ans,pos;
int a[N],sum[N],b[N];
map<int,int>c,c1;
signed main(){
	scanf("%lld%lld",&n,&m);
	for (int i=1; i<=n; ++i)
	{
		scanf("%lld",&a[i]);
		if (a[i]==m) pos=i;
	}
	for (int i=1; i<=n; ++i)
	{
		if (a[i]<m) b[i]=-1;
		if (a[i]>m) b[i]=1;
		if (a[i]==m) b[i]=0;
	}
	sum[pos]=b[pos]; c[sum[pos]]++;
	for (int i=pos-1; i>=1; --i) sum[i]=sum[i+1]+b[i],c[sum[i]]++;
	ans+=c[-sum[pos]]+c[-sum[pos]+1];
	for (int i=pos+1; i<=n; ++i)
	{
		sum[i]=sum[i-1]+b[i];
		ans+=c[-sum[i]]+c[-sum[i]+1];
	}

	printf("%lld\n",ans);
return 0;
}


/**
 *   author: malviyanshiv
 *   created: 05 April 2019  10:05:16
**/

#include <bits/stdc++.h>

using namespace std;

#define REP(i, a, b) for(int i = a; i < b; i++)
#define RREP(i, a, b) for(int i = a-1; i >= b; i--)
#define FORE(a) for(auto ele : a )
#define ALL(a) begin(a), end(a)
#define RPB(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))

#define PB push_back
#define MP make_pair
#define MOD 1000000007
#define INF 0x7fffffff
#define LINF 2000000000000000007
#define F first
#define S second
#define TC int t; cin >> t; while(t--)
#define SET(a,b) memset(a,b,sizeof(a))

#define TRACE

#ifdef TRACE
#define trace1(x)                cerr << #x << ": " << x << endl;
#define trace2(x, y)             cerr << #x << ": " << x << " | " << #y << ": " << y << endl;
#define trace3(x, y, z)          cerr << #x << ": " << x << " | " << #y << ": " << y << " | " << #z << ": " << z << endl;
#define trace4(a, b, c, d)       cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << endl;
#define trace5(a, b, c, d, e)    cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << " | " << #e << ": " << e << endl;
#define trace6(a, b, c, d, e, f) cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << " | " << #e << ": " << e << " | " << #f << ": " << f << endl;

#else

#define trace1(x)
#define trace2(x, y)
#define trace3(x, y, z)
#define trace4(a, b, c, d)
#define trace5(a, b, c, d, e)
#define trace6(a, b, c, d, e, f)

#endif

typedef long long ll;
typedef pair< int, int > PII;

void optimizeIO(){
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
}

int main(){
	optimizeIO();

	int n, k;
	cin >> n >> k;

	vector<int> arr(n);
	REP(i, 0, n)
		cin>> arr[i];
	vector<int> rem(k, 0);
	REP(i, 0, n)
		rem[arr[i]%k]++;
	int tot = 0;
	REP(i, 1, k){
		if( k%2 == 0 && i == k/2 )
			continue;
		tot += min( rem[i], rem[k-i]);
	}
	tot += ( rem[0] );
	if( k%2 == 0 ){
		tot += ( rem[k/2] );
		if( rem[k/2]&1 )
			tot --;
	}
	if( rem[0]&1 )
		tot--;
	cout << tot << endl;
	return 0;
}


/**
 *   author: malviyanshiv
 *   created: 05 April 2019  10:26:20
**/

#include <bits/stdc++.h>

using namespace std;

#define REP(i, a, b) for(int i = a; i < b; i++)
#define RREP(i, a, b) for(int i = a-1; i >= b; i--)
#define FORE(a) for(auto ele : a )
#define ALL(a) begin(a), end(a)
#define RPB(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))

#define PB push_back
#define MP make_pair
#define MOD 1000000007
#define INF 0x7fffffff
#define LINF 2000000000000000007
#define F first
#define S second
#define TC int t; cin >> t; while(t--)
#define SET(a,b) memset(a,b,sizeof(a))

#define TRACE

#ifdef TRACE
#define trace1(x)                cerr << #x << ": " << x << endl;
#define trace2(x, y)             cerr << #x << ": " << x << " | " << #y << ": " << y << endl;
#define trace3(x, y, z)          cerr << #x << ": " << x << " | " << #y << ": " << y << " | " << #z << ": " << z << endl;
#define trace4(a, b, c, d)       cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << endl;
#define trace5(a, b, c, d, e)    cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << " | " << #e << ": " << e << endl;
#define trace6(a, b, c, d, e, f) cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << " | " << #e << ": " << e << " | " << #f << ": " << f << endl;

#else

#define trace1(x)
#define trace2(x, y)
#define trace3(x, y, z)
#define trace4(a, b, c, d)
#define trace5(a, b, c, d, e)
#define trace6(a, b, c, d, e, f)

#endif

typedef long long ll;
typedef pair< int, int > PII;

void optimizeIO(){
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
}

int main(){
	optimizeIO();

	int n;
	cin >> n;
	vector<int> arr(n);
	REP(i, 0, n)
		cin >> arr[i];
	sort( arr.begin(), arr.end());
	int mx = 0;
	int mii = 0, mxi = 1;
	while( mxi < n && arr[mxi]-arr[mii] <= 5 )
		mxi++;
	mx = mxi - mii;
	while( mxi != n ){
		mii++;
		while( mxi < n && arr[mxi]-arr[mii] <= 5 )
			mxi++;
		mx = max( mx, mxi - mii);
	}
	cout << mx << endl;
	return 0;
}


/**
 *   author: malviyanshiv
 *   created: 05 April 2019  10:05:16
**/

#include <bits/stdc++.h>

using namespace std;

#define REP(i, a, b) for(int i = a; i < b; i++)
#define RREP(i, a, b) for(int i = a-1; i >= b; i--)
#define FORE(a) for(auto ele : a )
#define ALL(a) begin(a), end(a)
#define RPB(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))

#define PB push_back
#define MP make_pair
#define MOD 1000000007
#define INF 0x7fffffff
#define LINF 2000000000000000007
#define F first
#define S second
#define TC int t; cin >> t; while(t--)
#define SET(a,b) memset(a,b,sizeof(a))

#define TRACE

#ifdef TRACE
#define trace1(x)                cerr << #x << ": " << x << endl;
#define trace2(x, y)             cerr << #x << ": " << x << " | " << #y << ": " << y << endl;
#define trace3(x, y, z)          cerr << #x << ": " << x << " | " << #y << ": " << y << " | " << #z << ": " << z << endl;
#define trace4(a, b, c, d)       cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << endl;
#define trace5(a, b, c, d, e)    cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << " | " << #e << ": " << e << endl;
#define trace6(a, b, c, d, e, f) cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << " | " << #e << ": " << e << " | " << #f << ": " << f << endl;

#else

#define trace1(x)
#define trace2(x, y)
#define trace3(x, y, z)
#define trace4(a, b, c, d)
#define trace5(a, b, c, d, e)
#define trace6(a, b, c, d, e, f)

#endif

typedef long long ll;
typedef pair< int, int > PII;

void optimizeIO(){
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
}

int main(){
	optimizeIO();

	int n, k;
	cin >> n >> k;

	vector<int> arr(n);
	REP(i, 0, n)
		cin>> arr[i];
	vector<int> rem(k);
	REP(i, 0, n)
		rem[arr[i]%k]++;
	int tot = rem[0];
	REP(i, 1, k)
		tot += min( rem[i], rem[k-i]);
	tot = tot /2 ;
	tot = tot * 2;
	cout << tot << endl;
	return 0;
}


/**
 *   author: malviyanshiv
 *   created: 05 April 2019  10:05:16
**/

#include <bits/stdc++.h>

using namespace std;

#define REP(i, a, b) for(int i = a; i < b; i++)
#define RREP(i, a, b) for(int i = a-1; i >= b; i--)
#define FORE(a) for(auto ele : a )
#define ALL(a) begin(a), end(a)
#define RPB(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))

#define PB push_back
#define MP make_pair
#define MOD 1000000007
#define INF 0x7fffffff
#define LINF 2000000000000000007
#define F first
#define S second
#define TC int t; cin >> t; while(t--)
#define SET(a,b) memset(a,b,sizeof(a))

#define TRACE

#ifdef TRACE
#define trace1(x)                cerr << #x << ": " << x << endl;
#define trace2(x, y)             cerr << #x << ": " << x << " | " << #y << ": " << y << endl;
#define trace3(x, y, z)          cerr << #x << ": " << x << " | " << #y << ": " << y << " | " << #z << ": " << z << endl;
#define trace4(a, b, c, d)       cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << endl;
#define trace5(a, b, c, d, e)    cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << " | " << #e << ": " << e << endl;
#define trace6(a, b, c, d, e, f) cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << " | " << #e << ": " << e << " | " << #f << ": " << f << endl;

#else

#define trace1(x)
#define trace2(x, y)
#define trace3(x, y, z)
#define trace4(a, b, c, d)
#define trace5(a, b, c, d, e)
#define trace6(a, b, c, d, e, f)

#endif

typedef long long ll;
typedef pair< int, int > PII;

void optimizeIO(){
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
}

int main(){
	optimizeIO();

	int n, k;
	cin >> n >> k;

	vector<int> arr(n);
	REP(i, 0, n)
		cin>> arr[i];
	vector<int> rem(k, 0);
	REP(i, 0, n)
		rem[arr[i]%k]++;
	int tot = 0;
	REP(i, 1, k)
		tot += min( rem[i], rem[k-i]);
	tot += ( rem[0] );
	//cout << " tot " << tot << endl;
	if( rem[0]&1 )
		tot--;
	if( k%2 == 0 ){
		tot -= rem[k/2];
		if( rem[k/2]&1 )
			tot--;
	}
	//REP(i, 0, k)
		//cout << i << " " << rem[i] << endl;
	cout << tot << endl;
	return 0;
}


/**
 *   author: malviyanshiv
 *   created: 05 April 2019  10:05:16
**/

#include <bits/stdc++.h>

using namespace std;

#define REP(i, a, b) for(int i = a; i < b; i++)
#define RREP(i, a, b) for(int i = a-1; i >= b; i--)
#define FORE(a) for(auto ele : a )
#define ALL(a) begin(a), end(a)
#define RPB(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))

#define PB push_back
#define MP make_pair
#define MOD 1000000007
#define INF 0x7fffffff
#define LINF 2000000000000000007
#define F first
#define S second
#define TC int t; cin >> t; while(t--)
#define SET(a,b) memset(a,b,sizeof(a))

#define TRACE

#ifdef TRACE
#define trace1(x)                cerr << #x << ": " << x << endl;
#define trace2(x, y)             cerr << #x << ": " << x << " | " << #y << ": " << y << endl;
#define trace3(x, y, z)          cerr << #x << ": " << x << " | " << #y << ": " << y << " | " << #z << ": " << z << endl;
#define trace4(a, b, c, d)       cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << endl;
#define trace5(a, b, c, d, e)    cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << " | " << #e << ": " << e << endl;
#define trace6(a, b, c, d, e, f) cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << " | " << #e << ": " << e << " | " << #f << ": " << f << endl;

#else

#define trace1(x)
#define trace2(x, y)
#define trace3(x, y, z)
#define trace4(a, b, c, d)
#define trace5(a, b, c, d, e)
#define trace6(a, b, c, d, e, f)

#endif

typedef long long ll;
typedef pair< int, int > PII;

void optimizeIO(){
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
}

int main(){
	optimizeIO();

	int n, k;
	cin >> n >> k;

	vector<int> arr(n);
	REP(i, 0, n)
		cin>> arr[i];
	vector<int> rem(k);
	REP(i, 0, n)
		rem[arr[i]%k]++;
	int tot = 0;
	REP(i, 1, k)
		tot += min( rem[i], rem[k-i]);
	tot += ( rem[0] );
	if( rem[0]&1 )
		tot--;
	cout << tot << endl;
	return 0;
}


/**
 *   author: malviyanshiv
 *   created: 05 April 2019  10:05:16
**/

#include <bits/stdc++.h>

using namespace std;

#define REP(i, a, b) for(int i = a; i < b; i++)
#define RREP(i, a, b) for(int i = a-1; i >= b; i--)
#define FORE(a) for(auto ele : a )
#define ALL(a) begin(a), end(a)
#define RPB(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))

#define PB push_back
#define MP make_pair
#define MOD 1000000007
#define INF 0x7fffffff
#define LINF 2000000000000000007
#define F first
#define S second
#define TC int t; cin >> t; while(t--)
#define SET(a,b) memset(a,b,sizeof(a))

#define TRACE

#ifdef TRACE
#define trace1(x)                cerr << #x << ": " << x << endl;
#define trace2(x, y)             cerr << #x << ": " << x << " | " << #y << ": " << y << endl;
#define trace3(x, y, z)          cerr << #x << ": " << x << " | " << #y << ": " << y << " | " << #z << ": " << z << endl;
#define trace4(a, b, c, d)       cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << endl;
#define trace5(a, b, c, d, e)    cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << " | " << #e << ": " << e << endl;
#define trace6(a, b, c, d, e, f) cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << " | " << #e << ": " << e << " | " << #f << ": " << f << endl;

#else

#define trace1(x)
#define trace2(x, y)
#define trace3(x, y, z)
#define trace4(a, b, c, d)
#define trace5(a, b, c, d, e)
#define trace6(a, b, c, d, e, f)

#endif

typedef long long ll;
typedef pair< int, int > PII;

void optimizeIO(){
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
}

int main(){
	optimizeIO();

	int n, k;
	cin >> n >> k;

	vector<int> arr(n);
	REP(i, 0, n)
		cin>> arr[i];
	vector<int> rem(k);
	REP(i, 0, n)
		rem[arr[i]%k]++;
	int tot = 0;
	REP(i, 1, k)
		tot += min( rem[i], rem[k-i]);
	tot = tot /2 ;
	tot += ( rem[0] );
	if( rem[0]&1 )
		tot--;
	cout << tot << endl;
	return 0;
}


#include<iostream>
#include<vector>
#include<algorithm>

using namespace std;

int main()
{
	long long n ,k;
	cin>>n>>k;
	vector<long long> A(n+1,0),V(n+1,0);
	int b;
	for(int i=1;i<=n;i++)
	{
		cin>>b;
		A[i]=b;
	}
	sort(A.begin(),A.end());
	int index=0;
	for(int i=1;i<=n;i++)
	{
		if(!V[i])
		{
		   for(int j=i+1;j<=n;j++)
		   {
			   if(!V[j]&&(A[i]+A[j])%k==0)
			   {
				V[j]=1;
				V[i]=1;
				index+=2;
				break;
			   }
		   }
    	}
	}
	cout<<index<<endl;
	return 0;
}


#include<bits/stdc++.h>

using namespace std;

#define en '\n'
#define ll long long

vector<int> r(101,0);

int main()
{
	ll boxes = 0;
	int n;
	ll k;
	cin>>n>>k;
	for(int i=0;i<n;++i)
	{
		ll a;
		cin>>a;
		++r[a%k];
	}
	boxes+=(r[0]>>1)*2;
	//cout<<boxes<<en;
	for(int i=1;i<=k/2;++i)
	{
		ll mmin = min(r[i],r[k-i]);
		if(i!=k-i)mmin*=2;
		else mmin-=mmin%2;
		boxes+=mmin;
	}
	cout<<boxes<<en;

}


#include<bits/stdc++.h>

using namespace std;

#define en '\n'
#define ll long long

vector<int> r(101,0);

int main()
{
	ll boxes = 0;
	int n;
	ll k;
	cin>>n>>k;
	for(int i=0;i<n;++i)
	{
		ll a;
		cin>>a;
		++r[a%k];
	}
	boxes+=(r[0]>>1)*2;
	//cout<<boxes<<en;
	for(int i=1;i<=k/2;++i)
	{
		ll mmin = min(r[i],r[k-i]);
		if(i!=k-i)mmin*=2;
		boxes+=mmin;
	}
	cout<<boxes<<en;

}


#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;

int main()
{
	long long n ,k;
	cin>>n>>k;
	vector<long long> A(n+1,0),V(n+1,0);
	int b;
	for(int i=1;i<=n;i++)
	{
		cin>>b;
		A[i]=b;
	}
	sort(A.begin(),A.end());
	int index=0;
	for(int i=1;i<=n;i++)
	{
		for(int j=i;j<=n;j++)
		{
			if((A[i]+A[j])%k==0&&!V[j]&&!V[i]&&i!=j)
			{
				V[j]=1;
				V[i]=1;
				index+=2;
			}
		}
	}
	cout<<index<<endl;
	return 0;
}


#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;

int main()
{
	long long n ,k;
	cin>>n>>k;
	vector<long long> A(n+1,0),V(n+1,0);
	int b;
	for(int i=1;i<=n;i++)
	{
		cin>>b;
		A[i]=b;
	}
	sort(A.rbegin(),A.rend());
	int index=0;
	for(int i=1;i<=n;i++)
	{
		for(int j=i;j<=n;j++)
		{
			if((A[i]+A[j])%k==0&&!V[j]&&!V[i]&&i!=j)
			{
				V[j]=1;
				V[i]=1;
				index+=2;
			}
		}
	}
	cout<<index<<endl;
	return 0;
}


#include<bits/stdc++.h>

using namespace std;

#define en '\n'
#define ll long long

vector<int> r(101,0);

int main()
{
	ll boxes = 0;
	int n;
	ll k;
	cin>>n>>k;
	for(int i=0;i<n;++i)
	{
		ll a;
		cin>>a;
		++r[a%k];
	}
	boxes+=(r[0]>>1)*2;
	int limit = k-1;
	//cout<<boxes<<en;
	for(int i=1;i<=limit;++i)
	{
		ll mmin = min(r[i],r[limit-i+1]);
		//cout<<mmin<<en;
		boxes+=mmin;
	}
	cout<<boxes<<en;

}


#include<bits/stdc++.h>

using namespace std;

#define en '\n'
#define ll long long

vector<int> r(101,0);

int main()
{
	ll boxes = 0;
	int n;
	ll k;
	cin>>n>>k;
	for(int i=0;i<n;++i)
	{
		ll a;
		cin>>a;
		++r[a%k];
	}
	boxes+=(r[0]>>1)*2;
	int limit = k-1;
	cout<<boxes<<en;
	for(int i=1;i<=limit;++i)
	{
		ll mmin = min(r[i],r[limit-i+1]);
		//cout<<mmin<<en;
		boxes+=mmin;
	}
	cout<<boxes<<en;

}


#include<iostream>
#include<vector>

using namespace std;

int main()
{
	long long n ,k;
	cin>>n>>k;
	vector<long long> A(n+1,0),V(n+1,0);
	int b;
	for(int i=1;i<=n;i++)
	{
		cin>>b;
		A[i]=b;
	}
	int index=0;
	for(int i=1;i<=n;i++)
	{
		for(int j=i;j<=n;j++)
		{
			if((A[i]+A[j])%k==0&&!V[j]&&!V[i]&&i!=j)
			{
				V[j]=1;
				V[i]=1;
				index+=2;
			}
		}
	}
	cout<<index<<endl;
	return 0;
}


#include<bits/stdc++.h>

using namespace std;

#define en '\n'
#define ll long long

vector<int> r(101,0);

int main()
{
	ll boxes = 0;
	int n;
	ll k;
	cin>>n>>k;
	for(int i=0;i<n;++i)
	{
		ll a;
		cin>>a;
		++r[a%k];
	}
	boxes+=(r[0]>>1)*2;
	//cout<<boxes<<en;
	for(int i=1;i<=k/2;++i)
	{
		ll mmin = min(r[i],r[k-i]);
		if(i!=k-i)mmin*=2;
		boxes+=mmin;
	}
	if(boxes%2==1)--boxes;
	cout<<boxes<<en;

}


#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;

int main()
{
	long long n ,k;
	cin>>n>>k;
	vector<long long> A(n+1,0),V(n+1,0);
	int b;
	for(int i=1;i<=n;i++)
	{
		cin>>b;
		A[i]=b;
	}
	sort(A.begin(),A.end());
	int index=0;
	for(int i=1;i<=n;i++)
	{
		for(int j=i+1;j<=n;j++)
		{
			if(!V[j]&&!V[i]&&(A[i]+A[j])%k==0)
			{
				V[j]=1;
				V[i]=1;
				index+=2;
			}
		}
	}
	cout<<index<<endl;
	return 0;
}


#include<bits/stdc++.h>

using namespace std;

#define en '\n'
#define ll long long

vector<int> r(101,0);

int main()
{
	ll boxes = 0;
	int n;
	ll k;
	cin>>n>>k;
	for(int i=0;i<n;++i)
	{
		ll a;
		cin>>a;
		++r[a%k];
	}
	boxes+=(r[0]>>1)*2;
	//cout<<boxes<<en;
	for(int i=1;i<=k/2;++i)
	{
		ll mmin = min(r[i],r[k-i]);
		if(i!=k-1)mmin*=2;
		boxes+=mmin;
	}
	cout<<boxes<<en;

}


#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e5+7;
int n,k;
int a[maxn],b[maxn];
unordered_map<int,int> mp;
int main()
{
    scanf("%d%d",&n,&k);
    int ans = 0;
    for(int i=1;i<=n;i++)
    {
        scanf("%d",a+i);
        a[i] %= k;
        if(mp[(k-a[i])])
        {
            ans += 2;
            mp[k-a[i]]--;
        }
        else mp[a[i]]++;
    }
    printf("%d\n",ans);
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e5+7;
int n,k;
int a[maxn],b[maxn];
unordered_map<int,int> mp;
int main()
{
    scanf("%d%d",&n,&k);
    for(int i=1;i<=n;i++)
    {
        scanf("%d",a+i);
        b[i] = a[i]%k;
        mp[b[i]]++;
    }
    int cnt1 = 0,cnt2 = 0;
    for(int i=1;i<=n;i++)
    {
        if(!b[i]) cnt1++;
    }
    for(int i=1;i<=n;i++)
    {
        if(mp[k-b[i]]>0)
        {
            cnt2+=2;
            mp[k-b[i]]--;
            //mp[b[i]]--;
        }
    }
    printf("%d\n",(cnt1/2)*2+cnt2);
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e5+7;
int n,k;
int a[maxn],b[maxn];
unordered_map<int,int> mp;
int main()
{
    scanf("%d%d",&n,&k);
    for(int i=1;i<=n;i++)
    {
        scanf("%d",a+i);
        b[i] = a[i]%k;
        mp[b[i]]++;
    }
    int ans = 0;
    int cnt = 0;
    for(int i=1;i<=n;i++)
    {
        if(!b[i]) cnt++;
    }
    ans = cnt/2;
    ans *= 2;
    cnt = 0;
    for(int i=1;i<=n;i++)
    {
        if(mp[k-b[i]]>0 && mp[b[i]]>0 && b[i] && k-b[i])
        {
            cnt++;
            mp[k-b[i]]--;
            mp[b[i]]--;
        }
    }
    printf("%d\n",ans+cnt*2);
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e5+7;
int n,k;
int a[maxn],b[maxn];
unordered_map<int,int> mp;
int main()
{
    scanf("%d%d",&n,&k);
    for(int i=1;i<=n;i++)
    {
        scanf("%d",a+i);
        b[i] = a[i]%k;
        mp[b[i]]++;
    }
    int cnt1 = 0,cnt2 = 0;
    for(int i=1;i<=n;i++)
    {
        if(!b[i]) cnt1++;
    }
    for(int i=1;i<=n;i++)
    {
        if(mp[k-b[i]]>0 && mp[b[i]]>0)
        {
            cnt2++;
            mp[k-b[i]]--;
            mp[b[i]]--;
        }
    }
    printf("%d\n",(cnt1/2)*2+(cnt2/2)*2*2);
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e5+7;
int n,k;
int a[maxn],b[maxn];
unordered_map<int,int> mp;
int main()
{
    scanf("%d%d",&n,&k);
    for(int i=1;i<=n;i++)
    {
        scanf("%d",a+i);
        b[i] = a[i]%k;
        mp[b[i]]++;
    }
    int ans = 0;
    int cnt = 0;
    for(int i=1;i<=n;i++)
    {
        if(!b[i]) cnt++;
    }
    ans = cnt/2;
    ans *= 2;
    cnt = 0;
    for(int i=1;i<=n;i++)
    {
        if(mp[k-b[i]]>0 && mp[b[i]]>0)
        {
            cnt++;
            mp[k-b[i]]--;
            mp[b[i]]--;
        }
    }
    printf("%d\n",ans+cnt*2);
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e5+7;
int n,k;
int a[maxn],b[maxn];
unordered_map<int,int> mp;
int main()
{
    scanf("%d%d",&n,&k);
    int ans = 0;
    for(int i=1;i<=n;i++)
    {
        scanf("%d",a+i);
        a[i] %= k;
        if(mp[(k-a[i])%k])
        {
            ans += 2;
            mp[(k-a[i])%k]--;
        }
        else mp[a[i]]++;
    }
    printf("%d\n",ans);
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e5+7;
int n,k;
int a[maxn],b[maxn];
unordered_map<int,int> mp;
int main()
{
    scanf("%d%d",&n,&k);
    for(int i=1;i<=n;i++)
    {
        scanf("%d",a+i);
        b[i] = a[i]%k;
        mp[b[i]]++;
    }
    int cnt1 = 0,cnt2 = 0;
    for(int i=1;i<=n;i++)
    {
        if(!b[i]) cnt1++;
    }
    for(int i=1;i<=n;i++)
    {
        if(mp[k-b[i]]>0 && mp[b[i]]>0)
        {
            cnt2++;
            mp[k-b[i]]--;
            mp[b[i]]--;
        }
    }
    printf("%d\n",(cnt1/2)*2+(cnt2/2)*2);
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e5+7;
int n,k;
int a[maxn],b[maxn];
unordered_map<int,int> mp;
int main()
{
    scanf("%d%d",&n,&k);
    for(int i=1;i<=n;i++)
    {
        scanf("%d",a+i);
        b[i] = a[i]%k;
        mp[b[i]]++;
    }
    int ans = 0;
    int cnt = 0;
    for(int i=1;i<=n;i++)
    {
        if(!b[i]) cnt++;
    }
    ans = cnt/2;
    ans *= 2;
    cnt = 0;
    for(int i=1;i<=n;i++)
    {
        if(mp[k-b[i]]>0 && mp[b[i]]>0 && (k-b[i]!=b[i]))
        {
            cnt++;
            mp[k-b[i]]--;
            mp[b[i]]--;
        }
    }
    printf("%d\n",ans+cnt*2);
    return 0;
}


#include <bits/stdc++.h>
using namespace std;

int main()
{
    int i=0,j,n,k,d,m[20000],cnt=0;
    cin >> n >> k;
    while(n--)
    {
        cin >> d;
        if((d%k)==0)
            cnt++;
        else
        m[i++]=(d%k);
    }
    sort(m,m+i);
    if(cnt%2==1)
        cnt--;
    for(j=0;j<=i/2;j++)
    {
        if((m[j]+m[i-1-j])==k && j!=i/2)
        {
            cnt+=2;
        }
    }
    cout << cnt;
    return 0;
}


#include <bits/stdc++.h>
using namespace std;

int a[110];

int main()
{
    int n,k,cnt=0;
    cin >> n >> k;
    for(int i=0;i<n;i++)
    {
        int x;
        cin >> x;
        if(x%k==0)
            cnt++;
        else
            a[x%k]++;
    }
    if(cnt%2==1)
        cnt--;
    for(int i=1;i<k;i++)
    {
        while(a[i] && a[k-i])
        {
            if(i==k-i && a[i]==1) break;
            a[i]--,a[k-i]--,cnt+=2;
        }
    }
    cout << cnt;

    return 0;
}


#include <bits/stdc++.h>
using namespace std;

int main()
{
    int i=0,j,n,k,d,m[20000],cnt=0;
    cin >> n >> k;
    while(n--)
    {
        cin >> d;
        if((d%k)==0)
            cnt++;
        else
        m[i++]=(d%k);
    }
    sort(m,m+i);
    if(cnt%2==1)
        cnt-=1;
    for(j=0;j<=i/2;j++)
    {
        if((m[j]+m[i-1])==k && j!=i/2)
        {
            cnt+=2;
        }
    }
    cout << cnt;
    return 0;
}


#include <bits/stdc++.h>
using namespace std;

vector <int> m;

int main()
{
    int j=0,n,k,d,cnt=0;
    cin >> n >> k;
//    while(n--)
    for(int i=0;i<n;i++)
    {
        cin >> d;
        if(d%k==0)
            cnt++;
        else
            m.push_back(d%k);
//            m[j++] = d%k;
    }
    sort(m.begin(),m.end());
//    sort(m,m+n);
    if(cnt%2==1)
        cnt--;
    for(int i=0;i<=m.size()/2;i++)
    {
        if((m[i]+m[m.size()-1])==k && i!=m.size()/2)
        {
            cnt+=2;
        }
    }
    cout << cnt;
    return 0;
}


#include <bits/stdc++.h>
using namespace std;

int a[110];

int main()
{
    int n,k,cnt=0;
    cin >> n >> k;
    for(int i=0;i<n;i++)
    {
        int x;
        cin >> x;
        if(x%k==0)
            cnt++;
        else
            a[x%k]++;
    }
    if(cnt%2==1)
        cnt--;
    for(int i=1;i<k;i++)
    {
        while(a[i] && a[k-i])
        {
            a[i]--,a[k-i]--,cnt+=2;
        }
    }
    cout << cnt;

    return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    int a,b,c,e;
    cin >> a >> b;
    int m=0;
    map<int,int>mp;
    vector<int>vec;
    while(a--)
    {
        cin >> c;
        if(c%b==0)
        {
            m++;
        }
        else{
            vec.push_back(c%b);
            mp[c%b]++;

        }

    }
    int d=0;
    for(int i=0;i<vec.size();i++)
    {
        int l=vec[i];
        int k=b-vec[i];
       //cout << l << " " << k << endl;

        if(l==k && mp[l]>1)
        {
            d++;
            mp[k]--;
            mp[l]--;

        }
        else if(mp[k]>0 && mp[l]>0){
            mp[k]--;
            mp[l]--;
            d++;

        }

    }
    //cout << m << endl;
    m=m/2;
    //cout << m << " " << d << endl;
    cout << 2*m+2*d << endl;

}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    int a,b,c,e;
    cin >> a >> b;
    int m=0;
    map<int,int>mp;
    vector<int>vec;
    while(a--)
    {
        cin >> c;
        if(c%b==0)
        {
            m++;
        }
        else{
            vec.push_back(c%b);
            mp[c%b]++;

        }

    }
    int d=0;
    for(int i=0;i<vec.size();i++)
    {
        int l=vec[i];
        int k=b-vec[i];
       //cout << l << " " << k << endl;

        if(l==k && mp[l]>1)
        {
            d++;
            mp[k]--;
            mp[l]--;

        }
        else if(mp[k]>0){
            mp[k]--;
            mp[l]--;

        }

    }
    //cout << m << endl;
    m=m/2;
    //cout << m << " " << d << endl;
    cout << 2*m+2*d << endl;

}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    int a,b,c,e;
    cin >> a >> b;
    int m=0;
    map<int,int>mp;
    vector<int>vec;
    while(a--)
    {
        cin >> c;
        if(c%b==0)
        {
            m++;
        }
        else{
            vec.push_back(c%b);
            mp[c%b]++;

        }

    }
    int d=0;
    for(int i=0;i<vec.size();i++)
    {
        int l=vec[i];
        int k=b-vec[i];
       // cout << l << " " << k << endl;

        if(mp[k]>1)
        {
            d++;
            mp[k]--;

        }

    }
    //cout << m << endl;
    m=m/2;
    cout << 2*m+2*d << endl;

}