stablegradients/pie-gem5-pairs huggingface dataset:
// 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)

    {

        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;

    }

    sort(t,t+n+1);

    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]);

        add(sum[i]);

    }

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

}


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

using namespace std;



#define int long long

#define fi first

#define se second

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

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

#define yn(x) ((x) ? "YES" : "NO")



typedef pair <int, int> ii;

typedef pair <int, ii> iii;



const int siz = 2e5 + 10;

const int SIZ = 2e5 + 10;

const int mod = 1e9 + 7;

const int maxx = 2e9;

const int MAXX = 1e18;

const string file = "data";



int n;

int psum[siz];



void compress() {

    vector <ii> data; /// value, index;

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

        data.push_back(ii(psum[i], i));

    }



    sort (all(data));



    int num = 0, prv = MAXX;

    for (auto &x : data) {

        if (x.fi != prv) {

            prv = x.fi;

            num++;

        }

        psum[x.se] = num;

    }

}



int fen[SIZ];



void updatePos(int index, int value) {

    for (int i = index; i < SIZ; i += i & (-i)) {

        fen[i] += value;

    }

}



int getSum(int index) {

    int sum = 0;

    for (int i = index; i > 0; i -= i & (-i)) {

        sum += fen[i];

    }

    return sum;

}



int32_t main() {

    ios::sync_with_stdio(0);

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



//    freopen ((file + ".inp").c_str(), "r", stdin);

//    freopen ((file + ".out").c_str(), "w", stdout);



    int k;

    cin >> n >> k;



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

        int a;

        cin >> a;



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

    }



    compress();



    int ans = 0;

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

        ans += getSum(psum[i]);

        updatePos(psum[i], 1);

    }



    cout << ans << "\n";



//    cerr << "Time: " << 1000 * clock() / CLOCKS_PER_SEC << "ms\n";



    return 0;

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

#include<algorithm>

#include<cmath>

#include<string.h>

#include<cstdio>

#include<map>

using namespace std;

typedef long long ll;

const int MAX=200000+10; 

int n,k;

ll a[MAX];

ll b[MAX];

ll s[MAX];

map<ll, int>mp;

int lowbit(int x)

{

	return (x&-x);

}

ll sum(int x)

{

	ll ans=0;

	while(x>0)

	{

		ans+=a[x];

		x-=lowbit(x);

	}

	return ans;

}

void inite(int x,int num)//维护前缀数组a 

{

    while(x<=n+1){

        a[x]+=(long long)num;

        x+=lowbit(x);

    }

}

int main()

{

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

	s[0]=b[0]=0;

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

	{	

		int t;

		scanf("%d",&t);

		s[i]=s[i-1]+(long long)(t-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;

	memset(a,0,sizeof(a));

	ll res=0;

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

	{

		res+=sum(mp[s[i]]);

		inite(mp[s[i]],1);

	}

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

return 0;

}

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

using namespace std;



#define int long long

#define fi first

#define se second

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

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

#define yn(x) ((x) ? "YES" : "NO")



typedef pair <int, int> ii;

typedef pair <int, ii> iii;



const int siz = 2e5 + 10;

const int SIZ = 2e5 + 10;

const int mod = 1e9 + 7;

const int maxx = 2e9;

const int MAXX = 1e18;

const string file = "data";



int n;

int psum[siz];



void compress() {

    vector <ii> data; /// value, index;

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

        data.push_back(ii(psum[i], i));

    }



    sort (all(data));



    int num = 0, prv = MAXX;

    for (auto &x : data) {

        if (x.fi != prv) {

            prv = x.fi;

            num++;

        }

        psum[x.se] = num;

    }

}



int fen[SIZ];



void updatePos(int index, int value) {

    for (int i = index; i < SIZ; i += i & (-i)) {

        fen[i] += value;

    }

}



int getSum(int index) {

    int sum = 0;

    for (int i = index; i > 0; i -= i & (-i)) {

        sum += fen[i];

    }

    return sum;

}



int32_t main() {

    ios::sync_with_stdio(0);

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



//    freopen ((file + ".inp").c_str(), "r", stdin);

//    freopen ((file + ".out").c_str(), "w", stdout);



    int k;

    cin >> n >> k;



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

        int a;

        cin >> a;



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

    }



    compress();



    int ans = 0;

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

        ans += getSum(psum[i]);

        updatePos(psum[i], 1);

    }



    cout << ans << "\n";



//    cerr << "Time: " << 1000 * clock() / CLOCKS_PER_SEC << "ms\n";



    return 0;

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

