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



using namespace std;



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 b[252521]; // for za-atu

ll bit[252521]; // for fenwick-tree



// fenwick tree max size is n

ll sum(int x){

  ll ret = 0;

  while(x>0){

    ret += bit[x];

    x -= x&-x;

  }

  return ret;

}

void add(int x,ll v){

  while(x<=n){

    bit[x] += v;

    x += x&-x;

  }

}



int main(){

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

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

  REP(i,n)a[i+1] += a[i] - k;

  n++;



  // za-atu

  REP(i,n)b[i] = a[i];

  sort(b,b+n);

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

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



  // fenwick tree

  ll ans = 0;

  REP(i,n){

    ans += sum(a[i]);

    add(a[i], 1);

  }

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

  return 0;

}


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

    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;

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#include <bits/stdc++.h>



using namespace std;



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 b[252521]; // for za-atu

ll bit[252521]; // for fenwick-tree



// fenwick tree max size is n

ll sum(int x){

  ll ret = 0;

  while(x>0){

    ret += bit[x];

    x -= x&-x;

  }

  return ret;

}

void add(int x,ll v){

  while(x<=n){

    bit[x] += v;

    x += x&-x;

  }

}



int main(){

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

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

  REP(i,n)a[i+1] += a[i] - k;

  n++;



  // za-atu

  REP(i,n)b[i] = a[i];

  sort(b,b+n);

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

  REP(i,n)a[i] = lower_bound(b,b+m,a[i])-b+1;



  // fenwick tree

  ll ans = 0;

  REP(i,n){

    ans += sum(a[i]);

    add(a[i], 1);

  }

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

  return 0;

}


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

    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;

}

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

}


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

    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;

}

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

}

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

    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;

}

// 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<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

*/

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

}

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

*/

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

}

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

*/

// Fastest known solution for this problem:
// Original C++ solution (slower):
#include <bits/stdc++.h>

using namespace std;

using lint = long long;

using VI = vector<int>;

using VVI = vector<VI>;



int N = 1 << 18;

VI st(2 * N - 1);

int query(int a, int b, int k = 0, int l = 0, int r = N) {

  if (r <= a or b <= l) return 0;

  if (a <= l and r <= b) return st[k];

  return query(a, b, 2 * k + 1, l, (l + r) / 2) + query(a, b, 2 * k + 2, (l + r) / 2, r);

}

void add(int k) {

  k += N - 1;

  st[k]++;

  while (k > 0) {

    k = (k - 1) / 2;

    st[k]++;

  }

}



int main() {

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

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

  VI a(n);

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

    cin >> a[i];

    a[i] -= k;

  }

  vector<lint> c(n + 1);

  vector< pair<lint, int> > p(n + 1);

  p[0] = make_pair(c[0], 0);

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

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

    p[i + 1] = make_pair(c[i + 1], i + 1);

  }

  sort(p.begin(), p.end());

  VI b(n + 1);

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

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

  }

  lint res = 0;

  add(b[0]);

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

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

    add(b[i]);

  }

  cout << res << '\n';

  return 0;

}

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

using namespace std;

using lint = long long int;

template<class T = int> using V = vector<T>;

template<class T = int> using VV = V< V<T> >;

template<class T> void assign(V<T>& v, int n, const T& a = T()) { v.assign(n, a); }

template<class T, class... U> void assign(V<T>& v, int n, const U&... u) { v.resize(n); for (auto&& i : v) assign(i, u...); }



struct M {

  using T = int;

  static T op(const T& a, const T& b) { return a + b; }

  static constexpr T e() { return 0; }

};



template<class M> struct ST {

  using T = typename M::T;

  int n;

  V<T> t;



  ST(int n) : n(n) {

    t.assign(2 * n, M::e());

  }



  void build() {

    for (int i = n - 1; i; i--) t[i] = M::op(t[2 * i], t[2 * i + 1]);

  }



  T get(int l, int r) {

    T resl = M::e(), resr = M::e();

    for (l += n, r += n; l < r; l >>= 1, r >>= 1) { 

      if (l & 1) resl = M::op(resl, t[l++]); 

      if (r & 1) resr = M::op(t[--r], resr);

    }

    return M::op(resl, resr);

  }



  void set(int i, const T& a) {

    for (t[i += n] = a; i >>= 1;) t[i] = M::op(t[2 * i], t[2 * i + 1]);

  }

};



