stablegradients/pie-gem5-pairs huggingface dataset:
// Slower C++ solution:
//#pragma GCC optimize("O3")



#include <bits/stdc++.h>



using namespace std;

const int N = 1e5 + 5;



int arr[N];



int main() {

   // freopen("in.txt", "rt", stdin);

    int n, k;

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

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

        scanf("%d", arr + i);

    }

    int ans = 1e9;

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

        int a = arr[i - k + 1], b = arr[i];

        int v = 0;

        if (a >= 0 && b >= 0) {

            v = b;

        }

        if (a <= 0 && b <= 0) {

            v = -a;

        }

        if (a <= 0 && b >= 0) {

            v = b - a;

            v += min(b, -a);

        }

        ans = min(ans, v);

    }

    printf("%d", ans);

}

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

#include<cstring>

#include<algorithm>

const int maxn=1e5+10;

int n,k,x[maxn],ans=0x7fffffff;

int main()

{

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

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

    {

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

    }

    for(int l=1;l+k-1<=n;l++)

    {

        int r=l+k-1;

        ans=std::min(ans,x[r]-x[l]+std::min(abs(x[l]),abs(x[r])));

    }

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

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

using namespace std;

int main()

{

    int d,n,dif,min=1000000000,i,p,q;

    cin>>n>>d;

    int a[n];

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

    {

        cin>>a[i];

    }

    if(d==1)

    {

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

        {

            dif=abs(a[i]);

            if(min>dif)

            {

                min=dif;

            }

        }

        cout<<min<<endl;

        return 0;

    }

    for(i=0; i<n-d+1; i++)

    {

        if(a[i]<0&&a[i+d-1]<=0)

        {

            dif=0-a[i];

            //cout<<"1"<<endl;

        }

        else if(a[i]<0&&a[i+d-1]>0)

        {

            p=a[i+d-1];

            q=0-a[i];

            if(p>q)

            {

                dif=2*q+p;

            }

            else

            {

                dif=2*p+q;

            }

            //dif=a[i+d-1]+(0-a[i]);

            //cout<<"2"<<endl;

        }

        else if(a[i]>=0&&a[i+d-1]>0)

        {

            dif=a[i+d-1]-0;

            //cout<<"3"<<endl;

        }

        //cout<<dif<<endl;

        if(dif<min)

        {

            min=dif;

        }

    }

    cout<<min;

}


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

#include<cstring>

#include<algorithm>

const int maxn=1e5+10;

int n,k,x[maxn],ans=0x7fffffff;

int main()

{

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

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

    {

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

    }

    for(int l=1;l+k-1<=n;l++)

    {

        int r=l+k-1;

        ans=std::min(ans,x[r]-x[l]+std::min(abs(x[l]),abs(x[r])));

    }

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

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

using namespace std;

int main(void)

{

    std::ios::sync_with_stdio(false);

    long long int n,k,a,b,c,d=1e15;

    cin>>n>>k;

    int x[n];

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

    {

        cin>>x[i];

    }

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

    {

        a=i;

        b=i+k-1;

        c=min(abs(x[a])+abs(x[a]-x[b]), abs(x[b])+abs(x[a]-x[b]));

        d=min(c,d);

    }

    cout<<d<<endl;

}


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

#include<cstring>

#include<algorithm>

const int maxn=1e5+10;

int n,k,x[maxn],ans=0x7fffffff;

int main()

{

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

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

    {

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

    }

    for(int l=1;l+k-1<=n;l++)

    {

        int r=l+k-1;

        ans=std::min(ans,x[r]-x[l]+std::min(abs(x[l]),abs(x[r])));

    }

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

}
// Slower C++ solution:
// 基本テンプレート

 

#include <iostream>

#include <iomanip>

#include <cstdio>

#include <string>

#include <cstring>

#include <deque>

#include <list>

#include <queue>

#include <stack>

#include <vector>

#include <utility>

#include <algorithm>

#include <map>

#include <set>

#include <complex>

#include <cmath>

#include <limits>

#include <cfloat>

#include <climits>

#include <ctime>

#include <cassert>

#include <numeric>

#include <fstream>

#include <functional>

using namespace std;

 

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

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

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

#define int long long int

 

template<typename T> void chmax(T &a, T b) {a = max(a, b);}

template<typename T> void chmin(T &a, T b) {a = min(a, b);}

template<typename T> void chadd(T &a, T b) {a = a + b;}

 

typedef pair<int, int> pii;

typedef long long ll;

 

int dx[] = {0, 0, 1, -1};

int dy[] = {1, -1, 0, 0};

const ll INF = 1001001001001001LL;

const ll MOD = 1000000007LL;

 

signed main() {

    int N; cin >> N;

    int S = 0, mi = INF, ans = 0;

    rep(i,0,N) {

        int x, s; cin >> x >> s;

        int prev = S, cur = S + s;

        prev -= x; cur -= x;

        mi = min(mi, prev);

        ans = max(ans, cur - mi);

        S += s;

    }

    cout << ans << endl;

    return 0;

}

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

#include <algorithm>

using namespace std;

using ll = long long int;



const int S = 200010;

ll x[S], s[S], dp[S];

int main() {

    ll N, ans; scanf("%lld", &N);

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

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

    }



    ans = dp[0] = s[0];

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

        dp[i] = max(s[i], dp[i-1] + s[i] - (x[i] - x[i-1]));

        ans = max(ans, dp[i]);

    }

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

    return 0;

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



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

#define reps(i,x,n) for(int i=x; i<(n); i++)

#define rrep(i,n) for(int i=(n)-1; i>=0; i--)

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

#define X first

#define Y second

#define pb push_back

#define eb emplace_back



using namespace std;

typedef long long int ll;

typedef pair<int,int> pii;

typedef pair<ll,ll> pll;



template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }

