stablegradients/pie-gem5-bysrc huggingface dataset:
// Original C++ solution (slower):
#include<cstdio>

#include<cstring>

#include<algorithm>

using std::scanf;

using std::printf;

using std::memset;

struct node

{

  long long data;

  int id;

  bool operator< (const node& o) const

  { return this->data < o.data;}

};



typedef long long llong;

const int maxn = 200010;



llong treeset[maxn];

llong end[maxn];

node rec[maxn];

llong n;

llong k;



inline int lowbit(int x)

{ return x&(-x);}



void add(int x, llong d)

{

  while(x <= n)

  {

    treeset[x] += d;

    x += lowbit(x);

  }

}



llong sum(int x)

{

  llong ans = 0;

  while(x)

  {

    ans += treeset[x];

    x -= lowbit(x);

  }

  return ans;

}



int main()

{

  llong tmp;

  llong ans = 0;

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

  memset(rec, 0, sizeof(rec));

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

  {

    scanf("%lld", &tmp);

    rec[i].data = rec[i-1].data +tmp-k;

    rec[i].id = i;

  }

  std::sort(rec+1, rec+1+n);

  end[rec[1].id] = 1;

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

  {

    if(rec[i].data != rec[i-1].data)

    { end[rec[i].id] = i;}

    else

    { end[rec[i].id] = end[rec[i-1].id];}

  }

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

  {

    add(end[i], 1);

    ans += sum(n) - sum(end[i]);

  }

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

  {

    if(rec[i].data < 0)

    { ++ans;}

  }

  ans = n*(n+1)/2 - ans;

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

}


// Optimized solution to the same problem (faster):
#include <cstdio>

#include <cstring>

#include <algorithm>

using namespace std;

typedef long long ll;



const int MAX_N = 200000;



ll cnt = 0ll;

int n;

ll K, a[MAX_N + 10], s[MAX_N + 10], b[MAX_N + 10], t[MAX_N + 10];



void merge_sort(ll* A, int x, int y, ll* T) {

    if (y - x > 1) {

        int m = x + (y - x) / 2;

        int p = x, q = m, i = x;

        merge_sort(A, x, m, T);

        merge_sort(A, m, y, T);

        while (p < m || q < y) {

            if (q >= y || (p < m && A[p] <= A[q])) T[i++] = A[p++];

            else { T[i++] = A[q++]; cnt += m - p; }

        }

        for (i = x; i < y; i++) A[i] = T[i];

    }

}



int main() {

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

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

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

        s[i] = a[i] + (i ? s[i - 1] : 0);

        b[i] = (i ? s[i - 1] : 0) - K * i;

    }

    b[n] = s[n - 1] - n * K;

    merge_sort(b, 0, n + 1, t);

    printf("%lld\n", (ll)n * (n + 1) / 2 - cnt);

    return 0;

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#include<iostream>

#include<cstring>

#include<algorithm>

#include<cmath>

#include<cstdlib>

#include<cstdio>

#include<set>

#include<queue>

#include<map>

using namespace std;

long long s[200005],ts[200005],in[200005];

void p(int pos)

{

	while(pos<=200003)

	{

		in[pos]+=1;

		pos+=pos&(-pos);

	}

	

}

long long sum(int n)

{

	long long sum=0;

	while(n>0)

	{

		sum+=in[n];

		n-=n&(-n);

	}

	return sum;

}

int main()

{



	int n,k,x;

	long long ans=0;

	memset(s,0,sizeof(s));

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

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

	{

		scanf("%d",&x),s[i]=x-k+s[i-1],ts[i]=s[i];

		if(s[i]>=0)

		ans++;

		}

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

	int size=unique(ts+1,ts+1+n)-ts+1;

	for(int i=1;i<=n;i++)   s[i]=lower_bound(ts+1,ts+1+size,s[i])-ts;

	memset(in,0,sizeof(in));

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

		{

			ans+=sum(s[i]);

			p(s[i]);

		}

	

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

	return 0;

 } 

// Optimized solution to the same problem (faster):
#include<bits/stdc++.h>

using namespace std;

#define mod 1000000007

#define MOD(x) ((x)%mod)

int n;

long long mean;

long long a[200005]; 

