stablegradients/pie-gem5-pairs huggingface dataset:
// Slower C++ solution:
#include <bits/stdc++.h>



// using namespace std;

using std::sort;

using std::lower_bound;

using std::unique;

using std::vector;

using std::set;



typedef long long ll;



typedef int _loop_int;

#define REP(i,n) for(_loop_int i=0;i<(_loop_int)(n);++i)

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



int n;

ll k;

ll a[252521];

ll tmp[252521];



ll solve(int l,int r){

  if(r-l==1){

    return 0ll;

  }

  int mid = (l+r)/2;

  ll ret = solve(l,mid) + solve(mid,r);

  int hl = l, hr = mid;

  FOR(i,l,r){

    if(hl<mid && (hr==r || a[hl]<=a[hr])){

      tmp[i] = a[hl++];

    }else{

      ret += hl-l;

      tmp[i] = a[hr++];

    }

  }

  FOR(i,l,r)a[i]=tmp[i];

  return ret;

}



int main(){

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

  REP(i,n){

    scanf("%lld",a+i+1);

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

  }

  n++;

  ll ans = solve(0,n);

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

  return 0;

}


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

#include <stdio.h>

#include <utility>

 

// using namespace std;

using std::swap;

 

typedef long long ll;

 

typedef int _loop_int;

#define REP(i,n) for(_loop_int i=0;i<(_loop_int)(n);++i)

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



ll a[252521];

ll tmp[252521];

 

ll solve(int l,int r){

  if(r-l <= 16){

    ll ret = (r-l)*(r-l-1)/2;

    REP(k,r-l-1)FOR(i,l,r-1-k)if(a[i]>a[i+1])swap(a[i],a[i+1]),ret--;

    return ret;

  }

  // if(r-l==1){

  //   return 0ll;

  // }

  int mid = (l+r)/2;

  ll ret = solve(l,mid) + solve(mid,r);

  int hl = l, hr = mid;

  FOR(i,l,r){

    if(hl<mid && (hr==r || a[hl]<=a[hr])){

      tmp[i] = a[hl++];

    }else{

      ret += hl-l;

      tmp[i] = a[hr++];

    }

  }

  FOR(i,l,r)a[i]=tmp[i];

  return ret;

}

 

int main(){

  int n;

  ll k;

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

  REP(i,n){

    scanf("%lld",a+i+1);

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

  }

  ll ans = solve(0,n+1);

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

  return 0;

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

#include <stdio.h>

#include <algorithm>

 

// using namespace std;

using std::inplace_merge;

 

typedef long long ll;

 

typedef int _loop_int;

#define REP(i,n) for(_loop_int i=0;i<(_loop_int)(n);++i)

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

 

int n;

ll k;

ll a[252521];

ll tmp[252521];

 

ll solve(int l,int r){

  if(r-l==1){

    return 0ll;

  }

  int mid = (l+r)/2;

  ll ret = solve(l,mid) + solve(mid,r);

  int hl = l, hr = mid;

  FOR(i,l,r){

    if(hl<mid && (hr==r || a[hl]<=a[hr])){

      hl++;

    }else{

      ret += hl-l;

      hr++;

    }

  }

  inplace_merge(a+l,a+mid,a+r);

  return ret;

}

 

int main(){

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

  REP(i,n){

    scanf("%lld",a+i+1);

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

  }

  n++;

  ll ans = solve(0,n);

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

  return 0;

}

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

#include <stdio.h>

#include <utility>

 

// using namespace std;

using std::swap;

 

typedef long long ll;

 

typedef int _loop_int;

#define REP(i,n) for(_loop_int i=0;i<(_loop_int)(n);++i)

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



ll a[252521];

ll tmp[252521];

 

ll solve(int l,int r){

  if(r-l <= 16){

    ll ret = (r-l)*(r-l-1)/2;

    REP(k,r-l-1)FOR(i,l,r-1-k)if(a[i]>a[i+1])swap(a[i],a[i+1]),ret--;

    return ret;

  }

  // if(r-l==1){

  //   return 0ll;

  // }

  int mid = (l+r)/2;

  ll ret = solve(l,mid) + solve(mid,r);

  int hl = l, hr = mid;

  FOR(i,l,r){

    if(hl<mid && (hr==r || a[hl]<=a[hr])){

      tmp[i] = a[hl++];

    }else{

      ret += hl-l;

      tmp[i] = a[hr++];

    }

  }

  FOR(i,l,r)a[i]=tmp[i];

  return ret;

}

 

int main(){

  int n;

  ll k;

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

  REP(i,n){

    scanf("%lld",a+i+1);

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

  }

  ll ans = solve(0,n+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: 30.87204143634082x):
#include<cstdio>

#include<algorithm>

#define ll long long

using namespace std;



const int N=4e5+5;

int n,k,now,c[N],b[N];

ll s,ans;

struct A{ ll x; int id; }a[N];



bool cmp(A i,A j) {

    return i.x<j.x;

}



inline void add(int x) {

    for(int i=x;i<=now;i+=i&-i) {

        c[i]++;

    }

}



inline int ask(int x) {

    int ret=0;

    for(int i=x;i;i-=i&-i) {

        ret+=c[i];

    }

    return ret;

}



int main() {

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

    a[0]=(A){0,0};

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

        int x; scanf("%d",&x);

        s+=x;

        a[i]=(A){s-(ll)k*i,i};

    }

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

    b[a[0].id]=now=1;

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

        if(a[i].x!=a[i-1].x) {

            now++;

        }

        b[a[i].id]=now;

    }

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

        ans+=ask(b[i]),add(b[i]);

    }

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

    return 0;

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

#include<cstdio>

#include<cstring>

#include<algorithm>

#define N 200040

using namespace std;

int n,k;

long long ans=0,aux[N],sum[N];

long long tree[N];

int lowbit(int x)

{

	return x&-x;

}

long long getsum(int x)

{

	long long ans=0;

	for(int i=x;i;i-=lowbit(i))

	ans+=tree[i];

	return ans;

}

void add(int x,int k)

{

	for(int i=x;i<=n+16;i+=lowbit(i))

	tree[i]+=k;

}



int main()

{

	memset(sum,0,sizeof(sum));

	memset(aux,0,sizeof(aux));

	memset(tree,0,sizeof(tree));

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

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

	{

		int x;

		scanf("%d",&x);

		sum[i]=sum[i-1]+x-k;

		aux[i]=sum[i];

	}

	sort(aux,aux+1+n);

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

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

	sum[i]=lower_bound(aux,aux+1+m,sum[i])-aux+1;

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

	{

		ans+=getsum(sum[i]);

		add(sum[i],1);

	}

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

	return 0;

}

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

#include<algorithm>

#define ll long long

using namespace std;



const int N=4e5+5;

int n,k,now,c[N],b[N];

ll s,ans;

struct A{ ll x; int id; }a[N];



bool cmp(A i,A j) {

    return i.x<j.x;

}



inline void add(int x) {

    for(int i=x;i<=now;i+=i&-i) {

        c[i]++;

    }

}



inline int ask(int x) {

    int ret=0;

    for(int i=x;i;i-=i&-i) {

        ret+=c[i];

    }

    return ret;

}



int main() {

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

    a[0]=(A){0,0};

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

        int x; scanf("%d",&x);

        s+=x;

        a[i]=(A){s-(ll)k*i,i};

    }

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

    b[a[0].id]=now=1;

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

        if(a[i].x!=a[i-1].x) {

            now++;

        }

        b[a[i].id]=now;

    }

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

        ans+=ask(b[i]),add(b[i]);

    }

    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.990420194203202x):
#include<cstdio>

#include<iostream>

#include<cstring>

#include<algorithm>

#define int long long

#define rint register int

using namespace std;

const int maxn=2e5+5;

inline int read()

{

	int x=0,f=1;

	char ch=getchar();

	while(ch<'0'||ch>'9')

	{

		if(ch=='-') f=-1;

		ch=getchar();

	}

	while(ch>='0'&&ch<='9')

	{

		x=x*10+ch-'0';

		ch=getchar();

	}

	return x*f;

}

int n,k;

int a[maxn];

int sum[maxn];

int ans;

int c[maxn];

inline void msort(int l,int r)

{

	if(l==r)

	return ;

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

	msort(l,mid);

	msort(mid+1,r);

	int i=l,j=mid+1,k=l;

	while(i<=mid&&j<=r)

	{

		if(a[i]<=a[j])

		{

			ans+=r-j+1;

			c[k++]=a[i++];

		}

		else

		c[k++]=a[j++];

	}

	while(i<=mid)

	c[k++]=a[i++];

	while(j<=r)

	c[k++]=a[j++];

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

	a[i]=c[i];

}

signed main()

{

	n=read()+1;

	k=read();

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

	{

		a[i]=read();

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

		a[i]=sum[i]-k*(i-1);

	}

	msort(1,n);

	cout<<ans;

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

#include<cstdio>

#include<cstring>

#include<algorithm>

#define N 200040

using namespace std;

int n,k;

long long ans=0,aux[N],sum[N];

long long tree[N];

int lowbit(int x)

{

	return x&-x;

}

long long getsum(int x)

{

	long long ans=0;

	for(int i=x;i;i-=lowbit(i))

	ans+=tree[i];

	return ans;

}

void add(int x,int k)

{

	for(int i=x;i<=n+16;i+=lowbit(i))

	tree[i]+=k;

}



int main()

{

	memset(sum,0,sizeof(sum));

	memset(aux,0,sizeof(aux));

	memset(tree,0,sizeof(tree));

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

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

	{

		int x;

		scanf("%d",&x);

		sum[i]=sum[i-1]+x-k;

		aux[i]=sum[i];

	}

	sort(aux,aux+1+n);

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

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

	sum[i]=lower_bound(aux,aux+1+m,sum[i])-aux+1;

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

	{

		ans+=getsum(sum[i]);

		add(sum[i],1);

	}

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

	return 0;

}

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

#include<iostream>

#include<cstring>

#include<algorithm>

#define int long long

#define rint register int

using namespace std;

const int maxn=2e5+5;

inline int read()

{

	int x=0,f=1;

	char ch=getchar();

	while(ch<'0'||ch>'9')

	{

		if(ch=='-') f=-1;

		ch=getchar();

	}

	while(ch>='0'&&ch<='9')

	{

		x=x*10+ch-'0';

		ch=getchar();

	}

	return x*f;

}

int n,k;

int a[maxn];

int sum[maxn];

int ans;

int c[maxn];

inline void msort(int l,int r)

{

	if(l==r)

	return ;

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

	msort(l,mid);

	msort(mid+1,r);

	int i=l,j=mid+1,k=l;

	while(i<=mid&&j<=r)

	{

		if(a[i]<=a[j])

		{

			ans+=r-j+1;

			c[k++]=a[i++];

		}

		else

		c[k++]=a[j++];

	}

	while(i<=mid)

	c[k++]=a[i++];

	while(j<=r)

	c[k++]=a[j++];

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

	a[i]=c[i];

}

signed main()

{

	n=read()+1;

	k=read();

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

	{

		a[i]=read();

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

		a[i]=sum[i]-k*(i-1);

	}

	msort(1,n);

	cout<<ans;

}
// 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: 30.90242774558527x):
#include<cstdio>

#include<algorithm>

int n, k;

long long ans;

long long c[200010], val[200010], sum[200010];



inline void add(long long x, long long y){

	for(;x <= n;x += x & -x) c[x] += y;

}



inline long long ask(long long x){

	long long ans = 0;

	for(;x;x -= x & -x) ans += c[x];

	return ans;

}



int main(){

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

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

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

		val[i] -= k; 

	}

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

		sum[i] = (val[i] += val[i - 1]);

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

	}

	std::sort(sum + 1, sum + 1 + n);int t = std::unique(sum + 1, sum + 1 + n) - (sum + 1);

	for(int i = 1;i <= n;++i) val[i] = std::lower_bound(sum + 1, sum + 1 + t, val[i]) - sum;

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

		ans += ask(val[i]);add(val[i], 1);

	}

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

	return 0;

}