template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }



template<class A, size_t N, class T> void Fill(A (&a)[N], const T &v){ fill( (T*)a, (T*)(a+N), v ); }



const ll INF = 1e9+7;







template <typename T>

class RMQ {

	T query(int l, int r, int a, int b, int k){

		if( l <= a && b <= r ){

			return seg[k];

		}else if( l < b && a < r ){

			int m = (b+a)/2;

			T vl = query(l,r, a, m, k*2);

			T vr = query(l,r, m, b, k*2+1);

			return min(vl, vr);	// merge

		}

		return INF;	// default value

	}

public:

	vector<T> seg;	// セグメントツリー (親:k/2  子:k*2,k*2+1)

	int N;

	RMQ(int size){

		N = 1;

		while( N < size ) N<<=1;

		seg.assign(N*2, INF);		// default value

	}

	void update(int pos, T v){

		for(int k=N+pos; k>0; k/=2){

			seg[k] = v;

			v = min(seg[k], seg[k^1]);	// merge

		}

	}

	// [l,r)

	T get(int l, int r){

		return query(l, r, 0, N, 1);

	}

	T get(int pos){		// =get(pos, pos+1)

		return seg[N+pos];

	}

};



int main(){

	//ios_base::sync_with_stdio(false);

	ll N, ans=0;

	ll x[200005], s[200005];



	cin >> N;

	rep(i,N) cin >> x[i] >> s[i];

	x[N] = x[N-1];



	rep(i,N) chmax(ans, s[i]);



//	set<ll> st;

//	map<ll,ll> mp;

//	rep(i,N) st.insert(x[i]);

//	for(auto t: st) mp[t] = mp.size();



	RMQ<ll> sg(200005);

	ll sum = 0;

	sg.update(0,0);

	rep(i,N){

		sum += s[i];

		ll mn  = sg.get(0,i+1);

		chmax(ans, sum - mn);

		ll d = x[i+1] - x[i];

		sum -= d;

		sg.update(i+1, sum);

	}



	cout << ans << endl;



	return 0;

}


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



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

