stablegradients/pie-gem5-pairs huggingface dataset:
// Slower C++ solution:
#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;

} 

// Faster C++ solution for the same problem (measured speedup: 3.4429881366692356x):
#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;

}
// Slower C++ solution:
#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);

}


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

using namespace std;

typedef long long LL;



struct SetStk {

  vector<vector<LL>> stk;

  void add(LL x) {

    stk.push_back({x});

    while (stk.size() > 1) {

      int n = stk.size();

      if (stk[n - 1].size() == stk[n - 2].size()) {

        vector<LL> ans;

        merge(stk[n - 2].begin(), stk[n - 2].end(), 

              stk[n - 1].begin(), stk[n - 1].end(), back_inserter(ans));

        stk.pop_back();

        stk.back() = ans;

      }

      else break;

    }

  }

  int rank(LL a) {

    LL ans = 0;

    for (int i = 0; i < stk.size(); ++i) {

      auto &A = stk[i];

      ans += upper_bound(A.begin(), A.end(), a) - stk[i].begin();

    }

    return ans;

  }

};



int main() {

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

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

  vector<LL> A(n + 1);

  for (int i = 0; i < n; ++i) cin >> A[i + 1], A[i + 1] -= k, A[i + 1] += A[i];

  SetStk ds;

  LL ans = 0;

  ds.add(A[0]);

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

    ans += ds.rank(A[i]);

    ds.add(A[i]);

  }

  cout << ans << '\n';

}
// Slower C++ solution:
#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;

 } 

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

using namespace std;

typedef long long LL;



struct SetStk {

  vector<vector<LL>> stk;

  void add(LL x) {

    stk.push_back({x});

    while (stk.size() > 1) {

      int n = stk.size();

      if (stk[n - 1].size() == stk[n - 2].size()) {

        vector<LL> ans;

        merge(stk[n - 2].begin(), stk[n - 2].end(), 

              stk[n - 1].begin(), stk[n - 1].end(), back_inserter(ans));

        stk.pop_back();

        stk.back() = ans;

      }

      else break;

    }

  }

  int rank(LL a) {

    LL ans = 0;

    for (int i = 0; i < stk.size(); ++i) {

      auto &A = stk[i];

      ans += upper_bound(A.begin(), A.end(), a) - stk[i].begin();

    }

    return ans;

  }

};



int main() {

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

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

  vector<LL> A(n + 1);

  for (int i = 0; i < n; ++i) cin >> A[i + 1], A[i + 1] -= k, A[i + 1] += A[i];

  SetStk ds;

  LL ans = 0;

  ds.add(A[0]);

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

    ans += ds.rank(A[i]);

    ds.add(A[i]);

  }

  cout << ans << '\n';

}
// Slower C++ solution:
#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;

    }

}


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

using namespace std;

typedef long long LL;



struct SetStk {

  vector<vector<LL>> stk;

  void add(LL x) {

    stk.push_back({x});

    while (stk.size() > 1) {

      int n = stk.size();

      if (stk[n - 1].size() == stk[n - 2].size()) {

        vector<LL> ans;

        merge(stk[n - 2].begin(), stk[n - 2].end(), 

              stk[n - 1].begin(), stk[n - 1].end(), back_inserter(ans));

        stk.pop_back();

        stk.back() = ans;

      }

      else break;

    }

  }

  int rank(LL a) {

    LL ans = 0;

    for (int i = 0; i < stk.size(); ++i) {

      auto &A = stk[i];

      ans += upper_bound(A.begin(), A.end(), a) - stk[i].begin();

    }

    return ans;

  }

};



int main() {

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

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

  vector<LL> A(n + 1);

  for (int i = 0; i < n; ++i) cin >> A[i + 1], A[i + 1] -= k, A[i + 1] += A[i];

  SetStk ds;

  LL ans = 0;

  ds.add(A[0]);

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

    ans += ds.rank(A[i]);

    ds.add(A[i]);

  }

  cout << ans << '\n';

}
// Slower C++ solution:
#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;

} 

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

using namespace std;

typedef long long LL;



struct SetStk {

  vector<vector<LL>> stk;