#include <cstring>

#include <cstdlib>

#include <vector>

#include <iostream>

using namespace std;



typedef long long int LL;

const LL INF=1000000000000000ll;

const int maxn=100000*64;

struct ACM

{

    struct Node

    {

        LL val;

        int lson,rson;

    }seg[maxn];

    int sz;

    int newnode()

    {

        sz++;

        seg[sz].val=0;

        seg[sz].rson=-1;

        seg[sz].lson=-1;

        return sz;

    }

    void init()

    {

        sz=-1;

    }

    void update(int &root,LL l,LL r,LL val)

    {

        if(root==-1) root=newnode();

        seg[root].val++;

        if(l==r) return ;

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

        if(val<=mid) update(seg[root].lson,l,mid,val);

        else update(seg[root].rson,mid+1,r,val);

    }

    LL query(int root,LL l,LL r,LL ql,LL qr)

    {

        if(root==-1) return 0;

        if(l==ql&&r==qr) return seg[root].val;

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

        if(qr<=mid) return query(seg[root].lson,l,mid,ql,qr);

        else if(ql>mid) return query(seg[root].rson,mid+1,r,ql,qr);

        else return query(seg[root].lson,l,mid,ql,mid)+query(seg[root].rson,mid+1,r,mid+1,qr);

    }

    /**

    void debug(int i)

    {

        if(i==-1) return ;

        printf("node=%d val=%lld lson=%d rson=%d\n",i,seg[i].val,seg[i].lson,seg[i].rson);

        debug(seg[i].lson),debug(seg[i].rson);

    }

    */

}AC;



int main()

{

    int n,k,root=-1;

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

    LL sum=0,ans=0;

    AC.init();

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

    {

        int num;

        scanf("%d",&num);

		num-=k;

        AC.update(root,-INF,INF,sum);

        sum+=num;

        ans+=AC.query(root,-INF,INF,-INF,sum);

    }

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

    return 0;

}


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

#include <cstring>

#include <algorithm>

using namespace std;

typedef long long ll;



const int MAX_N = 200000;



ll cnt = 0ll;

int n;

ll K, a[MAX_N + 10], s[MAX_N + 10], b[MAX_N + 10], t[MAX_N + 10];



void merge_sort(ll* A, int x, int y, ll* T) {

    if (y - x > 1) {

        int m = x + (y - x) / 2;

        int p = x, q = m, i = x;

        merge_sort(A, x, m, T);

        merge_sort(A, m, y, T);

        while (p < m || q < y) {

            if (q >= y || (p < m && A[p] <= A[q])) T[i++] = A[p++];

            else { T[i++] = A[q++]; cnt += m - p; }

        }

        for (i = x; i < y; i++) A[i] = T[i];

    }

}



int main() {

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

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

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

        s[i] = a[i] + (i ? s[i - 1] : 0);

        b[i] = (i ? s[i - 1] : 0) - K * i;

    }

    b[n] = s[n - 1] - n * K;

    merge_sort(b, 0, n + 1, t);

    printf("%lld\n", (ll)n * (n + 1) / 2 - cnt);

    return 0;

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

using namespace std;

#define maxn 200010

#define lowb(x) (x & (-x))

int t[maxn], n, c[maxn], d[maxn];

long long a[maxn], b[maxn];

void add(int x) {

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

		t[i]++;

	}

}

long long query(int x) {

	long long s = 0;

	for (int i = x; i > 0; i -= lowb(i)) {

		s += t[i];

	}

	return s;

}

int cmp(int i, int j) {

	return b[i] < b[j];

}

int main()

{

	int k;

	

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

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

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

	}

	b[0] = 0;

	c[0] = 0;

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

		c[i] = i;

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

	}

	stable_sort(c, c + n + 1, cmp);

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

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

	}

	long long s = 0;

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

		s += query(d[i]);

		add(d[i]);

	}

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

}

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

#include <cstring>

#include <algorithm>

using namespace std;

typedef long long ll;



const int MAX_N = 200000;



ll cnt = 0ll;

int n;

ll K, a[MAX_N + 10], s[MAX_N + 10], b[MAX_N + 10], t[MAX_N + 10];



void merge_sort(ll* A, int x, int y, ll* T) {

    if (y - x > 1) {

        int m = x + (y - x) / 2;

        int p = x, q = m, i = x;

        merge_sort(A, x, m, T);

        merge_sort(A, m, y, T);

        while (p < m || q < y) {

            if (q >= y || (p < m && A[p] <= A[q])) T[i++] = A[p++];

            else { T[i++] = A[q++]; cnt += m - p; }

        }

        for (i = x; i < y; i++) A[i] = T[i];

    }

}