#define reps(i,x,n) for(int i=x; i<(n); i++)

#define rrep(i,n) for(int i=(n)-1; i>=0; i--)

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

#define X first

#define Y second

#define pb push_back

#define eb emplace_back



using namespace std;

typedef long long int ll;

typedef pair<int,int> pii;

typedef pair<ll,ll> pll;



template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }

template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }



template<class A, size_t N, class T> void Fill(A (&a)[N], const T &v){ fill( (T*)a, (T*)(a+N), v ); }



const ll INF = 1e18+7;





int main(){

	//ios_base::sync_with_stdio(false);

	ll N, ans=0;

	ll x[200005], s[200005];



	cin >> N;

	rep(i,N) cin >> x[i] >> s[i];



	ll sum = 0, mn = 0;

	rep(i,N){

		sum += s[i];

		chmax(ans, sum - mn);

		ll d = x[i+1] - x[i];

		sum -= d;

		chmin(mn, sum);

	}



	cout << ans << endl;



	return 0;

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



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

#define reps(i,x,n) for(int i=x; i<(n); i++)

#define rrep(i,n) for(int i=(n)-1; i>=0; i--)

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

#define X first

#define Y second

#define pb push_back

#define eb emplace_back



using namespace std;

typedef long long int ll;

typedef pair<int,int> pii;

typedef pair<ll,ll> pll;



template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }

template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }



template<class A, size_t N, class T> void Fill(A (&a)[N], const T &v){ fill( (T*)a, (T*)(a+N), v ); }



const ll INF = 1e9+7;







template <typename T>

class RMQ {

	T query(int l, int r, int a, int b, int k){

		if( l <= a && b <= r ){

			return seg[k];

		}else if( l < b && a < r ){

			int m = (b+a)/2;

			T vl = query(l,r, a, m, k*2);

			T vr = query(l,r, m, b, k*2+1);

			return min(vl, vr);	// merge

		}

		return INF;	// default value

	}

public:

	vector<T> seg;	// セグメントツリー (親:k/2  子:k*2,k*2+1)

	int N;

	RMQ(int size){

		N = 1;

		while( N < size ) N<<=1;

		seg.assign(N*2, INF);		// default value

	}

	void update(int pos, T v){

		for(int k=N+pos; k>0; k/=2){

			seg[k] = v;

			v = min(seg[k], seg[k^1]);	// merge

		}

	}

	// [l,r)

	T get(int l, int r){

		return query(l, r, 0, N, 1);

	}

	T get(int pos){		// =get(pos, pos+1)

		return seg[N+pos];

	}

};



int main(){

	//ios_base::sync_with_stdio(false);

	ll N, ans=0;

	ll x[200005], s[200005];



	cin >> N;

	rep(i,N) cin >> x[i] >> s[i];

	x[N] = x[N-1];



	rep(i,N) chmax(ans, s[i]);



//	set<ll> st;

//	map<ll,ll> mp;

//	rep(i,N) st.insert(x[i]);

//	for(auto t: st) mp[t] = mp.size();



	RMQ<ll> sg(200005);

	ll sum = 0;

	sg.update(0,0);

	rep(i,N){

		sum += s[i];

		ll mn  = sg.get(0,i+1);

		chmax(ans, sum - mn);

		ll d = x[i+1] - x[i];

		sum -= d;

		sg.update(i+1, sum);

	}



	cout << ans << endl;



	return 0;

}


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



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

#define reps(i,x,n) for(int i=x; i<(n); i++)

#define rrep(i,n) for(int i=(n)-1; i>=0; i--)

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

#define X first

#define Y second

#define pb push_back

#define eb emplace_back



using namespace std;

typedef long long int ll;

typedef pair<int,int> pii;

typedef pair<ll,ll> pll;



template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }

template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }



template<class A, size_t N, class T> void Fill(A (&a)[N], const T &v){ fill( (T*)a, (T*)(a+N), v ); }