long long s[200005]; 

long long temp[200005]; 

long long ans;

void merge(int l,int r)

{

	int m=(l+r)/2;

	int h1=l,h2=m+1;

	int t1=m,t2=r;

	if(h1<t1) merge(h1,t1);

	if(h2<t2) merge(h2,t2);

	for(int i=l;i<=r;i++)	

	{

		if(h1<=t1&&h2<=t2)

		{

			if(s[h1]>s[h2])

			{

				temp[i]=s[h1++];

			}

			else

			{

				temp[i]=s[h2++];

				ans+=t1-h1+1;

			}

		}

		else if(h1<=t1)

		{

			temp[i]=s[h1++];

		}

		else

		{

			temp[i]=s[h2++];

		}

	}

	for(int i=l;i<=r;i++)

		s[i]=temp[i];

}

int main()

{

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

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

	{

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

		a[i]-=mean;

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

	}

	merge(1,n);

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

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

	printf("%lld",ans);

	return 0;

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#include <iostream>

#include <cstring>

#include <algorithm>

using namespace std;

const int N = 2e5 + 10;

int t[N];

int lowbit(int x){return x&(-x);}

void add(int x){

    while(x<N){

        t[x]++;

        x+=lowbit(x);

    }

}

long long sum(int x){

    long long ans=0;

    while(x){

        ans+=t[x];

        x-=lowbit(x);

    }

    return ans;

}

struct node{int id;long long val;};

node arr[N];

bool comp(node p1,node p2){

    return p1.val<p2.val;

}

int num[N];

int main(){

    std::ios::sync_with_stdio(false);

    int n,k;

    while(cin>>n>>k){

        memset(t,0,sizeof(t));

        long long a;

        arr[0].id = 0;

        arr[0].val = 0;

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

            arr[i].id = i;

            cin>>a;

            arr[i].val = a-k;

        }

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

            arr[i].val += arr[i-1].val;

        }

        sort(arr,arr+n+1,comp);

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

            if(i>0&&arr[i].val==arr[i-1].val)num[arr[i].id] = num[arr[i-1].id];

            else num[arr[i].id] = i+1;

        }

        long long ans = 0;

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

            int x = num[i];

            ans += sum(x);

            add(x);

        }

        cout<<ans<<endl;

    }

}


// Optimized solution to the same problem (faster):
#include<bits/stdc++.h>

using namespace std;

#define mod 1000000007

#define MOD(x) ((x)%mod)

int n;

long long mean;

long long a[200005]; 

long long s[200005]; 

long long temp[200005]; 

long long ans;

void merge(int l,int r)

{

	int m=(l+r)/2;

	int h1=l,h2=m+1;

	int t1=m,t2=r;

	if(h1<t1) merge(h1,t1);

	if(h2<t2) merge(h2,t2);

	for(int i=l;i<=r;i++)	

	{

		if(h1<=t1&&h2<=t2)

		{

			if(s[h1]>s[h2])

			{

				temp[i]=s[h1++];

			}

			else

			{

				temp[i]=s[h2++];

				ans+=t1-h1+1;

			}

		}

		else if(h1<=t1)

		{

			temp[i]=s[h1++];

		}

		else

		{

			temp[i]=s[h2++];

		}

	}

	for(int i=l;i<=r;i++)

		s[i]=temp[i];

}

int main()

{

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

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

	{

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

		a[i]-=mean;

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

	}

	merge(1,n);

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

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

	printf("%lld",ans);

	return 0;

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#include <algorithm>

#include <iostream>

#include <cstring>

#include <cstdio>

#include <cmath>

#include <map>

using namespace std;



int n;

long long m;

long long sum[300000];

long long c[300000];

long long d[300000];



int lowbit(int x){

	return x & -x;

}



void update(int x){

	while (x<=n+10){

		c[x]+=1;

		x+=lowbit(x);

	}

}



int query(int x){

	int s=0;

	while (x>0){

		s+=c[x];

		x-=lowbit(x);

	}

	return s;

}



struct o_O{

	long long b;

	int d;

}p[600000];



bool cmp(o_O a,o_O b){

	return a.b<b.b;

}



int main(){

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

	long long w;

	sum[0]=0;

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

		scanf("%lld",&w);

		sum[i]=sum[i-1]+w;

	}

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

		sum[i]=sum[i]-m*i;

		p[i].b=sum[i];

		p[i].d=i;

	}

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

	sum[p[0].d]=1;

	int n1=1;

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

		if (p[i].b==p[i-1].b){

			sum[p[i].d]=n1;

		}else {

			n1++;

			sum[p[i].d]=n1;

		}

	}

	memset(c,0,sizeof(c));

	long long ans=0;

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

		ans+=query(sum[i]);

		update(sum[i]); 

	}

	printf("%lld",ans);

	return 0;

} 