/*

对区间[l, r] average = (sum[r] - sum[l - 1]) / (r - l + 1) >= k

等价于sum[r]-r*k>=sum[l-1]-(l-1)*k

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

#include<cstdio>

#include<cstring>

#include<algorithm>

#define N 200040

using namespace std;

int n,k;

long long ans=0,aux[N],sum[N];

long long tree[N];

int lowbit(int x)

{

	return x&-x;

}

long long getsum(int x)

{

	long long ans=0;

	for(int i=x;i;i-=lowbit(i))

	ans+=tree[i];

	return ans;

}

void add(int x,int k)

{

	for(int i=x;i<=n+16;i+=lowbit(i))

	tree[i]+=k;

}



int main()

{

	memset(sum,0,sizeof(sum));

	memset(aux,0,sizeof(aux));

	memset(tree,0,sizeof(tree));

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

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

	{

		int x;

		scanf("%d",&x);

		sum[i]=sum[i-1]+x-k;

		aux[i]=sum[i];

	}

	sort(aux,aux+1+n);

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

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

	sum[i]=lower_bound(aux,aux+1+m,sum[i])-aux+1;

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

	{

		ans+=getsum(sum[i]);

		add(sum[i],1);

	}

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

	return 0;

}

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

#include<algorithm>

int n, k;

long long ans;

long long c[200010], val[200010], sum[200010];



inline void add(long long x, long long y){

	for(;x <= n;x += x & -x) c[x] += y;

}



inline long long ask(long long x){

	long long ans = 0;

	for(;x;x -= x & -x) ans += c[x];

	return ans;

}



int main(){

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

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

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

		val[i] -= k; 

	}

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

		sum[i] = (val[i] += val[i - 1]);

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

	}

	std::sort(sum + 1, sum + 1 + n);int t = std::unique(sum + 1, sum + 1 + n) - (sum + 1);

	for(int i = 1;i <= n;++i) val[i] = std::lower_bound(sum + 1, sum + 1 + t, val[i]) - sum;

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

		ans += ask(val[i]);add(val[i], 1);

	}

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

	return 0;

}

/*

对区间[l, r] average = (sum[r] - sum[l - 1]) / (r - l + 1) >= k

等价于sum[r]-r*k>=sum[l-1]-(l-1)*k

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

#include<iostream>

#include<cstring>

#include<algorithm>

#define int long long

#define rint register int

using namespace std;

const int maxn=2e5+5;

inline int read()

{

	int x=0,f=1;

	char ch=getchar();

	while(ch<'0'||ch>'9')

	{

		if(ch=='-') f=-1;

		ch=getchar();

	}

	while(ch>='0'&&ch<='9')

	{

		x=x*10+ch-'0';

		ch=getchar();

	}

	return x*f;

}

int n,k;

int a[maxn];

int sum[maxn];

int ans;

int c[maxn];

inline void msort(int l,int r)

{

	if(l==r)

	return ;

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

	msort(l,mid);

	msort(mid+1,r);

	int i=l,j=mid+1,k=l;

	while(i<=mid&&j<=r)

	{

		if(a[i]<=a[j])

		{

			ans+=r-j+1;

			c[k++]=a[i++];

		}

		else

		c[k++]=a[j++];

	}

	while(i<=mid)

	c[k++]=a[i++];

	while(j<=r)

	c[k++]=a[j++];

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

	a[i]=c[i];

}

signed main()

{

	n=read()+1;

	k=read();

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

	{

		a[i]=read();

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

		a[i]=sum[i]-k*(i-1);

	}

	msort(1,n);

	cout<<ans;

}

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

#include<algorithm>

int n, k;

long long ans;

long long c[200010], val[200010], sum[200010];



inline void add(long long x, long long y){

	for(;x <= n;x += x & -x) c[x] += y;

}



inline long long ask(long long x){

	long long ans = 0;

	for(;x;x -= x & -x) ans += c[x];

	return ans;

}



int main(){

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

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

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

		val[i] -= k; 

	}

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

		sum[i] = (val[i] += val[i - 1]);

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

	}

	std::sort(sum + 1, sum + 1 + n);int t = std::unique(sum + 1, sum + 1 + n) - (sum + 1);

	for(int i = 1;i <= n;++i) val[i] = std::lower_bound(sum + 1, sum + 1 + t, val[i]) - sum;

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

		ans += ask(val[i]);add(val[i], 1);

	}

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

	return 0;

}

/*

对区间[l, r] average = (sum[r] - sum[l - 1]) / (r - l + 1) >= k

等价于sum[r]-r*k>=sum[l-1]-(l-1)*k

*/
// 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.991722598898671x):
#include <algorithm>

#include <cstdio>

#include <cstring>

#include <iostream>

#include <map>

#include <set>

#include <vector>

#define rr int

using namespace std;

typedef long long ll;

ll read() {

    char i = getchar();

    ll f = 1, res = 0;

    while (i < '0' || i > '9') {

        if (i == '-') f = -1;

        i = getchar();

    }

    while (i >= '0' && i <= '9') {

        res = res * 10 + i - '0';

        i = getchar();

    }

    return f * res;

}

int n;

ll K;

const int N = 3e5 + 50;

ll a[N];

ll sum[N], c[N];

ll ans = 0;

inline void merge(int l, int r) {

    if (l < r) {

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

        merge(l, mid);

        merge(mid + 1, r);

        int i = l, j = mid + 1, now = l;

        while (i <= mid && j <= r) {

            if (a[i] <= a[j]) {

                c[now++] = a[i++];

                ans += r - j + 1; //这里注意不能重复计算，每次取得取单独更新贡献

            } else

                c[now++] = a[j++];

        }

        while (i <= mid) c[now++] = a[i++];

        while (j <= r) c[now++] = a[j++];

        for (rr i = l; i <= r; ++i) a[i] = c[i];

    }

}

int main() {

    n = read() + 1, K = read();

    for (rr i = 2; i <= n; ++i) {

        a[i] = read();

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

        a[i] = sum[i] - K * ll(i - 1);

    }

    // for (rr i = 1; i <= n; ++i) cout << a[i] << ' ';

    merge(1, n);

    // for (rr i = 1; i <= n; ++i) cout << a[i] << endl;

    cout << ans;

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

#include<cstdio>

#include<cstring>

#include<algorithm>

#define N 200040

using namespace std;

int n,k;

long long ans=0,aux[N],sum[N];

long long tree[N];

int lowbit(int x)

{

	return x&-x;

}

long long getsum(int x)

{

	long long ans=0;

	for(int i=x;i;i-=lowbit(i))

	ans+=tree[i];

	return ans;

}

void add(int x,int k)

{

	for(int i=x;i<=n+16;i+=lowbit(i))

	tree[i]+=k;

}



int main()

{

	memset(sum,0,sizeof(sum));

	memset(aux,0,sizeof(aux));

	memset(tree,0,sizeof(tree));

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

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

	{

		int x;

		scanf("%d",&x);

		sum[i]=sum[i-1]+x-k;

		aux[i]=sum[i];

	}

	sort(aux,aux+1+n);

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

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

	sum[i]=lower_bound(aux,aux+1+m,sum[i])-aux+1;

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

	{

		ans+=getsum(sum[i]);

		add(sum[i],1);

	}

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

	return 0;

}

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

#include <cstdio>

#include <cstring>

#include <iostream>

#include <map>

#include <set>

#include <vector>

#define rr int

using namespace std;

typedef long long ll;

ll read() {

    char i = getchar();

    ll f = 1, res = 0;

    while (i < '0' || i > '9') {

        if (i == '-') f = -1;

        i = getchar();

    }

    while (i >= '0' && i <= '9') {

        res = res * 10 + i - '0';

        i = getchar();

    }

    return f * res;

}

int n;

ll K;

const int N = 3e5 + 50;

ll a[N];

ll sum[N], c[N];

ll ans = 0;

inline void merge(int l, int r) {

    if (l < r) {

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

        merge(l, mid);

        merge(mid + 1, r);

        int i = l, j = mid + 1, now = l;

        while (i <= mid && j <= r) {

            if (a[i] <= a[j]) {

                c[now++] = a[i++];

                ans += r - j + 1; //这里注意不能重复计算，每次取得取单独更新贡献

            } else

                c[now++] = a[j++];

        }

        while (i <= mid) c[now++] = a[i++];

        while (j <= r) c[now++] = a[j++];

        for (rr i = l; i <= r; ++i) a[i] = c[i];

    }

}

int main() {

    n = read() + 1, K = read();

    for (rr i = 2; i <= n; ++i) {

        a[i] = read();

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

        a[i] = sum[i] - K * ll(i - 1);

    }

    // for (rr i = 1; i <= n; ++i) cout << a[i] << ' ';

    merge(1, n);

    // for (rr i = 1; i <= n; ++i) cout << a[i] << endl;

    cout << ans;

}