stablegradients/pie-gem5-pairs huggingface dataset:
// Slower C++ solution:
#include<cstdio>

#include<cstring>

#include<algorithm>

using namespace std;

 

const int MAXN=200005;

 

struct node{

    long long num;

    int id;

 

    bool operator<(const node &another)const

    {

        if(num==another.num)return id<another.id;

        return num<another.num;

    }

};

 

int n,k;

long long a[MAXN];

node b[MAXN];

 

int lowbit(int x)

{

    return (x&-x);

}

 

void modify(int x,int num)

{

    if(x==0){

        a[x]+=(long long)num;

        return;

    }

    while(x<=n){

        a[x]+=(long long)num;

        x+=lowbit(x);

    }

}

 

long long sum(int x)

{

    long long ans=a[0];

    while(x>0){

        ans+=a[x];

        x-=lowbit(x);

    }

    return ans;

}

 

int main()

{

    scanf("%d %d",&n,&k);

    b[0].num=0;b[0].id=0;

    for(int i=1;i<=n;i++){

        int x;

        scanf("%d",&x);

        b[i].num=b[i-1].num+(long long)(x-k);

        b[i].id=i;

    }

    sort(b,b+1+n);

    long long cnt=0;

    memset(a,0,sizeof(a));

    for(int i=0;i<=n;i++){

        if(b[i].id>0)cnt+=sum(b[i].id-1);

        modify(b[i].id,1);

    }

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

    return 0;

}


// Faster C++ solution for the same problem (measured speedup: 1.790347045273049x):
#include<bits/stdc++.h>

using namespace std;

int bit[200003],n,k;

pair<long long,int>a[200003]; 

int sum(int x){

	int ret=0;

	for(;x>=1;x-=x&(-x))ret+=bit[x];

	return ret;

}

void add(int x){

	for(;x<n+2;x+=x&(-x))bit[x]++; 

}

int main(){

	cin>>n>>k;

	for(int i=1;i<=n;i++)scanf("%lld",&a[i].first),a[i].first-=k,a[i].second=i+1;

	for(int i=0;i<n;i++)a[i+1].first+=a[i].first;

	for(int i=n;i>=0;i--)a[i+1]=a[i];

	a[1].second=1;

	sort(a+1,a+n+2);

	long long ans=0;

	for(int i=1;i<=n+1;i++){

		ans+=sum(a[i].second);

		//cout<<a[i].second<<' '<<sum(a[i].second)<<endl;

		add(a[i].second);

	}

	cout<<ans;

}
// Slower C++ solution:
#include<cstdio>

#include<ctime>

#include<cmath>

#include<iostream>

#include<algorithm>

using namespace std;

const int MAXN = 200005;

int n, m;

long long k, ans;

long long a[MAXN];

long long t[MAXN];

long long b[MAXN];

long long Query(int x)

{

	long long ret = 0;

	while(x)

	{

		ret += b[x];

		x -= (x & -x);

	}

	return ret;

}

void Insert(int x)

{

	while (x <= m+1)

	{

		++b[x];

		x += (x & -x);

	}

}

int main()

{

	scanf("%d%lld", &n, &k);

	for (int i = 1; i <= n; ++i)

	{

		scanf("%lld", &a[i]);

		t[i] = (a[i] += a[i-1] - k);

	}

	sort(t, t + n + 1);

	m = unique(t, t + n + 1) - t + 1;

	for (int i = 0; i <= n; ++i)

	{

		a[i] = lower_bound(t, t + m, a[i]) - t + 1;

		ans += Query(a[i]);

		Insert(a[i]);

	}

	printf("%lld", ans);

	return 0;

}

// Faster C++ solution for the same problem (measured speedup: 5.29594400220401x):
#include <cstdio>

#include <algorithm>



using namespace std;



typedef long long ll;



const int maxn=2e5+50;



int n,k,N,r[maxn];

ll ans,a[maxn],sum[maxn];



inline int read(int x=0,char c=getchar()) {

	while(c<'0'||c>'9') c=getchar();

	while(c>='0'&&c<='9') x=x*10+c-'0',c=getchar();

	return x;

}



ll c[maxn];



inline void add(int x,int v){for(;x<=N;x+=x&-x)c[x]+=v;}

inline int ask(int x){int y=0;for(;x;x-=x&-x)y+=c[x];return y;}



int main() {

	n=read();k=read();

	for(register int i=1;i<=n;++i) a[i]=read()-k; //转换为区间和大于等于0 

	for(register int i=1;i<=n;++i) if((sum[i]=(a[i]+=a[i-1]))>=0) ++ans;

	//处理前缀和的同时把区间左端点为1的情况直接算了 

	sort(sum+1,sum+1+n); N=unique(sum+1,sum+1+n)-sum-1; //不同前缀和的个数 

	for(register int i=1;i<=n;++i) r[i]=lower_bound(sum+1,sum+1+N,a[i])-sum; //离散化 

	for(register int i=1;i<=n;++i) ans+=ask(r[i]),add(r[i],1);

	//枚举右端点 看有多少个左端点满足要求 

	printf("%lld",ans);

	return 0;

}
// Slower C++ solution:
#include <iostream>

#include<stdio.h>

#include<string.h>

#include<math.h>

#include<queue>

#include<algorithm>

#define N 200500

#define LL long long

#define mem(a,b) memset(a,b,sizeof(a));

using namespace std;

LL sum[N],t[N];

LL tree[N];

int n,k,a,m,nn;

void add(int x)

{

    while(x<=nn)//nn为上限，要大于离散化后的最大的数字，

    {

        tree[x]++;

        x+=x&-x;//向上更新，树状数组核心代码。此处就不解释了，不会的先学树状数组。

    }

}

LL query(int x)

{

    LL num=0;

    while(x)

    {

        num+=tree[x];

        x-=x&-x;//向下求和

    }

    return num;

}

int main()

{

    mem(t,0);

    mem(tree,0);

    mem(sum,0);

    scanf("%d%d",&n,&k);

    nn=n+10;

    for(int i=1; i<=n; i++)

    {

        scanf("%d",&a);

        t[i]=sum[i]=sum[i-1]+a-k;//预处理出sum[i]数组（就是上面讲解的num数组）

    }//t[i]数组为离散化的辅助数组

    sort(t,t+n+1);//排序，排n+1个数字的序（包括了sum[0]）

    m=unique(t,t+n+1)-t;//去重

    for(int i=0; i<=n; i++)

        sum[i]=lower_bound(t,t+m+1,sum[i])-t+1;//离散化

    LL ans=0;

    for(int i=0;i<=n;i++)

    {

        ans+=query(sum[i]);//查询有多少个小于sum[i]的数字

        add(sum[i]);//更新树桩数组。

    }

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

}


// Faster C++ solution for the same problem (measured speedup: 3.3089769690416446x):
#include <bits/stdc++.h>

using namespace std;

#define FOR(i,a,b) for (int i=(a);i<=(b);++i)

#define ROF(i,a,b) for (int i=(a);i>=(b);--i)

typedef long long ll;

inline int read() {

	int x=0,s=1; char ch=getchar();

	while (ch<'0'||ch>'9') { if (ch=='-') s=-1; ch=getchar(); }

	while (ch>='0'&&ch<='9') { x=x*10+ch-'0'; ch=getchar(); }

	return s*x;

}



const int MAXN=200005,Mo=1000000007;

ll sum[MAXN];

int n,m,q,a[MAXN],b[MAXN],f[MAXN];

#define lowbit(x) ((x)&(-(x)))

void add(int x,int y){ for (;x<MAXN;x+=lowbit(x)) f[x]+=y; }

int getsum(int x){ int y=0; for (;x;x-=lowbit(x)) y+=f[x]; return y; }

int cmp(int i,int j){ return sum[i]<sum[j]; }

int main(){

	n=read(); m=read();

	b[0]=sum[0]=0;

	FOR(i,1,n) a[i]=read()-m,b[i]=i,sum[i]=sum[i-1]+a[i];

	sort(b,b+1+n,cmp);

	//FOR(i,0,n) printf("%lld%c",sum[i]," \n"[i==n]);

	//FOR(i,0,n) printf("%d%c",b[i]," \n"[i==n]);

	int k=1;

	FOR(i,0,n) {

		if (i&&sum[b[i]]!=sum[b[i-1]]) k++;

		a[b[i]]=k;

	}

	//FOR(i,0,n) printf("%d%c",a[i]," \n"[i==n]);

	memset(f,0,sizeof(f));

	ll ans=0;

	FOR(i,0,n) {

		ans+=getsum(a[i]);

		add(a[i],1);

	}

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

	

	return 0;

}



/*

*/
// Slower C++ solution:
#include <iostream>

#include<stdio.h>

#include<string.h>

#include<math.h>

#include<queue>

#include<algorithm>

#define N 200500

#define LL long long

#define mem(a,b) memset(a,b,sizeof(a));

using namespace std;

LL sum[N],t[N];

LL tree[N];

int n,k,a,m,nn;

void add(int x)

{

    while(x<=nn)//nn为上限，要大于离散化后的最大的数字，

    {

        tree[x]++;

        x+=x&-x;//向上更新，树状数组核心代码。此处就不解释了，不会的先学树状数组。

    }

}

LL query(int x)

{

    LL num=0;

    while(x)

    {

        num+=tree[x];

        x-=x&-x;//向下求和

    }

    return num;

}

int main()

{

    mem(t,0);

    mem(tree,0);

    mem(sum,0);

    scanf("%d%d",&n,&k);

    nn=n+10;

    for(int i=1; i<=n; i++)

    {

        scanf("%d",&a);

        t[i]=sum[i]=sum[i-1]+a-k;//预处理出sum[i]数组（就是上面讲解的num数组）

    }//t[i]数组为离散化的辅助数组

    sort(t,t+n+1);//排序，排n+1个数字的序（包括了sum[0]）

    m=unique(t,t+n+1)-t;//去重

    for(int i=0; i<=n; i++)

        sum[i]=lower_bound(t,t+m+1,sum[i])-t+1;//离散化

    LL ans=0;

    for(int i=0;i<=n;i++)

    {

        ans+=query(sum[i]);//查询有多少个小于sum[i]的数字

        add(sum[i]);//更新树桩数组。

    }

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

}


// Faster C++ solution for the same problem (measured speedup: 5.903816299667818x):
#include<cstdio>

#include<cstring>

#include<cmath>

#include<algorithm>

#include<iostream>

#include<vector>

#include<queue>

#include<stack>

#include<map>

#include<set>

using namespace std;

#define lowbit(x) x&(-x);

typedef long long ll;

const ll inf=1e18;

const int N=2e5+3;

int n,k;

ll a[N],b[N],c[N],d[N];

int sum(int x){

	int ans=0;

	while(x){

		ans+=c[x];

		x-=lowbit(x);

	}

	return ans;

}

void modify(int x){

	while(x<N){

		c[x]++;

		x+=lowbit(x);

	}

}

int main(){

	ll ans=0;

    cin>>n>>k;

    for(int i=1;i<=n;i++){

    	cin>>a[i];

    	a[i]+=a[i-1];

    	b[i]=a[i]-1LL*i*k;

    	d[i]=b[i];

    }

    sort(b+1,b+1+n);

    int m=unique(b+1,b+1+n)-b;

    for(int i=1;i<=n;i++) a[i]=lower_bound(b+1,b+1+m,d[i])-b;

    for(int i=1;i<=n;i++){

    	if(d[i]>=0) ans++;

    	ans+=sum(a[i]);

    	modify(a[i]);

    }

    cout<<ans<<endl;

    return 0;

}
// Slower C++ solution:
#include <bits/stdc++.h>

using namespace std;

#define FOR(i,a,b) for (int i=(a);i<=(b);++i)

#define ROF(i,a,b) for (int i=(a);i>=(b);--i)

typedef long long ll;

inline int read() {

	int x=0,s=1; char ch=getchar();

	while (ch<'0'||ch>'9') { if (ch=='-') s=-1; ch=getchar(); }

	while (ch>='0'&&ch<='9') { x=x*10+ch-'0'; ch=getchar(); }

	return s*x;

}



const int MAXN=200005,Mo=1000000007;

ll sum[MAXN];

int n,m,q,a[MAXN],b[MAXN],f[MAXN];

#define lowbit(x) ((x)&(-(x)))

void add(int x,int y){ for (;x<MAXN;x+=lowbit(x)) f[x]+=y; }

int getsum(int x){ int y=0; for (;x;x-=lowbit(x)) y+=f[x]; return y; }

int cmp(int i,int j){ return sum[i]<sum[j]; }

int main(){

	n=read(); m=read();

	b[0]=sum[0]=0;

	FOR(i,1,n) a[i]=read()-m,b[i]=i,sum[i]=sum[i-1]+a[i];

	sort(b,b+1+n,cmp);

	//FOR(i,0,n) printf("%lld%c",sum[i]," \n"[i==n]);

	//FOR(i,0,n) printf("%d%c",b[i]," \n"[i==n]);

	int k=1;

	FOR(i,0,n) {

		if (i&&sum[b[i]]!=sum[b[i-1]]) k++;

		a[b[i]]=k;

	}

	//FOR(i,0,n) printf("%d%c",a[i]," \n"[i==n]);

	memset(f,0,sizeof(f));

	ll ans=0;

	FOR(i,0,n) {

		ans+=getsum(a[i]);

		add(a[i],1);

	}

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

	

	return 0;

}



/*

*/


// Faster C++ solution for the same problem (measured speedup: 1.7841817440565921x):
#include<cstdio>

#include<cstring>

#include<cmath>

#include<algorithm>

#include<iostream>

#include<vector>

#include<queue>

#include<stack>

#include<map>

#include<set>

using namespace std;

#define lowbit(x) x&(-x);

typedef long long ll;

const ll inf=1e18;

const int N=2e5+3;

int n,k;

ll a[N],b[N],c[N],d[N];

int sum(int x){

	int ans=0;

	while(x){

		ans+=c[x];

		x-=lowbit(x);

	}

	return ans;

}

void modify(int x){

	while(x<N){

		c[x]++;

		x+=lowbit(x);

	}

}

int main(){

	ll ans=0;

    cin>>n>>k;

    for(int i=1;i<=n;i++){

    	cin>>a[i];

    	a[i]+=a[i-1];

    	b[i]=a[i]-1LL*i*k;

    	d[i]=b[i];

    }

    sort(b+1,b+1+n);

    int m=unique(b+1,b+1+n)-b;

    for(int i=1;i<=n;i++) a[i]=lower_bound(b+1,b+1+m,d[i])-b;

    for(int i=1;i<=n;i++){

    	if(d[i]>=0) ans++;

    	ans+=sum(a[i]);

    	modify(a[i]);

    }

    cout<<ans<<endl;

    return 0;

}
// Slower C++ solution:
#include <iostream>

#include<stdio.h>

#include<string.h>

#include<math.h>

#include<queue>

#include<algorithm>

#define N 200500

#define LL long long

#define mem(a,b) memset(a,b,sizeof(a));

using namespace std;

LL sum[N],t[N];

LL tree[N];

int n,k,a,m,nn;

void add(int x)

{

    while(x<=nn)//nn为上限，要大于离散化后的最大的数字，

    {

        tree[x]++;

        x+=x&-x;//向上更新，树状数组核心代码。此处就不解释了，不会的先学树状数组。

    }

}

LL query(int x)

{

    LL num=0;

    while(x)

    {

        num+=tree[x];

        x-=x&-x;//向下求和

    }

    return num;

}

int main()

{

    mem(t,0);

    mem(tree,0);

    mem(sum,0);

    scanf("%d%d",&n,&k);

    nn=n+10;

    for(int i=1; i<=n; i++)

    {

        scanf("%d",&a);

        t[i]=sum[i]=sum[i-1]+a-k;//预处理出sum[i]数组（就是上面讲解的num数组）

    }//t[i]数组为离散化的辅助数组

    sort(t,t+n+1);//排序，排n+1个数字的序（包括了sum[0]）

    m=unique(t,t+n+1)-t;//去重

    for(int i=0; i<=n; i++)

        sum[i]=lower_bound(t,t+m+1,sum[i])-t+1;//离散化

    LL ans=0;

    for(int i=0;i<=n;i++)

    {

        ans+=query(sum[i]);//查询有多少个小于sum[i]的数字

        add(sum[i]);//更新树桩数组。

    }

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

}


// Faster C++ solution for the same problem (measured speedup: 5.984486621380079x):
#include<bits/stdc++.h>

#define lson(x) (x<<1)

#define rson(x) ((x<<1)|1)

using namespace std;



typedef long long ll;

typedef vector<int> vii;



const int maxn=200003;

const int inf=0x3f3f3f3f;



int n,k,b[maxn];

ll pre[maxn],a[maxn],res,sum[maxn<<2];



void update(int id,int l,int r,int pos){

	++sum[id];

	if(l==r) return ;

	int mid=(l+r)/2;

	if(mid>=pos) update(lson(id),l,mid,pos);

	else update(rson(id),mid+1,r,pos);

}



ll query(int id,int l,int r,int L,int R){

	if(l>=L&&r<=R) return sum[id];

	if(l>R||L>r) return 0;

	int mid=(l+r)/2;

	return query(lson(id),l,mid,L,R)

		  +query(rson(id),mid+1,r,L,R);

}



int main(){

	scanf("%d%d",&n,&k);

	for(int i=1;i<=n;++i){

		scanf("%lld",&pre[i]);

		pre[i]-=k;

		pre[i]+=pre[i-1];

		a[i]=pre[i];

		if(a[i]>=0) ++res;

	}

	sort(a+1,a+n+1);

	int U=unique(a+1,a+n+1)-a-1;

	for(int i=1;i<=n;++i)

		b[i]=lower_bound(a+1,a+U+1,pre[i])-a;

	for(int i=1;i<=n;++i){

		res+=query(1,1,n,1,b[i]);

		update(1,1,n,b[i]);

	}

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

	return 0;

}
// Slower C++ solution:
#include <bits/stdc++.h>

using namespace std;

#define FOR(i,a,b) for (int i=(a);i<=(b);++i)

#define ROF(i,a,b) for (int i=(a);i>=(b);--i)

typedef long long ll;

inline int read() {

	int x=0,s=1; char ch=getchar();

	while (ch<'0'||ch>'9') { if (ch=='-') s=-1; ch=getchar(); }

	while (ch>='0'&&ch<='9') { x=x*10+ch-'0'; ch=getchar(); }

	return s*x;

}



const int MAXN=200005,Mo=1000000007;

ll sum[MAXN];

int n,m,q,a[MAXN],b[MAXN],f[MAXN];

#define lowbit(x) ((x)&(-(x)))

void add(int x,int y){ for (;x<MAXN;x+=lowbit(x)) f[x]+=y; }

int getsum(int x){ int y=0; for (;x;x-=lowbit(x)) y+=f[x]; return y; }

int cmp(int i,int j){ return sum[i]<sum[j]; }

int main(){

	n=read(); m=read();

	b[0]=sum[0]=0;

	FOR(i,1,n) a[i]=read()-m,b[i]=i,sum[i]=sum[i-1]+a[i];

	sort(b,b+1+n,cmp);

	//FOR(i,0,n) printf("%lld%c",sum[i]," \n"[i==n]);

	//FOR(i,0,n) printf("%d%c",b[i]," \n"[i==n]);

	int k=1;

	FOR(i,0,n) {

		if (i&&sum[b[i]]!=sum[b[i-1]]) k++;

		a[b[i]]=k;

	}

	//FOR(i,0,n) printf("%d%c",a[i]," \n"[i==n]);

	memset(f,0,sizeof(f));

	ll ans=0;

	FOR(i,0,n) {

		ans+=getsum(a[i]);

		add(a[i],1);

	}

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

	

	return 0;

}



/*

*/


// Faster C++ solution for the same problem (measured speedup: 1.8085609774169336x):
#include<bits/stdc++.h>

#define lson(x) (x<<1)

#define rson(x) ((x<<1)|1)

using namespace std;



typedef long long ll;

typedef vector<int> vii;



const int maxn=200003;

const int inf=0x3f3f3f3f;



int n,k,b[maxn];

ll pre[maxn],a[maxn],res,sum[maxn<<2];



void update(int id,int l,int r,int pos){

	++sum[id];

	if(l==r) return ;

	int mid=(l+r)/2;

	if(mid>=pos) update(lson(id),l,mid,pos);

	else update(rson(id),mid+1,r,pos);

}



ll query(int id,int l,int r,int L,int R){

	if(l>=L&&r<=R) return sum[id];

	if(l>R||L>r) return 0;

	int mid=(l+r)/2;

	return query(lson(id),l,mid,L,R)

		  +query(rson(id),mid+1,r,L,R);

}



int main(){

	scanf("%d%d",&n,&k);

	for(int i=1;i<=n;++i){

		scanf("%lld",&pre[i]);

		pre[i]-=k;

		pre[i]+=pre[i-1];

		a[i]=pre[i];

		if(a[i]>=0) ++res;

	}

	sort(a+1,a+n+1);

	int U=unique(a+1,a+n+1)-a-1;

	for(int i=1;i<=n;++i)

		b[i]=lower_bound(a+1,a+U+1,pre[i])-a;

	for(int i=1;i<=n;++i){

		res+=query(1,1,n,1,b[i]);

		update(1,1,n,b[i]);

	}

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

	return 0;

}
// Slower C++ solution:
#include <iostream>

#include<stdio.h>

#include<string.h>

#include<math.h>

#include<queue>

#include<algorithm>

#define N 200500

#define LL long long

#define mem(a,b) memset(a,b,sizeof(a));

using namespace std;

LL sum[N],t[N];

LL tree[N];

int n,k,a,m,nn;

void add(int x)

{

    while(x<=nn)//nn为上限，要大于离散化后的最大的数字，

    {

        tree[x]++;

        x+=x&-x;//向上更新，树状数组核心代码。此处就不解释了，不会的先学树状数组。

    }

}

LL query(int x)

{

    LL num=0;

    while(x)

    {

        num+=tree[x];

        x-=x&-x;//向下求和

    }

    return num;

}

int main()

{

    mem(t,0);

    mem(tree,0);

    mem(sum,0);

    scanf("%d%d",&n,&k);

    nn=n+10;

    for(int i=1; i<=n; i++)

    {

        scanf("%d",&a);

        t[i]=sum[i]=sum[i-1]+a-k;//预处理出sum[i]数组（就是上面讲解的num数组）

    }//t[i]数组为离散化的辅助数组

    sort(t,t+n+1);//排序，排n+1个数字的序（包括了sum[0]）

    m=unique(t,t+n+1)-t;//去重

    for(int i=0; i<=n; i++)

        sum[i]=lower_bound(t,t+m+1,sum[i])-t+1;//离散化

    LL ans=0;

    for(int i=0;i<=n;i++)

    {

        ans+=query(sum[i]);//查询有多少个小于sum[i]的数字

        add(sum[i]);//更新树桩数组。

    }

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

}


// Faster C++ solution for the same problem (measured speedup: 5.977977469488403x):
#include <iostream>

#include <cstdio>

#include <algorithm>

#include <cstring>

#include <map>

using namespace std;

typedef long long ll;



map<int, int> ma;

const int MAXN = 200005, MAXM = 800005;

struct node{

    int l, r;

    ll sum;

}tree[MAXM];

int n, c;

ll ans;

ll a[MAXN], b[MAXN];



void pushup(int q){

    tree[q].sum = tree[q << 1].sum + tree[q << 1 | 1].sum;

}



void build(int q, int l, int r){

    tree[q].l = l;

    tree[q].r = r;

    if(l == r){

        tree[q].sum = 0;

        return;

    }

    int mid = (l + r) >> 1;

    build(q << 1, l, mid);

    build(q << 1 | 1, mid + 1, r);

    pushup(q);

}



void update(int q, int x, int y){

    if(tree[q].l > x || tree[q].r < x) return;

    if(tree[q].l == x && tree[q].r == x){

        tree[q].sum += y;

        return;

    }

    update(q << 1, x, y);

    update(q << 1 | 1, x, y);

    pushup(q);

}