  void add(LL x) {

    stk.push_back({x});

    while (stk.size() > 1) {

      int n = stk.size();

      if (stk[n - 1].size() == stk[n - 2].size()) {

        vector<LL> ans;

        merge(stk[n - 2].begin(), stk[n - 2].end(), 

              stk[n - 1].begin(), stk[n - 1].end(), back_inserter(ans));

        stk.pop_back();

        stk.back() = ans;

      }

      else break;

    }

  }

  int rank(LL a) {

    LL ans = 0;

    for (int i = 0; i < stk.size(); ++i) {

      auto &A = stk[i];

      ans += upper_bound(A.begin(), A.end(), a) - stk[i].begin();

    }

    return ans;

  }

};



int main() {

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

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

  vector<LL> A(n + 1);

  for (int i = 0; i < n; ++i) cin >> A[i + 1], A[i + 1] -= k, A[i + 1] += A[i];

  SetStk ds;

  LL ans = 0;

  ds.add(A[0]);

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

    ans += ds.rank(A[i]);

    ds.add(A[i]);

  }

  cout << ans << '\n';

}
// Slower C++ solution:
#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);

}


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

#include <ext/pb_ds/assoc_container.hpp>

#include <ext/pb_ds/tree_policy.hpp>

#define mst(a,b) memset(a,b,sizeof(a))

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

#define X first

#define Y second

using namespace std;

using namespace __gnu_cxx;

using namespace __gnu_pbds;

typedef long long LL;

typedef long long ll;

typedef unsigned long long ull;

typedef pair<int, int> pii;

typedef pair<ll, ll> pll;

const int inf = 0x3f3f3f3f;

const ll INF = 0x3f3f3f3f3f3f3f3f;

const int maxn = 200000+10;

const int maxm = 200000+10;

const int mod = 1e9+7;

const double eps = 1e-9;

int bit[maxn],tot;

void update(int pos,int val){

    for (;pos<=tot;pos+=lowbit(pos)) bit[pos]+=val;

}

int query(int pos){

    int res=0;

    for (;pos;pos-=lowbit(pos)) res+=bit[pos];

    return res;

}

ll x[maxn],s[maxn];

int get_id(ll val){

    return lower_bound(x+1,x+tot+1,val)-x;

}

int main() {

#ifdef local

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

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

#endif

    ios::sync_with_stdio(0);

    cin.tie(0);cout.tie(0);

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

    x[++tot]=0;

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

        int v; cin>>v;

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

        x[++tot]=s[i]-1ll*i*k;

    }

    sort(x+1,x+tot+1);

    tot=unique(x+1,x+tot+1)-x-1;

    update(get_id(0),1);

    ll ans=0;

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

        ll tmp=s[i]-1ll*i*k;

        ans+=query(get_id(tmp));

        update(get_id(tmp),1);

    }

    cout<<ans<<"\n";

    return 0;

}
// Slower C++ solution:
#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;

 } 

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

#include <ext/pb_ds/assoc_container.hpp>

#include <ext/pb_ds/tree_policy.hpp>

#define mst(a,b) memset(a,b,sizeof(a))

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

#define X first

#define Y second

using namespace std;

using namespace __gnu_cxx;

using namespace __gnu_pbds;

typedef long long LL;

typedef long long ll;

typedef unsigned long long ull;

typedef pair<int, int> pii;

typedef pair<ll, ll> pll;

const int inf = 0x3f3f3f3f;

const ll INF = 0x3f3f3f3f3f3f3f3f;

const int maxn = 200000+10;

const int maxm = 200000+10;

const int mod = 1e9+7;

const double eps = 1e-9;

int bit[maxn],tot;

void update(int pos,int val){

    for (;pos<=tot;pos+=lowbit(pos)) bit[pos]+=val;

}

int query(int pos){

    int res=0;

    for (;pos;pos-=lowbit(pos)) res+=bit[pos];

    return res;

}

ll x[maxn],s[maxn];

int get_id(ll val){

    return lower_bound(x+1,x+tot+1,val)-x;

}

