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

using namespace std;

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

#define ROF(i,a,b) for (int i=(a);i>=(b);--i)

typedef long long ll;

inline int read() {

	int x=0,s=1; char ch=getchar();

	while (ch<'0'||ch>'9') { if (ch=='-') s=-1; ch=getchar(); }

	while (ch>='0'&&ch<='9') { x=x*10+ch-'0'; ch=getchar(); }

	return s*x;

}



const int MAXN=200005,Mo=1000000007;

ll sum[MAXN];

int n,m,q,a[MAXN],b[MAXN],f[MAXN];

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

void add(int x,int y){ for (;x<MAXN;x+=lowbit(x)) f[x]+=y; }

int getsum(int x){ int y=0; for (;x;x-=lowbit(x)) y+=f[x]; return y; }

int cmp(int i,int j){ return sum[i]<sum[j]; }

int main(){

	n=read(); m=read();

	b[0]=sum[0]=0;

	FOR(i,1,n) a[i]=read()-m,b[i]=i,sum[i]=sum[i-1]+a[i];

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

	//FOR(i,0,n) printf("%lld%c",sum[i]," \n"[i==n]);

	//FOR(i,0,n) printf("%d%c",b[i]," \n"[i==n]);

	int k=1;

	FOR(i,0,n) {

		if (i&&sum[b[i]]!=sum[b[i-1]]) k++;

		a[b[i]]=k;

	}

	//FOR(i,0,n) printf("%d%c",a[i]," \n"[i==n]);

	memset(f,0,sizeof(f));

	ll ans=0;

	FOR(i,0,n) {

		ans+=getsum(a[i]);

		add(a[i],1);

	}

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

	

	return 0;

}



/*

*/


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

#include <ext/pb_ds/assoc_container.hpp> 

#include <ext/pb_ds/tree_policy.hpp> 

using namespace std;

using namespace __gnu_pbds;   

#define ordered_set tree<pll, null_type,less<pll>, rb_tree_tag,tree_order_statistics_node_update> 

#define ll long long int

#define ff first

#define ss second

#define pb push_back

#define mp make_pair

#define pll pair<ll,ll>

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

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



ll p[200005],a[200005];

map<ll,ll>M;

int main()

{

    ios_base::sync_with_stdio(false);

    ll n,i,j,k,x,y,t,m;



    cin >> n >> k;

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

        cin >> a[i];



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

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



    ll ans=0;

    ordered_set os;

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

    {

        if(p[i]>=k*i)

            ans++;



        x=p[i]-k*i;

        ll c=0;

        if(M.find(x)!=M.end())

            c=M[x];



        ans+=(ll)os.order_of_key({x,-i})+c;

        M[x]++;

        os.insert({x,-i});

    }

    cout<<ans<<endl;

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

}


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

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

}


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

}
// 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 <= 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;

}
// 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 <= 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;

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

}


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

    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>



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;

}


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

    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>



// 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 <= 32){

    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 <= 32){

    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>



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;

}


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



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;

}


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

}