int main() {

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

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

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

        s[i] = a[i] + (i ? s[i - 1] : 0);

        b[i] = (i ? s[i - 1] : 0) - K * i;

    }

    b[n] = s[n - 1] - n * K;

    merge_sort(b, 0, n + 1, t);

    printf("%lld\n", (ll)n * (n + 1) / 2 - cnt);

    return 0;

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

#include <ext/pb_ds/assoc_container.hpp>

using namespace __gnu_pbds; 

using namespace std;

template<class T> using rset = tree<T,null_type,less<T>,rb_tree_tag,tree_order_statistics_node_update>; 



using ll = long long;

using db = double;

using vi = vector<int>;

const int maxn = 1000000; 



ll n, k; 

ll a[maxn], s[maxn]; 

rset<pair<ll,int>> S; 



int main() {

	cin>>n>>k; 

	s[0] = 0; 

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

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

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

	}

	S.insert({s[0],0}); 

	ll ans = 0; 

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

		S.insert({s[i],i}); 

		ans += S.order_of_key({s[i],i});

	}

	cout<<ans<<endl; 

}


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

#include <cstring>

#include <algorithm>

using namespace std;

typedef long long ll;



const int MAX_N = 200000;



ll cnt = 0ll;

int n;

ll K, a[MAX_N + 10], s[MAX_N + 10], b[MAX_N + 10], t[MAX_N + 10];



void merge_sort(ll* A, int x, int y, ll* T) {

    if (y - x > 1) {

        int m = x + (y - x) / 2;

        int p = x, q = m, i = x;

        merge_sort(A, x, m, T);

        merge_sort(A, m, y, T);

        while (p < m || q < y) {

            if (q >= y || (p < m && A[p] <= A[q])) T[i++] = A[p++];

            else { T[i++] = A[q++]; cnt += m - p; }

        }

        for (i = x; i < y; i++) A[i] = T[i];

    }

}



int main() {

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

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

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

        s[i] = a[i] + (i ? s[i - 1] : 0);

        b[i] = (i ? s[i - 1] : 0) - K * i;

    }

    b[n] = s[n - 1] - n * K;

    merge_sort(b, 0, n + 1, t);

    printf("%lld\n", (ll)n * (n + 1) / 2 - cnt);

    return 0;

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

#include<cstdio>

#include<map>

#include<algorithm>

using namespace std;

typedef long long ll;

map<ll,int> t;

int cnt;

const int N=2e5+5;

int n;ll k,a[N]={0},as[N];

int bit[N]={0};

void add(int x,int val) {

    while(x<cnt) bit[x]+=val,x+=x&-x;

}

int sum(int x) {

    int s=0;while(x) s+=bit[x],x-=x&-x;return s;

}

int main() {

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

    t.clear();

    for(int i=1;i<=n;i++) scanf("%lld",a+i),a[i]-=k,a[i]+=a[i-1],as[i]=a[i];

    ll ans=0;

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

    cnt=1;

    for(int i=1;i<=n;i++) if(!t.count(as[i])) t[as[i]]=cnt++;

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

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

        ans+=sum(t[a[i]]);

        add(t[a[i]],1);

    }

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

    return 0;

}


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

#include <cstring>

#include <algorithm>

using namespace std;

typedef long long ll;



const int MAX_N = 200000;



ll cnt = 0ll;

int n;

ll K, a[MAX_N + 10], s[MAX_N + 10], b[MAX_N + 10], t[MAX_N + 10];



void merge_sort(ll* A, int x, int y, ll* T) {

    if (y - x > 1) {

        int m = x + (y - x) / 2;

        int p = x, q = m, i = x;

        merge_sort(A, x, m, T);

        merge_sort(A, m, y, T);

        while (p < m || q < y) {

            if (q >= y || (p < m && A[p] <= A[q])) T[i++] = A[p++];

            else { T[i++] = A[q++]; cnt += m - p; }

        }

        for (i = x; i < y; i++) A[i] = T[i];

    }

}



int main() {

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

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

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

        s[i] = a[i] + (i ? s[i - 1] : 0);

        b[i] = (i ? s[i - 1] : 0) - K * i;

    }

    b[n] = s[n - 1] - n * K;

    merge_sort(b, 0, n + 1, t);

    printf("%lld\n", (ll)n * (n + 1) / 2 - cnt);

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

#include <cstring>

#include <algorithm>

using namespace std;

typedef long long ll;



const int MAX_N = 200000;



ll cnt = 0ll;

int n;

ll K, a[MAX_N + 10], s[MAX_N + 10], b[MAX_N + 10], t[MAX_N + 10];



void merge_sort(ll* A, int x, int y, ll* T) {

    if (y - x > 1) {

        int m = x + (y - x) / 2;

        int p = x, q = m, i = x;

        merge_sort(A, x, m, T);

        merge_sort(A, m, y, T);

        while (p < m || q < y) {

            if (q >= y || (p < m && A[p] <= A[q])) T[i++] = A[p++];

            else { T[i++] = A[q++]; cnt += m - p; }

        }

        for (i = x; i < y; i++) A[i] = T[i];

    }

}



int main() {

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

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

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

        s[i] = a[i] + (i ? s[i - 1] : 0);

        b[i] = (i ? s[i - 1] : 0) - K * i;

    }

    b[n] = s[n - 1] - n * K;

    merge_sort(b, 0, n + 1, t);

    printf("%lld\n", (ll)n * (n + 1) / 2 - cnt);

    return 0;

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

#include<cstring>

#include<algorithm>

using std::scanf;

using std::printf;

using std::memset;

struct node

{

  long long data;

  int id;

  bool operator< (const node& o) const

  { return this->data < o.data;}

};



typedef long long llong;

const int maxn = 200010;



llong treeset[maxn];

llong end[maxn];

node rec[maxn];

llong n;

llong k;



inline int lowbit(int x)

{ return x&(-x);}



void add(int x, llong d)

{

  while(x <= n)

  {

    treeset[x] += d;

    x += lowbit(x);

  }

}



llong sum(int x)

{

  llong ans = 0;

  while(x)

  {

    ans += treeset[x];

    x -= lowbit(x);

  }

  return ans;

}



int main()

{

  llong tmp;

  llong ans = 0;

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

  memset(rec, 0, sizeof(rec));

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

  {

    scanf("%lld", &tmp);

    rec[i].data = rec[i-1].data +tmp-k;

    rec[i].id = i;

  }

  std::sort(rec+1, rec+1+n);

  end[rec[1].id] = 1;

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

  {

    if(rec[i].data != rec[i-1].data)

    { end[rec[i].id] = i;}

    else

    { end[rec[i].id] = end[rec[i-1].id];}

  }

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

  {

    add(end[i], 1);

    ans += sum(n) - sum(end[i]);

  }

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

  {

    if(rec[i].data < 0)

    { ++ans;}

  }

  ans = n*(n+1)/2 - ans;

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

}


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

#include<iostream>

#include<cstdio>

#include<cstring>

#include<map>

using namespace std;

typedef long long ll;

const int maxn = 200000 + 10;

ll a[maxn];

ll c[maxn];

int n, k;

struct node{

    ll v;

	int t;

    int id;

}d[maxn];



bool cmp(node f, node g){

    return f.v < g.v;

}



bool cmp1(node f, node g){

    return f.id < g.id;

}



int lowbit(int x){

    return x & (-x);

}



void add(int x, ll value){

    while(x < maxn){

        c[x] += value;

        x = x + lowbit(x);

    }

}



ll sum(int x){

    ll ans = 0;

    while(x > 0){

        ans += c[x];

        x = x - lowbit(x);

    }

    return ans;

}



int main(){

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



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

        scanf("%d", &a[i]);

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



    }

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

        d[i].v = d[i - 1].v + a[i];

        d[i].id = i;

    }

    d[0].v = 0;

    d[0].id = 0;

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

    int cnt = 0;

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

        if(i == 0 || d[i].v != d[i - 1].v){

            cnt++;

            d[i].t = cnt;

        }else d[i].t = d[i - 1].t;

    }

    sort(d, d + n + 1, cmp1);

    ll ans = 0;





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



       ans += sum(d[i].t);

       add(d[i].t, 1);

    }

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

    return 0;

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

#include<cstring>

#include<algorithm>

using std::scanf;

using std::printf;

using std::memset;

struct node

{

  long long data;

  int id;

  bool operator< (const node& o) const

  { return this->data < o.data;}

};



typedef long long llong;

const int maxn = 200010;



llong treeset[maxn];

llong end[maxn];

node rec[maxn];

llong n;

llong k;



inline int lowbit(int x)

{ return x&(-x);}



void add(int x, llong d)

{

  while(x <= n)

  {

    treeset[x] += d;

    x += lowbit(x);

  }

}



llong sum(int x)

{

  llong ans = 0;

  while(x)

  {

    ans += treeset[x];

    x -= lowbit(x);

  }

  return ans;

}



int main()

{

  llong tmp;

  llong ans = 0;

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

  memset(rec, 0, sizeof(rec));

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

  {

    scanf("%lld", &tmp);

    rec[i].data = rec[i-1].data +tmp-k;

    rec[i].id = i;

  }

  std::sort(rec+1, rec+1+n);

  end[rec[1].id] = 1;

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

  {

    if(rec[i].data != rec[i-1].data)

    { end[rec[i].id] = i;}

    else

    { end[rec[i].id] = end[rec[i-1].id];}

  }

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

  {

    add(end[i], 1);

    ans += sum(n) - sum(end[i]);

  }

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

  {

    if(rec[i].data < 0)

    { ++ans;}

  }

  ans = n*(n+1)/2 - ans;

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

}


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

#include <cstdio>

#include <cstring>

#include <cmath>

#include <algorithm>

#define maxn 1000100

using namespace std;

typedef long long ll;

ll n,k;

ll sans[maxn];

ll s[maxn];

ll chara[maxn];

ll lowbit(ll x)

{

    return x&(-x);

}

void upd(ll x,ll t)

{

    while(x<=n)

    {

        sans[x]+=t;

        x+=lowbit(x);

    }

}

ll sum(ll x)

{

    ll ans=0;

    while(x>0)

    {

        ans+=sans[x];

        x-=lowbit(x);

    }

    return ans;

}





int main()

{

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

    ll a;

    int cnt=0;

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

    {

        scanf("%I64d",&a);

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

        chara[cnt++]=s[i];

    }

    ll ans=0;

    sort(chara,chara+cnt);

    int siz=unique(chara,chara+cnt)-chara;

    ll t;

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

    {

        t=lower_bound(chara,chara+siz,s[i])-chara+1;

        ans+=sum(t);

        upd(t,1);

    }

    cout<<ans<<endl;

    return 0;

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

#include<cstring>

#include<algorithm>

using std::scanf;

using std::printf;

using std::memset;

struct node

{

  long long data;

  int id;

  bool operator< (const node& o) const

  { return this->data < o.data;}

};



typedef long long llong;

const int maxn = 200010;



llong treeset[maxn];

llong end[maxn];

node rec[maxn];

llong n;

llong k;



inline int lowbit(int x)

{ return x&(-x);}



void add(int x, llong d)

{

  while(x <= n)

  {

    treeset[x] += d;

    x += lowbit(x);

  }

}



llong sum(int x)

{

  llong ans = 0;

  while(x)

  {

    ans += treeset[x];

    x -= lowbit(x);

  }

  return ans;

}



int main()

{

  llong tmp;

  llong ans = 0;

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

  memset(rec, 0, sizeof(rec));

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

  {

    scanf("%lld", &tmp);

    rec[i].data = rec[i-1].data +tmp-k;

    rec[i].id = i;

  }

  std::sort(rec+1, rec+1+n);

  end[rec[1].id] = 1;

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

  {

    if(rec[i].data != rec[i-1].data)

    { end[rec[i].id] = i;}

    else

    { end[rec[i].id] = end[rec[i-1].id];}

  }

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

  {

    add(end[i], 1);

    ans += sum(n) - sum(end[i]);

  }

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

  {

    if(rec[i].data < 0)

    { ++ans;}

  }

  ans = n*(n+1)/2 - ans;

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

}


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

#include <cstdio>

#include <cstring>

#include <cmath>

#include <algorithm>

#define maxn 1000100

using namespace std;

typedef long long ll;

ll n,k;

ll sans[maxn];

ll s[maxn];

ll chara[maxn];

ll lowbit(ll x)

{

    return x&(-x);

}

void upd(ll x,ll t)

{

    while(x<=n)

    {

        sans[x]+=t;

        x+=lowbit(x);

    }

}

ll sum(ll x)

{

    ll ans=0;

    while(x>0)

    {

        ans+=sans[x];

        x-=lowbit(x);

    }

    return ans;

}





int main()

{

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

    ll a;

    int cnt=0;

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

    {

        scanf("%I64d",&a);

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

        chara[cnt++]=s[i];

    }

    s[0]=0;

    ll ans=0;

    sort(chara,chara+cnt);

    int siz=unique(chara,chara+cnt)-chara;

    ll t;

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

    {

        t=lower_bound(chara,chara+siz,s[i])-chara+1;

        ans+=sum(t);

        upd(t,1);

    }

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

    return 0;

}