stablegradients/pie-gem5-pairs huggingface dataset:
// Slower C++ solution:
#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;

}

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

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

}


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

}
// Slower C++ solution:


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

}

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

#include<cstdio>

#include<cstdlib>

#include<cstring>

#include<algorithm>

#include<map>

using namespace std;



const int maxn=2e5+5;



map<long long,int>mp;

long long a[maxn],b[maxn],c[maxn],d[maxn],n,m,K,ans=0;



int lowbit(int x)

{

    return x&(-x);

}

int getsum(int x)

{

    int sum=0;

    while(x)

    {

        sum+=c[x];

        x-=lowbit(x);

    }

    return sum;

}



void add(int x)

{

    while(x<maxn)

    {

        c[x]++;

        x+=lowbit(x);

    }

}



int main()

{

    cin>>n>>K;

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

    {

        cin>>a[i];

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

        b[i]=a[i]-K*i;

        d[i]=b[i];

    }

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

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

    for(long long i=1;i<m;i++)

    {

        mp[b[i]]=i;

    }

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

    {

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

        ans=ans+getsum(mp[d[i]]);

        add(mp[d[i]]);

    }

    cout<<ans;

    return 0;

}
// Slower C++ solution:


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

}

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

using namespace std;

long long arr[200000+10];

long long a[200000+10];

long long n,k;

long long ans = 0;

void Merge(int l,int mid,int r)

{

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

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

    {

        if(arr[i]>arr[j])

        {

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

            ans+=mid-i+1;

        }

        else

		{

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

		}

    }

    while(i<=mid)

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

    while(j<=r)

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

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

        arr[e]=a[e];

}

void Merge_sort(int l,int r)

{

    if(l<r)

    {

        int mid=(l+r)/2;

        Merge_sort(l,mid);

        Merge_sort(mid+1,r);

        Merge(l,mid,r);

    }

}

int main()

{

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

	arr[0] = 0;

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

	{

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

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

	}

	Merge_sort(0,n);

	printf("%lld\n",(n*n+n)/2-ans);

	return 0;

}
// Slower C++ solution:


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

}

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

#include<cmath>

#include<ctime>

#include<queue>

#include<stack>

#include<cstdio>

#include<cstring>

#include<iostream>

#include<algorithm>

using namespace std;

typedef long long ll;

inline int read(){

	int ans=0,fh=1;

	char ch=getchar();

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

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

		ch=getchar();

	}

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

		ans=(ans<<1)+(ans<<3)+ch-'0',ch=getchar();

	return ans*fh;

}

const int maxn=4e5+100;

int n,k,siz[maxn<<2],mx;

ll a[maxn],b[maxn];

map<ll,int>bh;

inline void lsh(){

	for(int i=1;i<=n;i++) b[i]=a[i];

	sort(b+1,b+n+1),b[0]=b[1]-1;

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

		if(b[i]!=b[i-1]) bh[b[i]]=++mx;

	for(int i=1;i<=n;i++) a[i]=bh[a[i]];

}

void insert(int o,int l,int r,int qz){

	siz[o]++;

	if(l==r) return;

	int mid=l+r>>1;

	if(qz<=mid) insert(o<<1,l,mid,qz);

	else insert(o<<1|1,mid+1,r,qz);

}

ll query(int o,int l,int r,int ql,int qr){

	if(ql==l&&qr==r) return siz[o];

	int mid=l+r>>1;

	ll ans=0;

	if(ql<=mid) ans=query(o<<1,l,mid,ql,min(qr,mid));

	if(qr>mid) ans+=query(o<<1|1,mid+1,r,max(ql,mid+1),qr);

	return ans;

}

int main(){

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

	n=read(),k=read();

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

		b[i]=read()-k;

	for(int i=1;i<=n+1;i++) a[i]=a[i-1]+b[i-1];

	n++,lsh();

	ll ans=0;

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

		ans+=query(1,1,mx,1,a[i]);

		insert(1,1,mx,a[i]);

	}

	cout<<ans<<endl;

	return 0;

}
// Slower C++ solution:


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

}

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

using namespace std;

#define debug(x) cout << #x": " << x << endl;

inline int lowbit(int x) { return x & -x; }

typedef long long LL;

const int N = 2e5 + 10;

const int inf = 0x3f3f3f3f;

const int mod = 1e9 + 7;



LL a[N];

LL b[N];

int bits[N];



inline void update(int pos) {

    for (; pos < N; pos += lowbit(pos))

        bits[pos]++;

}

inline int query(int pos) {

    int res = 0;

    for (; pos; pos -= lowbit(pos))

        res += bits[pos];

    return res;

}



int main() {

#ifdef purple_bro

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

#endif // purple_bro

    int n, k;



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



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

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

        a[i] -= k;

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

        b[i] = a[i];

    }



    b[n + 1] = 0;

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

    int tot = unique(b + 1, b + 1 + n + 1) - b - 1;



    int pos = lower_bound(b + 1, b + 1 + tot, 0) - b;

    update(pos);



    LL ans = 0;



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

        int pos = lower_bound(b + 1, b + 1 + tot, a[i]) - b;

        ans += query(pos);

        update(pos);

    }



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



    return 0;

}
// Slower C++ solution:


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

}

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


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

}

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

using namespace std;

#define MID (l+r)/2

#define ll long long

typedef pair<ll, ll> ii;

#define S second

#define F first



ll seg[1000000];

ll n, k;



void update(ll p, ll l=0, ll r=n-1, ll ind=1){

	if(l==r && l==p)

		seg[ind]++;

	else if(l==r || p<l || p>r) return;

	else{

		update(p, l, MID, ind*2);

		update(p, MID+1, r, ind*2+1);

		seg[ind] = seg[ind*2] + seg[ind*2+1];

	}

}



ll query(ll rl, ll rr, ll l=0, ll r=n-1, ll ind=1){

	if(rl<=l && r<=rr) return seg[ind];

	else if(rl>r || l>rr) return 0;

	else{

		return query(rl, rr, l, MID, ind*2) + query(rl, rr, MID+1, r, ind*2+1);

	}

}



int main(){

	cin>>n>>k;

	ll a[n];

	ll tot=0;

	ll t[n+1];

	vector<ii> s;

	//s.push_back(ii(0,0));

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

		cin>>a[i];

		tot+=a[i];

		tot-=k;

		t[i] = tot;

		s.push_back(ii(t[i], i));

	}

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

	ll ans=0;

	for(ll i=s.size()-1;i>=0;i--){

		if(s[i].F>=0) ans++;

		ans += query(s[i].S + 1, n-1);

		update(s[i].S);

	}

	cout<<ans<<endl;

}
// Slower C++ solution:


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

}

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

#define fi first

#define se second

#define ii pair<int, int>

#define iii tuple<int, int, int>

#define int long long

using namespace std;



int n, k;

int ans = 0;

int psum[200005];

int tree[800005];

ii tmp[200005];



void upd(int id, int l, int r, int i)

{

    if (i < l || i > r)

        return;

    if (l == r)

    {

        if (l == i)

            tree[id]++;

        return;

    }



    int mid = (l + r) / 2;

    upd(id*2, l, mid, i);

    upd(id*2 + 1, mid+1, r, i);

    tree[id] = tree[id*2] + tree[id*2 + 1];

}



int get(int id, int l, int r, int u, int v)

{

    if (v < l || r < u)

        return 0;



    if (u <= l && r <= v)

        return tree[id];



    int mid = (l + r) / 2;

    return get(id*2, l, mid, u, v) + get(id*2 + 1, mid+1, r, u, v);

}



void compress()

{

    int last = 1e18, cnt = 0;

    sort(tmp, tmp + n + 1);

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

    {

        if (last != tmp[i].fi)

        {

            cnt++;

            last = tmp[i].fi;

        }

        psum[tmp[i].se] = cnt;

    }

}



int32_t main()

{

    ios::sync_with_stdio(0);

    cin.tie(0);

    cout.tie(0);



//    freopen("depart.inp", "r", stdin);

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



    cin >> n >> k;

    int sum = 0;



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

    {

        int x;

        cin >> x;

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

        tmp[i].fi = psum[i];

        tmp[i].se = i;

    }

    compress();



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

    {

        ans += get(1, 0, n, 0, psum[i]);

        upd(1, 0, n, psum[i]);

    }

    cout << ans;

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

}

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

}