int main() {

  cin.tie(NULL); ios::sync_with_stdio(false);

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

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

  V<lint> c(n + 1); for (int i = 0; i < n; i++) c[i + 1] = c[i] + a[i];

  V<lint> z = c; sort(z.begin(), z.end());

  z.erase(unique(z.begin(), z.end()), z.end());

  for (int i = 0; i < n + 1; i++) c[i] = lower_bound(z.begin(), z.end(), c[i]) - z.begin();

  ST<M> st(z.size());

  st.set(c[0], 1);

  lint res = 0;

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

    res += st.get(0, c[i] + 1);

    st.set(c[i], st.get(c[i], c[i] + 1) + 1);

  }

  cout << res << '\n';

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#include <bits/stdc++.h>

using namespace std;

const int MAXN = 200010;



template <typename T>

class FenwickTree

{

public:

  int N;

  vector<T> dat;



  FenwickTree(int n, T m = 0)

  {

    init(n, m);

  }



  void init(int n, int m)

  {

    N = n;

    dat.resize(n + 1);

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

    {

      dat[i] = m;

    }

  }



  int64_t sum(int i)

  {

    T s = 0;

    while (i > 0)

    {

      s += dat[i];

      i -= i & -i;

    }

    return s;

  }



  void add(int i, T x)

  {

    while (i <= N)

    {

      dat[i] += x;

      i += i & -i;

    }

  }

};



int main()

{

  int64_t N, K;

  cin >> N >> K;

  vector<int64_t> A(N);

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

  {

    cin >> A.at(i);

  }

  vector<int64_t> S(N + 1, 0);

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

  {

    S[i] = S[i - 1] + A[i - 1];

  }

  vector<int64_t> v, cv;

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

  {

    v.push_back(S[i] - i * K);

  }

  cv = v;

  sort(v.begin(), v.end());

  map<int64_t, int64_t> mp;

  int n = 1;

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

  {

    if (i && v[i - 1] < v[i])

    {

      n++;

    }

    mp[v[i]] = n;

  }

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

  {

    cv[i] = mp[cv[i]];

  }

  int64_t ans = 0;

  FenwickTree<int64_t> ft(MAXN);

  for (auto c : cv)

  {

    ans += ft.sum(c);

    ft.add(c, 1);

  }

  cout << ans << endl;

}


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

using namespace std;



template <typename T>

class FenwickTree

{

public:

  int N;

  vector<T> dat;



  FenwickTree(int n, T m = 0)

  {

    init(n, m);

  }



  void init(int n, int m)

  {

    N = n;

    dat.resize(n + 1);

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

    {

      dat[i] = m;

    }

  }



  int64_t sum(int i)

  {

    T s = 0;

    while (i > 0)

    {

      s += dat[i];

      i -= i & -i;

    }

    return s;

  }



  void add(int i, T x)

  {

    while (i <= N)

    {

      dat[i] += x;

      i += i & -i;

    }

  }

};



int main()

{

  int64_t N, K;

  cin >> N >> K;

  vector<int64_t> A(N), S(N + 1, 0); // l <= x <= r -> S[r+1] - S[l]

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

  {

    cin >> A.at(i);

  }

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

  {

    S.at(i + 1) = S.at(i) + A.at(i);

  }

  vector<int64_t> B(N + 1);

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

  {

    B.at(i) = S.at(i) - K * i;

  }

  auto C = B;

  sort(C.begin(), C.end());

  int cnt = 1;

  map<int64_t, int64_t> mp;

  mp[C[0]] = 1;

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

  {

    if (C.at(i) > C.at(i - 1))

    {

      cnt++;

    }

    mp[C[i]] = cnt;

  }

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

  {

    B.at(i) = mp[B.at(i)];

  }

  int64_t ans = 0;

  FenwickTree<int> ft(cnt + 1);

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

  {

    ans += ft.sum(B.at(i));

    ft.add(B.at(i), 1);

  }

  cout << ans << endl;

}

// Fastest known solution for this problem:
// Original C++ solution (slower):