void query(int q, int l, int r){

    if(tree[q].l > r || tree[q].r < l) return;

    if(tree[q].l >= l && tree[q].r <= r){

        ans += tree[q].sum;

        return;

    }

    query(q << 1, l, r);

    query(q << 1 | 1, l, r);

}



void solve(){

    sort(b, b + n + 1);

    c = unique(b, b + n + 1) - b;

    for (int i = 0; i <= n; i++)

        a[i] = lower_bound(b, b + c + 1, a[i]) - b + 1;

}



int main(){

    int k, m = 0;

    scanf("%d%d", &n, &k);

    ll res = 0;

    for(int i = 1; i <= n; i++){

        scanf("%lld", &a[i]);

        a[i] -= k; a[i] += a[i - 1];

        b[i] = a[i];

    }

    solve();

    build(1, 0, n);

    for(int i = 0; i <= n; i++){

        ans = 0;

        query(1, 0, a[i]);

        res += ans;

        update(1, a[i], 1);

    }

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

    return 0;

}
// Slower C++ solution:
#include <bits/stdc++.h>

using namespace std;

#define FOR(i,a,b) for (int i=(a);i<=(b);++i)

#define ROF(i,a,b) for (int i=(a);i>=(b);--i)

typedef long long ll;

inline int read() {

	int x=0,s=1; char ch=getchar();

	while (ch<'0'||ch>'9') { if (ch=='-') s=-1; ch=getchar(); }

	while (ch>='0'&&ch<='9') { x=x*10+ch-'0'; ch=getchar(); }

	return s*x;

}



const int MAXN=200005,Mo=1000000007;

ll sum[MAXN];

int n,m,q,a[MAXN],b[MAXN],f[MAXN];

#define lowbit(x) ((x)&(-(x)))

void add(int x,int y){ for (;x<MAXN;x+=lowbit(x)) f[x]+=y; }

int getsum(int x){ int y=0; for (;x;x-=lowbit(x)) y+=f[x]; return y; }

int cmp(int i,int j){ return sum[i]<sum[j]; }

int main(){

	n=read(); m=read();

	b[0]=sum[0]=0;

	FOR(i,1,n) a[i]=read()-m,b[i]=i,sum[i]=sum[i-1]+a[i];

	sort(b,b+1+n,cmp);

	//FOR(i,0,n) printf("%lld%c",sum[i]," \n"[i==n]);

	//FOR(i,0,n) printf("%d%c",b[i]," \n"[i==n]);

	int k=1;

	FOR(i,0,n) {

		if (i&&sum[b[i]]!=sum[b[i-1]]) k++;

		a[b[i]]=k;

	}

	//FOR(i,0,n) printf("%d%c",a[i]," \n"[i==n]);

	memset(f,0,sizeof(f));

	ll ans=0;

	FOR(i,0,n) {

		ans+=getsum(a[i]);

		add(a[i],1);

	}

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

	

	return 0;

}



/*

*/


// Faster C++ solution for the same problem (measured speedup: 1.8065938582884007x):
#include <iostream>

#include <cstdio>

#include <algorithm>

#include <cstring>

#include <map>

using namespace std;

typedef long long ll;



map<int, int> ma;

const int MAXN = 200005, MAXM = 800005;

struct node{

    int l, r;

    ll sum;

}tree[MAXM];

int n, c;

ll ans;

ll a[MAXN], b[MAXN];



void pushup(int q){

    tree[q].sum = tree[q << 1].sum + tree[q << 1 | 1].sum;

}



void build(int q, int l, int r){

    tree[q].l = l;

    tree[q].r = r;

    if(l == r){

        tree[q].sum = 0;

        return;

    }

    int mid = (l + r) >> 1;

    build(q << 1, l, mid);

    build(q << 1 | 1, mid + 1, r);

    pushup(q);

}



void update(int q, int x, int y){

    if(tree[q].l > x || tree[q].r < x) return;

    if(tree[q].l == x && tree[q].r == x){

        tree[q].sum += y;

        return;

    }

    update(q << 1, x, y);

    update(q << 1 | 1, x, y);

    pushup(q);

}



void query(int q, int l, int r){

    if(tree[q].l > r || tree[q].r < l) return;

    if(tree[q].l >= l && tree[q].r <= r){

        ans += tree[q].sum;

        return;

    }

    query(q << 1, l, r);

    query(q << 1 | 1, l, r);

}



void solve(){

    sort(b, b + n + 1);

    c = unique(b, b + n + 1) - b;

    for (int i = 0; i <= n; i++)

        a[i] = lower_bound(b, b + c + 1, a[i]) - b + 1;

}



int main(){

    int k, m = 0;

    scanf("%d%d", &n, &k);

    ll res = 0;

    for(int i = 1; i <= n; i++){

        scanf("%lld", &a[i]);

        a[i] -= k; a[i] += a[i - 1];

        b[i] = a[i];

    }

    solve();

    build(1, 0, n);

    for(int i = 0; i <= n; i++){

        ans = 0;

        query(1, 0, a[i]);

        res += ans;

        update(1, a[i], 1);

    }

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

    return 0;

}
// Slower C++ solution:
#include <iostream>

#include<stdio.h>

#include<string.h>

#include<math.h>

#include<queue>

#include<algorithm>

#define N 200500

#define LL long long

#define mem(a,b) memset(a,b,sizeof(a));

using namespace std;

LL sum[N],t[N];

LL tree[N];

int n,k,a,m,nn;

void add(int x)

{

    while(x<=nn)//nn为上限，要大于离散化后的最大的数字，

    {

        tree[x]++;

        x+=x&-x;//向上更新，树状数组核心代码。此处就不解释了，不会的先学树状数组。

    }

}

LL query(int x)

{

    LL num=0;

    while(x)

    {

        num+=tree[x];

        x-=x&-x;//向下求和

    }

    return num;

}

int main()

{

    mem(t,0);

    mem(tree,0);

    mem(sum,0);

    scanf("%d%d",&n,&k);

    nn=n+10;

    for(int i=1; i<=n; i++)

    {

        scanf("%d",&a);

        t[i]=sum[i]=sum[i-1]+a-k;//预处理出sum[i]数组（就是上面讲解的num数组）

    }//t[i]数组为离散化的辅助数组

    sort(t,t+n+1);//排序，排n+1个数字的序（包括了sum[0]）

    m=unique(t,t+n+1)-t;//去重

    for(int i=0; i<=n; i++)

        sum[i]=lower_bound(t,t+m+1,sum[i])-t+1;//离散化

    LL ans=0;

    for(int i=0;i<=n;i++)

    {

        ans+=query(sum[i]);//查询有多少个小于sum[i]的数字

        add(sum[i]);//更新树桩数组。

    }

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

}


// Faster C++ solution for the same problem (measured speedup: 5.782949031864275x):
#include <bits/stdc++.h>

#include <ext/pb_ds/assoc_container.hpp> 

#include <ext/pb_ds/tree_policy.hpp> 

using namespace std;

using namespace __gnu_pbds;   

#define ordered_set tree<pll, null_type,less<pll>, rb_tree_tag,tree_order_statistics_node_update> 

#define ll long long int

#define ff first

#define ss second

#define pb push_back

#define mp make_pair

#define pll pair<ll,ll>

#define all(x) x.begin(),x.end()

#define sz(x) (ll)x.size() 



ll p[200005],a[200005];

map<ll,ll>M;

int main()

{

    ios_base::sync_with_stdio(false);

    ll n,i,j,k,x,y,t,m;



    cin >> n >> k;

    for(i=1;i<=n;i++)

        cin >> a[i];



    for(i=1;i<=n;i++)

        p[i]=p[i-1]+a[i];



    ll ans=0;

    ordered_set os;

    for(i=1;i<=n;i++)

    {

        if(p[i]>=k*i)

            ans++;



        x=p[i]-k*i;

        ll c=0;

        if(M.find(x)!=M.end())

            c=M[x];



        ans+=(ll)os.order_of_key({x,-i})+c;

        M[x]++;

        os.insert({x,-i});

    }

    cout<<ans<<endl;

}