int main(){

	//ios_base::sync_with_stdio(false);

	ll N, ans=0;

	ll x[200005], s[200005];



	cin >> N;

	rep(i,N) cin >> x[i] >> s[i];



	ll sum = 0, mn = 0;

	rep(i,N){

		sum += s[i];

		chmax(ans, sum - mn);

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

		chmin(mn, sum);

	}



	cout << ans << endl;



	return 0;

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

#include <iostream>

#include <algorithm>

#include <map>

#include <cstring>



using namespace std;



typedef long long LL;



#define MAXN 4010

#define mo 1000000007



int n, m, a[MAXN];

int sum[MAXN];

int f[MAXN][MAXN];

char s[MAXN];



void Init()

{

    int i;

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

    scanf("%s", s + 1);

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

        a[i] = s[i] - '0';

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

    }

}



void Dp()

{

    int i, j = 1, k, l, r, R = 0, ad = 0;

    f[0][0] = 1;

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

        scanf("%d %d", &l, &r);

        for(; j < l; ++j, ad = 0){

            if(j > R){

                R = j;

                ad += a[j];

            }

            for(k = 0; k <= sum[R] && j + k <= R; ++k){

                if(k - ad >= 0) f[j][k] = (f[j][k] + f[j - 1][k - ad]) % mo;

                if(k - ad + 1>= 0) f[j][k] = (f[j][k] + f[j - 1][k - ad + 1]) % mo;

            }

        }

        if(r > R){

            ad += sum[r] - sum[R];

            R = r;

        }

//        for(; j < l; ++j, ad = 0){

//            for(k = 0; k <= sum[R] && j + k <= R; ++k){

//                if(k - ad >= 0) f[j][k] = (f[j][k] + f[j - 1][k - ad]) % mo;

//                if(k - ad + 1>= 0) f[j][k] = (f[j][k] + f[j - 1][k - ad + 1]) % mo;

//            }

//        }

    }

    for(; j <= n; ++j, ad = 0){

        if(j > R){

            R = j;

            ad += a[j];

        }

        for(k = 0; k <= sum[R] && j + k <= R; ++k){

            if(k - ad >= 0) f[j][k] = (f[j][k] + f[j - 1][k - ad]) % mo;

            if(k - ad + 1>= 0) f[j][k] = (f[j][k] + f[j - 1][k - ad + 1]) % mo;

        }

    }

    printf("%d\n", f[n][0]);

}



int main()

{

    Init();

    Dp();



    return 0;

}


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

#include<algorithm>

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

using namespace std;

typedef long long ll;

const int maxn=3000+10,mo=1000000007;

int f[maxn][maxn],right[maxn],sum[maxn];

int i,j,k,l,r,t,n,m,ans,one,zero;

char get(){

    char ch=getchar();

    while (ch!='0'&&ch!='1') ch=getchar();

    return ch;

}

int main(){

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

    fo(i,1,n) sum[i]=get()-'0';

    fo(i,1,n+1) sum[i]+=sum[i-1];

    fo(i,1,n+1) right[i]=i;

    fo(i,1,m){

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

        right[j]=max(right[j],k);

    }

    fo(i,1,n) right[i]=max(right[i],right[i-1]);

    f[1][sum[right[1]]]=1;

    fo(i,1,n)

        fo(j,0,n)

            if (f[i][j]){

                l=right[i]+1;r=right[i+1];

                one=j;zero=right[i]-i+1-j;

                if (zero) (f[i+1][j+sum[r]-sum[l-1]]+=f[i][j])%=mo;

                if (one) (f[i+1][j-1+sum[r]-sum[l-1]]+=f[i][j])%=mo;

            }

    ans=f[n+1][0];

    (ans+=mo)%=mo;

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

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

using namespace std;



typedef long long ll;

typedef pair<int, int> pii;

typedef pair<int, pii> pipii;

typedef pair<pii, int> piipi;

typedef pair<pii, pii> piipii;



#define mp make_pair

#define fi first

#define se second

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

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

#define eb emplace_back

const int mod = 1000000007;



int l[3005], r[3005], mx[3005];

char s[3005];

int sum[3005][2];

int dp[3005][3005];

int main(){

    int n, m;

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

    scanf("%s", s+1);

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

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

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

        mx[l[i]] = max(mx[l[i]], r[i]);

    }



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

        sum[i][s[i]-'0']++;

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

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

    }



    for(int i=1;i<=n;i++) mx[i] = max(mx[i], mx[i-1]);



    dp[0][0] = 1;

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

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

            if(dp[i-1][j]){

                int c0 = sum[mx[i]][0] - j;

                int c1 = sum[mx[i]][1] - (i-1-j);

                if(c0 > 0) dp[i][j+1] = (dp[i][j+1] + dp[i-1][j])%mod;

                if(c1 > 0) dp[i][j] = (dp[i][j] + dp[i-1][j])%mod;

            }

        }

    }

    int ans = 0;

    for(int j=0;j<=n;j++) ans = (ans + dp[n][j])%mod;

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

}

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