#include<bits/stdc++.h>

#define LL long long

#define MOD (LL)1000000007

#define pi acos(-1.0)

#define ULL unsigned long long

#define mem_1(str) memset(str,-1,sizeof(str))

#define mem0(str) memset(str,0,sizeof(str))

#define rep(i,a,n) for (int i=a;i<n;i++)

#define per(i,a,n) for (int i=n-1;i>=a;i--)

#define INF 999999999

using namespace std;

LL num[300000];

LL id[300000];

LL sum[300000];

int m,idd[300000];;

inline int lowbit(int x)

{

	return x&(-x);

}

void add(int x)

{

    for(int i=x;i<=m;i+=lowbit(i))

    {

    	sum[i]++;

	}    

}

LL add2(int x)

{

    LL ans=0;

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

    {

    	ans=ans+sum[i];

	}        

    return ans;

}

int main()

{

	mem0(id);

	mem0(num);

	mem0(sum);

	mem0(idd);

	int n,k; 

		LL ans=0;

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

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

	{

		int a;

		scanf("%d",&a);

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

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

	}

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

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

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

	{

		idd[i]=lower_bound(num+1,num+m+1,id[i])-num;

	}



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

	{

		ans+=add2(idd[i]);

		add(idd[i]);

	}

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

}

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

using namespace std;

typedef long long ll;



#define ls rt<<1

#define rs rt<<1|1

#define lb(x) (x&-x)

typedef pair<int,int> pii;

const int maxn = 4e5 + 10;

const int maxm = 1e6 + 10 ;

const int inf=0x3f3f3f3f;

const ll INF = 0x3f3f3f3f3f3f3f3fLL;

const int st=(1<<20)-1;

const int mod = 1e9+7;

const double eps = 1e-5;

const int vec[2][2]={1,0,0,1};



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<<1)+(x<<3)+(ch^48);

        ch=getchar();

    }

    return x*f;

}

int f[maxn],n,m;

inline void add(int x,int p) {

    for(int i=x;i<=m;i+=lb(i)) f[i]+=p;

}

inline int ask(int r) {

    int ans=0;

    for(int i=r;i;i-=lb(i)) ans+=f[i];

    return ans;

}

ll pre[maxn],p[maxn];

int a[maxn];

int main() {

#ifdef LOCAL

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

#endif // LOCAL

//    ios::sync_with_stdio(false);

//    cin.tie(0);

    int k;

    n=read();

    k=read();

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

        a[i]=read();

        a[i]-=k;

    }

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

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

        p[++m]=pre[i];

    }

    p[++m]=0;

    sort(p+1,p+1+m);

    m=unique(p+1,p+1+m)-p-1;

    int pos=lower_bound(p+1,p+1+m,0)-p;

    ll ans=0;

    add(pos,1);

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

        pos=lower_bound(p+1,p+1+m,pre[i])-p;

        ans+=ask(pos);

        add(pos,1);

    }

    cout<<ans;

    return 0;

}

//校园网真tm卡


// Fastest known solution for this problem:
// Original C++ solution (slower):
#include <bits/stdc++.h>

using namespace std;



int solve() {

	int n;

	cin >> n;

	cout << (n + 999) / 1000 * 1000 - n << '\n';

	return 0;

}



int main() {

	cin.tie(0)->sync_with_stdio(0);

	

	int t = 1;

	// cin >> t;

	while (t--) solve();

	return 0;

}

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

int main(){

int a=0, b;

 

    scanf("%d", &b);

    for(a=0;a<b;a+=1000){

    a;

    }

printf("%d", a-b);



 

 

return 0;

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
// In the name of God



#include <bits/stdc++.h>



using namespace std;



int main() {

	ios_base::sync_with_stdio(false);

	cin.tie(0);

	

	int n;

	cin >> n;



	cout << (1000 - (n % 1000)) % 1000;



	return 0;

}


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

int main(){

	int n;

	scanf ("%d", &n);

	int uang;

	while(uang<n){

		uang=uang+1000;

	}	

	if(uang==n){

		puts("0");

	}

	else if(uang>=n){

		printf("%d", uang-n);

	}

	return 0;

}

// Fastest known solution for this problem: