stablegradients/pie-gem5-pairs huggingface dataset:
// 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.163869923625893x):
//2020-04-11 23:20:32

//#pragma GCC optimize("-Ofast","unroll-loops","omit-frame-pointer","inline") //Optimization flags

//#pragma GCC option("arch=native","tune=native","no-zero-upper") //Enable AVX

//#pragma GCC target("avx2")  //Enable AVX

#include <bits/stdc++.h>

#include <ext/pb_ds/assoc_container.hpp>



using namespace __gnu_pbds;

using namespace std;

typedef long long ll;

typedef long double ld;

typedef unsigned long long ull;

typedef tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update> indexed_set;

//order_of_key(x) : number of items less than x

//find_by_order(x) : iterator to x



#define mem(dp,a)           memset(dp,a,sizeof dp)

#define rep(i,a,b)          for(ll i=a;i<b;i++)

#define pb(x)               push_back(x)

#define mp(x,y)             make_pair(x,y)

#define fastio              ios_base::sync_with_stdio(false);cin.tie(NULL)

#define F                   first

#define S                   second

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



const ld pi=3.14159265359;

ll INF=1e18+10;

ll MOD=998244353;

ll mod=1e9+7;



inline ll add(ll a,ll b,ll m){

    if((a+b)>=m)return (a+b)%m;

    return a+b;

}



inline ll mul(ll a,ll b,ll m){

    if((a*b)<m)return a*b;

    return (a*b)%m;

}



int main()

{

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

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

    ll n,k;cin>>n>>k;

    ll a[n];

    rep(i,0,n){

        cin>>a[i];

        if(i!=0)

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

    }



    rep(i,0,n)a[i]-=((i+1)*k);

    set<pair<ll,ll>> ss;

    rep(i,0,n)ss.insert(mp(a[i],i));

    ss.insert(mp(-1,INF));

    map<pair<ll,ll>,int> m;

    int cnt=0;

    for(auto x: ss)m[x]=cnt++;

    rep(i,0,n)a[i]=m[mp(a[i],i)];

    ll ans=0;

    indexed_set s;s.insert(m[mp(-1,INF)]);

    rep(i,0,n){

        s.insert(a[i]);

        ll rank=s.order_of_key(a[i]);

        ans+=rank;

    }

    cout<<ans;

}
// 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.360457513033868x):
//2020-04-11 23:20:32

//#pragma GCC optimize("-Ofast","unroll-loops","omit-frame-pointer","inline") //Optimization flags

//#pragma GCC option("arch=native","tune=native","no-zero-upper") //Enable AVX

//#pragma GCC target("avx2")  //Enable AVX

#include <bits/stdc++.h>

#include <ext/pb_ds/assoc_container.hpp>



using namespace __gnu_pbds;

using namespace std;

typedef long long ll;

typedef long double ld;

typedef unsigned long long ull;

typedef tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update> indexed_set;

//order_of_key(x) : number of items less than x

//find_by_order(x) : iterator to x



#define mem(dp,a)           memset(dp,a,sizeof dp)

#define rep(i,a,b)          for(ll i=a;i<b;i++)

#define pb(x)               push_back(x)

#define mp(x,y)             make_pair(x,y)

#define fastio              ios_base::sync_with_stdio(false);cin.tie(NULL)

#define F                   first

#define S                   second

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



const ld pi=3.14159265359;

ll INF=1e18+10;

ll MOD=998244353;

ll mod=1e9+7;



inline ll add(ll a,ll b,ll m){

    if((a+b)>=m)return (a+b)%m;

    return a+b;

}



inline ll mul(ll a,ll b,ll m){

    if((a*b)<m)return a*b;

    return (a*b)%m;

}



int main()

{

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

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

    ll n,k;cin>>n>>k;

    ll a[n];

    rep(i,0,n){

        cin>>a[i];

        if(i!=0)

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

    }



    rep(i,0,n)a[i]-=((i+1)*k);

    set<pair<ll,ll>> ss;

    rep(i,0,n)ss.insert(mp(a[i],i));

    ss.insert(mp(-1,INF));

    map<pair<ll,ll>,int> m;

    int cnt=0;

    for(auto x: ss)m[x]=cnt++;

    rep(i,0,n)a[i]=m[mp(a[i],i)];

    ll ans=0;

    indexed_set s;s.insert(m[mp(-1,INF)]);

    rep(i,0,n){

        s.insert(a[i]);

        ll rank=s.order_of_key(a[i]);

        ans+=rank;

    }

    cout<<ans;

}
// 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.3213753818556726x):
#include<bits/stdc++.h>

using namespace std;

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

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

const long double EPS = 1e-14;

const int maxn = 100500;

const int mod = 1e9 + 7;

#include<ext/pb_ds/assoc_container.hpp>

#include<ext/pb_ds/tree_policy.hpp>

using namespace __gnu_pbds;

template <typename T>

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

#define int long long



/*  ordered_set<int>  s;

    s.insert(1); 

    s.insert(3);

    cout << s.order_of_key(2) << endl; // the number of elements in s less than 2

    cout << *s.find_by_order(0) << endl; // print the 0-th smallest number in s(0-based) */



signed main(){

    ios::sync_with_stdio(0);

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

    int n, k;

    cin >> n >> k;

    long long ans = 0;

    ordered_set < pair < int, int > > s;

    s.insert({0, 0});

    long long sm = 0;

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

        int x;

        cin >> x;

        sm += x;

        ans += s.order_of_key({sm - k * i, i});

        s.insert({sm - i * k, i});

    }

    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.116845447830152x):
#include<bits/stdc++.h>

using namespace std;

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

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

const long double EPS = 1e-14;

const int maxn = 100500;

const int mod = 1e9 + 7;

#include<ext/pb_ds/assoc_container.hpp>

#include<ext/pb_ds/tree_policy.hpp>

using namespace __gnu_pbds;

template <typename T>

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

#define int long long



/*  ordered_set<int>  s;

    s.insert(1); 

    s.insert(3);

    cout << s.order_of_key(2) << endl; // the number of elements in s less than 2

    cout << *s.find_by_order(0) << endl; // print the 0-th smallest number in s(0-based) */



signed main(){

    ios::sync_with_stdio(0);

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

    int n, k;

    cin >> n >> k;

    long long ans = 0;

    ordered_set < pair < int, int > > s;

    s.insert({0, 0});

    long long sm = 0;

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

        int x;

        cin >> x;

        sm += x;

        ans += s.order_of_key({sm - k * i, i});

        s.insert({sm - i * k, i});

    }

    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.874093181926412x):
#include<bits/stdc++.h>

using namespace std;

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

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

const long double EPS = 1e-14;

const int maxn = 100500;

const int mod = 1e9 + 7;

#include<ext/pb_ds/assoc_container.hpp>

#include<ext/pb_ds/tree_policy.hpp>

using namespace __gnu_pbds;

template <typename T>

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

#define int long long



/*  ordered_set<int>  s;

    s.insert(1); 

    s.insert(3);

    cout << s.order_of_key(2) << endl; // the number of elements in s less than 2

    cout << *s.find_by_order(0) << endl; // print the 0-th smallest number in s(0-based) */



signed main(){

    ios::sync_with_stdio(0);

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

    int n, k;

    cin >> n >> k;

    long long ans = 0;

    ordered_set < pair < int, int > > s;

    s.insert({0, 0});

    long long sm = 0;

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

        int x;

        cin >> x;

        sm += x;

        ans += s.order_of_key({sm - k * i, i});

        s.insert({sm - i * k, i});

    }

    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.3225063387938545x):
#include<bits/stdc++.h>

using namespace std;

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

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

const long double EPS = 1e-14;

const int maxn = 100500;

const int mod = 1e9 + 7;

#include<ext/pb_ds/assoc_container.hpp>

#include<ext/pb_ds/tree_policy.hpp>

using namespace __gnu_pbds;

template <typename T>

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

#define int long long



/*  ordered_set<int>  s;

    s.insert(1); 

    s.insert(3);

    cout << s.order_of_key(2) << endl; // the number of elements in s less than 2

    cout << *s.find_by_order(0) << endl; // print the 0-th smallest number in s(0-based) */



signed main(){

    ios::sync_with_stdio(0);

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

    int n, k;

    cin >> n >> k;

    long long ans = 0;

    ordered_set < pair < int, int > > s;

    s.insert({0, 0});

    long long sm = 0;

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

        int x;

        cin >> x;

        sm += x;

        ans += s.order_of_key({sm - k * i, i});

        s.insert({sm - i * k, i});

    }

    cout << ans << '\n';

    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: 1.3048417354427018x):
#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;

}
// 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: 1.6173515911636605x):
#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;

}
// 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: 1.305286045297586x):
#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;

}