// Optimized solution to the same problem (faster):
#include<bits/stdc++.h>

using namespace std;

#define mod 1000000007

#define MOD(x) ((x)%mod)

int n;

long long mean;

long long a[200005]; 

long long s[200005]; 

long long temp[200005]; 

long long ans;

void merge(int l,int r)

{

	int m=(l+r)/2;

	int h1=l,h2=m+1;

	int t1=m,t2=r;

	if(h1<t1) merge(h1,t1);

	if(h2<t2) merge(h2,t2);

	for(int i=l;i<=r;i++)	

	{

		if(h1<=t1&&h2<=t2)

		{

			if(s[h1]>s[h2])

			{

				temp[i]=s[h1++];

			}

			else

			{

				temp[i]=s[h2++];

				ans+=t1-h1+1;

			}

		}

		else if(h1<=t1)

		{

			temp[i]=s[h1++];

		}

		else

		{

			temp[i]=s[h2++];

		}

	}

	for(int i=l;i<=r;i++)

		s[i]=temp[i];

}

int main()

{

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

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

	{

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

		a[i]-=mean;

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

	}

	merge(1,n);

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

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

	printf("%lld",ans);

	return 0;

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#include<iostream>

#include<cstdio>

#include<cstring>

#include<algorithm>

#include<map>

using namespace std;

 

const int MAXN=200005;

 

int n,k;

long long a[MAXN],s[MAXN],b[MAXN];

map<long long,int> mp;

 

int lowbit(int x)

{

    return (x&-x);

}

 

void modify(int x,int num)

{

    while(x<=n+1){

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

        x+=lowbit(x);

    }

}

 

long long sum(int x)

{

    long long ans=0;

    while(x>0){

        ans+=a[x];

        x-=lowbit(x);

    }

    return ans;

}

 

int main()

{

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

    s[0]=0;b[0]=0;

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

        int x;

        scanf("%d",&x);

        s[i]=s[i-1]+(long long)(x-k);

        b[i]=s[i];

    }

    sort(b,b+1+n);

    int tot=0;

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

        if(!mp.count(b[i]))mp[b[i]]=++tot; 

    long long cnt=0;

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

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

        cnt+=sum(mp[s[i]]);

        modify(mp[s[i]],1);

    }

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

    return 0;

} 

// Optimized solution to the same problem (faster):
#include <bits/stdc++.h>

#include <ext/pb_ds/assoc_container.hpp>

#include <ext/pb_ds/tree_policy.hpp>



using namespace __gnu_pbds;

using namespace std;



template<typename T>

using Tree = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;



#define loop(i,n) for(int i = 0;i < int(n);i++)

#define rloop(i,n) for(int i = int(n);i >= 0;i--)

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

#define SZ(c) int(c.size())

#define ALL(c) c.begin(), c.end()

#define RALL(c) c.rbegin(), c.rend()

#define PI acos(-1)

#define pb push_back

#define mp make_pair

#define fr first

#define sc second

#define sfi1(v) scanf("%d",&v)

#define sfi2(v1,v2) scanf("%d %d",&v1,&v2)

#define sfi3(v1,v2,v3) scanf("%d %d %d",&v1,&v2,&v3)

#define sfll1(v) scanf("%I64d",&v);

#define sfll2(v1,v2) scanf("%I64d %I64d",&v1,&v2)

#define sfll3(v1,v2,v3) scanf("%I64d %I64d %I64d",&v1,&v2,&v3)

#define endl '\n'



typedef vector<int> vi;

typedef vector<pair<int,int> > vii;

typedef long long ll;

typedef pair<int, int> pii;