int main() {

#ifdef local

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

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

#endif

    ios::sync_with_stdio(0);

    cin.tie(0);cout.tie(0);

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

    x[++tot]=0;

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

        int v; cin>>v;

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

        x[++tot]=s[i]-1ll*i*k;

    }

    sort(x+1,x+tot+1);

    tot=unique(x+1,x+tot+1)-x-1;

    update(get_id(0),1);

    ll ans=0;

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

        ll tmp=s[i]-1ll*i*k;

        ans+=query(get_id(tmp));

        update(get_id(tmp),1);

    }

    cout<<ans<<"\n";

    return 0;

}
// Slower C++ solution:
#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;

    }

}


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

#include <ext/pb_ds/assoc_container.hpp>

#include <ext/pb_ds/tree_policy.hpp>

#define mst(a,b) memset(a,b,sizeof(a))

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

#define X first

#define Y second

using namespace std;

using namespace __gnu_cxx;

using namespace __gnu_pbds;

typedef long long LL;

typedef long long ll;

typedef unsigned long long ull;

typedef pair<int, int> pii;

typedef pair<ll, ll> pll;

const int inf = 0x3f3f3f3f;

const ll INF = 0x3f3f3f3f3f3f3f3f;

const int maxn = 200000+10;

const int maxm = 200000+10;

const int mod = 1e9+7;

const double eps = 1e-9;

int bit[maxn],tot;

void update(int pos,int val){

    for (;pos<=tot;pos+=lowbit(pos)) bit[pos]+=val;

}

int query(int pos){

    int res=0;

    for (;pos;pos-=lowbit(pos)) res+=bit[pos];

    return res;

}

ll x[maxn],s[maxn];

int get_id(ll val){

    return lower_bound(x+1,x+tot+1,val)-x;

}

int main() {

#ifdef local

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

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

#endif

    ios::sync_with_stdio(0);

    cin.tie(0);cout.tie(0);

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

    x[++tot]=0;

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

        int v; cin>>v;

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

        x[++tot]=s[i]-1ll*i*k;

    }

    sort(x+1,x+tot+1);

    tot=unique(x+1,x+tot+1)-x-1;

    update(get_id(0),1);

    ll ans=0;

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

        ll tmp=s[i]-1ll*i*k;

        ans+=query(get_id(tmp));

        update(get_id(tmp),1);

    }

    cout<<ans<<"\n";

    return 0;

}
// Slower C++ solution:
#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;

} 

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

#include <ext/pb_ds/assoc_container.hpp>

#include <ext/pb_ds/tree_policy.hpp>

#define mst(a,b) memset(a,b,sizeof(a))

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

#define X first

#define Y second

using namespace std;

using namespace __gnu_cxx;

using namespace __gnu_pbds;

typedef long long LL;

typedef long long ll;

typedef unsigned long long ull;

typedef pair<int, int> pii;

typedef pair<ll, ll> pll;

const int inf = 0x3f3f3f3f;

const ll INF = 0x3f3f3f3f3f3f3f3f;

const int maxn = 200000+10;

const int maxm = 200000+10;

const int mod = 1e9+7;

const double eps = 1e-9;

int bit[maxn],tot;

void update(int pos,int val){

    for (;pos<=tot;pos+=lowbit(pos)) bit[pos]+=val;

}

int query(int pos){

    int res=0;

    for (;pos;pos-=lowbit(pos)) res+=bit[pos];

    return res;

}

ll x[maxn],s[maxn];

int get_id(ll val){

    return lower_bound(x+1,x+tot+1,val)-x;

}

int main() {

#ifdef local

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

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

#endif

    ios::sync_with_stdio(0);

    cin.tie(0);cout.tie(0);

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

    x[++tot]=0;

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

        int v; cin>>v;

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

        x[++tot]=s[i]-1ll*i*k;

    }

    sort(x+1,x+tot+1);

    tot=unique(x+1,x+tot+1)-x-1;

    update(get_id(0),1);

    ll ans=0;

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

        ll tmp=s[i]-1ll*i*k;

        ans+=query(get_id(tmp));

        update(get_id(tmp),1);

    }

    cout<<ans<<"\n";

    return 0;

}