#include<algorithm>

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

using namespace std;

typedef long long ll;

const int maxn=3000+10,mo=1000000007;

int f[maxn][maxn],right[maxn],sum[maxn];

int i,j,k,l,r,t,n,m,ans,one,zero;

char get(){

    char ch=getchar();

    while (ch!='0'&&ch!='1') ch=getchar();

    return ch;

}

int main(){

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

    fo(i,1,n) sum[i]=get()-'0';

    fo(i,1,n+1) sum[i]+=sum[i-1];

    fo(i,1,n+1) right[i]=i;

    fo(i,1,m){

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

        right[j]=max(right[j],k);

    }

    fo(i,1,n) right[i]=max(right[i],right[i-1]);

    f[1][sum[right[1]]]=1;

    fo(i,1,n)

        fo(j,0,n)

            if (f[i][j]){

                l=right[i]+1;r=right[i+1];

                one=j;zero=right[i]-i+1-j;

                if (zero) (f[i+1][j+sum[r]-sum[l-1]]+=f[i][j])%=mo;

                if (one) (f[i+1][j-1+sum[r]-sum[l-1]]+=f[i][j])%=mo;

            }

    ans=f[n+1][0];

    (ans+=mo)%=mo;

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

}
// Slower C++ solution:
//Compete against Yourself.

#include <bits/stdc++.h>

#define _ ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);

#define int long long

#define pb push_back

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

#define F first

#define S second

#define L long double

#define P pair<int, int>

const int inf = 0x3f3f3f3f3f3f3f3LL;

const int mod = (int)1e9 + 7;

using namespace std;

#if LOCAL

#include "../../tr.h"

#else

#define tr(...)

#define endl '\n'

#endif

template<class T> void smin(T& a, T val) {if (a > val) a = val;}template<class T> void smax(T& a, T val) {if (a < val) a = val;}

const int N = 5*(int)1e5 + 10;



const int M = 62;



int n, a[N];

int32_t main(){_



   cin>>n;



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

   {

      cin>>a[i];

   }



   vector<int> cnt(M, 0);

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

   {

      for (int j = 0; j < M; ++j)

      {

         if(a[i] & (1LL << j))

            cnt[j]++;

      }

   }

   

   int ans = 0;

   for (int j = 0; j < M; ++j)

   {

      int ok = (cnt[j]) * (n - cnt[j]) % mod;

      ok *= ((1LL << j) % mod);

      ok %= mod;

      ans += ok;

      ans %= mod;

   }

   

   cout<<ans;



   return 0;

}


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

//#include <iostream>

//#include <algorithm>

//#include <cstring>

//#include <queue> //priority_queue 优先队列

#include <map>

#include <set> //multiset  set<int,greater<int>>大到小

//#include <vector>// ::iterator it;

//#include <stack>

//#include <cmath> // auto &Name : STLName  Name.

//#include <utility>

//#include <sstream>

//#include <string>

#define mod 1000000007

#define mod9 998244353

typedef unsigned long long ull;

typedef long long ll;

typedef double db;

typedef long double ld;

const db eps=1e-10;

const int INF = 0x3f3f3f3f;

const ll inf=0x3f3f3f3f3f3f3f3f;

const int N=1e6+5;

using namespace std;





ll t,n,m,k,cnt=0;

ll a[65]={0};

ll sum=0;

ll ksm(ll a,ll b){

    ll c=mod;

    ll ans=1;

    a=a%c;

    while(b>0){

        if(b%2) ans=(ans*a)%c;

        b=b/2;

        a=(a*a)%c;

    }

    return ans;

}

int main(){

    scanf("%lld",&n);

    k=n;

    while(n--){

        scanf("%lld",&m);

        for(ll i=0;m;i++){

            ll x=m%2;

            m/=2;

            if(x) a[i]++;

        }

    }

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

        sum=(sum+((a[i]*(k-a[i]))%mod)*ksm(2,i))%mod;

    }

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

    return 0;

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

using namespace std;

#include<ext/pb_ds/assoc_container.hpp>

#include<ext/pb_ds/tree_policy.hpp>

using namespace __gnu_pbds;

template<typename T>

using ordered_set = tree<T, null_type,less<T>, rb_tree_tag,tree_order_statistics_node_update>;

#define ll long long

#define ff first

#define ss second



ll n, a[300009], ans[64], mod = 1000000007;

ll freq[64];



void func(ll x)

{

    for(ll i = 0; x; i++)

    {

        freq[i] += (x&1);

        x = x >> 1;

    }

}



ll po(ll a, ll b)

{

    if(b == 0)

        return 1;

    ll x = 1;

    if(b&1)

        x = a%mod;

    ll y = po(a, b/2);

    return (((y*y)%mod)*x)%mod;

}



int main()

{

    ll i, j;

    cin >> n;



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

    {

        cin >> a[i];

        func(a[i]);

    }



//    for(auto u : freq)

//        cout << u.ff << " " << u.ss << endl;



    for(i = 0; i <= 62; i++)

    {

        for(j = 0; j < n; j++)

        {

            if(a[j] & (1LL << i))

            {

                ans[i] += (n-j) - freq[i];

                freq[i]--;

            }

            else

                ans[i] += freq[i];

        }

    }



    ll x = 0;

    for(i = 0; i <= 62; i++)

        x = (x + (ans[i]%mod)*po(2LL, i))%mod;

    cout << x;

}


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

//#include <iostream>

//#include <algorithm>

//#include <cstring>

//#include <queue> //priority_queue 优先队列

#include <map>

#include <set> //multiset  set<int,greater<int>>大到小

//#include <vector>// ::iterator it;

//#include <stack>

//#include <cmath> // auto &Name : STLName  Name.

//#include <utility>

//#include <sstream>

//#include <string>

#define mod 1000000007

#define mod9 998244353

typedef unsigned long long ull;

typedef long long ll;

typedef double db;

typedef long double ld;

const db eps=1e-10;

const int INF = 0x3f3f3f3f;

const ll inf=0x3f3f3f3f3f3f3f3f;

const int N=1e6+5;

using namespace std;





ll t,n,m,k,cnt=0;

ll a[65]={0};

ll sum=0;

ll ksm(ll a,ll b){

    ll c=mod;

    ll ans=1;

    a=a%c;

    while(b>0){

        if(b%2) ans=(ans*a)%c;

        b=b/2;

        a=(a*a)%c;

    }

    return ans;

}

int main(){

    scanf("%lld",&n);

    k=n;

    while(n--){

        scanf("%lld",&m);

        for(ll i=0;m;i++){

            ll x=m%2;

            m/=2;

            if(x) a[i]++;

        }

    }

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

        sum=(sum+((a[i]*(k-a[i]))%mod)*ksm(2,i))%mod;

    }

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

    return 0;

}