int main()

{



#ifndef ONLINE_JUDGE

	//freopen("in.in", "r", stdin);

	//freopen("out.in", "w", stdout);

#endif

	ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);



    long long ans = 0;

	long long n, k;

	cin >> n >> k;

	vector<long long> pref(n+1);

	Tree<pair<ll,int> > ms;

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

		int num;

		cin >> num;

		pref[i] = pref[i-1] + num;

		ms.insert({pref[i-1] - k * (i - 1),i});

        ans += ms.order_of_key({pref[i] - i * k + 1 , -1});

	}

	cout << ans << endl;



    return 0;

}


// Fastest known solution for this problem:
// Original C++ solution (slower):
#include<iostream>

#include<algorithm>

#include<cmath>

#include<string.h>

#include<cstdio>

#include<map>

using namespace std;

typedef long long ll;

const int MAX=200000+10; 

int n,k;

ll a[MAX];

ll b[MAX];

ll s[MAX];

map<ll, int>mp;

int lowbit(int x)

{

    return (x&-x);

}

 

void modify(int x,int num)

{

    while(x<=n+1){

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

        x+=lowbit(x);

    }

}

 

long long sum(int x)

{

    long long ans=0;

    while(x>0){

        ans+=a[x];

        x-=lowbit(x);

    }

    return ans;

}

 

int main()

{

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

    s[0]=0;b[0]=0;

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

        int x;

        scanf("%d",&x);

        s[i]=s[i-1]+(long long)(x-k);

        b[i]=s[i];

    }

    sort(b,b+1+n);

    int tot=0;

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

        if(!mp.count(b[i]))mp[b[i]]=++tot; 

    long long cnt=0;

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

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

        cnt+=sum(mp[s[i]]);

        modify(mp[s[i]],1);

    }

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

    return 0;

} 

// Optimized solution to the same problem (faster):
#include <bits/stdc++.h>

#include <ext/pb_ds/assoc_container.hpp>

#include <ext/pb_ds/tree_policy.hpp>



using namespace __gnu_pbds;

using namespace std;



template<typename T>

using Tree = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;



#define loop(i,n) for(int i = 0;i < int(n);i++)

#define rloop(i,n) for(int i = int(n);i >= 0;i--)

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

#define SZ(c) int(c.size())

#define ALL(c) c.begin(), c.end()

#define RALL(c) c.rbegin(), c.rend()

#define PI acos(-1)

#define pb push_back

#define mp make_pair

#define fr first

#define sc second

#define sfi1(v) scanf("%d",&v)

#define sfi2(v1,v2) scanf("%d %d",&v1,&v2)

#define sfi3(v1,v2,v3) scanf("%d %d %d",&v1,&v2,&v3)

#define sfll1(v) scanf("%I64d",&v);

#define sfll2(v1,v2) scanf("%I64d %I64d",&v1,&v2)

#define sfll3(v1,v2,v3) scanf("%I64d %I64d %I64d",&v1,&v2,&v3)

#define endl '\n'



typedef vector<int> vi;

typedef vector<pair<int,int> > vii;

typedef long long ll;

typedef pair<int, int> pii;





int main()

{



#ifndef ONLINE_JUDGE

	//freopen("in.in", "r", stdin);

	//freopen("out.in", "w", stdout);

#endif

	ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);



    long long ans = 0;

	long long n, k;

	cin >> n >> k;

	vector<long long> pref(n+1);

	Tree<pair<ll,int> > ms;

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

		int num;

		cin >> num;

		pref[i] = pref[i-1] + num;

		ms.insert({pref[i-1] - k * (i - 1),i});

        ans += ms.order_of_key({pref[i] - i * k + 1 , -1});

	}

	cout << ans << endl;



    return 0;

}


// Fastest known solution for this problem:
// Original C++ solution (slower):
#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;

}


// Optimized solution to the same problem (faster):
#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;

} 

// Fastest known solution for this problem:
// Original C++ solution (slower):
#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;

}

// Optimized solution to the same problem (faster):
#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;

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#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);

}


// Optimized solution to the same problem (faster):
#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;

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#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;

}



/*

*/


// Optimized solution to the same problem (faster):
#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;

}

// Fastest known solution for this problem: