Problem:


Score : 400 points

Problem Statement

We have N integers. The i-th integer is A_i.

Find \sum_{i=1}^{N-1}\sum_{j=i+1}^{N} (A_i \mbox{ XOR } A_j), modulo (10^9+7).

What is \mbox{ XOR }?

The XOR of integers A and B, A \mbox{ XOR } B, is defined as follows:

When A \mbox{ XOR } B is written in base two, the digit in the 2^k's place (k \geq 0) is 1 if either A or B, but not both, has 1 in the 2^k's place, and 0 otherwise.

For example, 3 \mbox{ XOR } 5 = 6. (In base two: 011 \mbox{ XOR } 101 = 110.)

Constraints

2 \leq N \leq 3 \times 10^5

0 \leq A_i < 2^{60}

All values in input are integers.

Input

Input is given from Standard Input in the following format:

N
A_1 A_2 ... A_N

Output

Print the value \sum_{i=1}^{N-1}\sum_{j=i+1}^{N} (A_i \mbox{ XOR } A_j), modulo (10^9+7).

Sample Input 1

3
1 2 3

Sample Output 1

6

We have (1\mbox{ XOR } 2)+(1\mbox{ XOR } 3)+(2\mbox{ XOR } 3)=3+2+1=6.

Sample Input 2

10
3 1 4 1 5 9 2 6 5 3

Sample Output 2

237

Sample Input 3

10
3 14 159 2653 58979 323846 2643383 27950288 419716939 9375105820

Sample Output 3

103715602

Print the sum modulo (10^9+7).



Sample input:
3
1 2 3


Sample output:
6

Submission status: Runtime Error

Solution code:
# ABC 147 D

N=int(input())
A=list(map(int,input().split()))
res=0
p=10**9+7

bits=[0]*71
for a in A:
    j=0
    while a>>j:
        if (a>>j)&1:
            bits[j]+=1
        j+=1

t=0
n=70
while 1:
    if bits[n]!=0:
        break
    n-=1

for a in A:
    j=0
    while j<=n:
        if (a>>j)&1:
            res+=((2**j)*(N-bits[j]))%p
        else:
            res+=((2**j)*bits[j])%p
        j+=1
    t=res
print((res*500000004)%p)

Submission status: Runtime Error

Solution code:
N = int(input())
A = list(map(int, input().split()))
A = sorted(A)

count = 0

max = A[-1]
import math
V = [0]*(math.floor(math.log(max, 2))+1)

for i in range (0, N):
	B = A[i]
	vount = 0
	while B > 0:
		if B%2 == 0:
			B = B//2
			vount+=1			
		else:
			B = (B-1)//2
			V[vount]+=1
			vount+=1

for i in range (0, len(V)):
	count+=((V[i]*(N-V[i]))*(2**i))

print(count%(10**9+7))

Submission status: Runtime Error

Solution code:
import math
N = int(input())
A = list(map(int, input().split()))
bit = [0] * (math.ceil(math.log2(max(A))))
MOD = 10 ** 9 + 7
for a in A:
    b = a
    i = 0
    while a > 0:
        if a % (2 ** (i+1)) != 0:
            a -= 2 ** i
            bit[i] += 1
        i += 1
answer = 0
for i, b in enumerate(bit):
    answer += (2 ** i) * (b * (N-b))
print(answer % MOD)

Submission status: Runtime Error

Solution code:
n = int(input())
A = list(map(int, input().split()))

mod = 10 ** 9 + 7
ans = 0

for k in range(60):
    x, y = 0, 0
    for a in A:
        x += 1 & a >> k
    tmp = x * (n - x) % mod
    tmp *= pow(2, k, mod)
    ans += tmp
    ans %= mod
print(ans)

Submission status: Runtime Error

Solution code:
import math
n = int(input())
A = list(map(int, input().split()))

mod = 10**9+7
ans = 0

max_a = max(A)

for k in range(math.floor(math.log(max_a, 2))+1):
    x, y = 0, 0
    for a in A:
        if a & 1<<k:
            x += 1
    ans += x*(n-x)*pow(2, k, mod)
    ans %= mod
print(ans)

Submission status: Runtime Error

Solution code:
import sys
input = sys.stdin.readline
MOD = pow(10, 9) + 7

def make_fact_list(n, MOD):
    # make factorial list from 0 to n
    fact = [0] * (n+1)
    inv = [0] * (n+1)
    factinv = [0] * (n+1)

    fact[0]=fact[1]=1
    inv[1]=1
    factinv[0]=factinv[1]=1

    for i in range(2,n+1):
        fact[i] = fact[i-1] * i % MOD
        inv[i] = MOD - (( inv[MOD % i] *  (MOD // i)) % MOD )
        factinv[i] = factinv[i-1] * inv[i] % MOD
    
    return fact, factinv

def cbn(n, k, MOD, fact = [], factinv = []):
    if len(fact) == 0 and len(factinv) == 0:
        fact, factinv = make_fact_list(n, MOD)
    return fact[n] * factinv[n-k] * factinv[k] % MOD



n = int(input())
a = list(map(int, input().split()))

m = max(a)

k = len(format(m, 'b'))

num = [0] * k

for x in a:
    for j in range(k):
        if (x >> j) & 1:
            num[j] += 1

fact, factinv = make_fact_list(max(num), MOD)

s = 0

#print(num)

for i in range(k):
    s += (n - num[i]) * num[i] * pow(2, i, MOD) % MOD

print(s % MOD)

Submission status: Runtime Error

Solution code:
def readinput():
    n=int(input())
    l=list(map(int,input().split()))
    return n,l

def main(n,a):
    MOD=10**9+7
    hist=[0]*61
    bs=[]
    for i in range(n):
        # s=list(reversed(bin(a[i])[2:]))
        # for j in range(len(s)):
        #     if s[j]=='1':
        #         hist[j]+=1
        # bs.append(s)

        s=bin(a[i])[2:]
        for j in range(len(s)):
            if s[j]=='1':
                hist[len(s)-j-1]+=1
        # j=0
        # ai=a[i]
        # while ai>0:
        #     if ai&1==1:
        #         hist[j]+=1
        #     ai = ai >> 1
        #     j+=1


    #print(bs)
    #print(hist)
    sum=0
    for i in range(n-1):
        s=bs[i]
        b=1
        for j in range(len(s)):
            if s[j]=='0':
                sum=(sum+hist[j]*b)%MOD
            else:
                sum=(sum+( n-i-hist[j] )*b)%MOD
                hist[j]-=1
            b*=2
        for j in range(len(s),61):
            sum=(sum+hist[j]*b)%MOD
            b*=2
    # b=1
    # for j in range(61):
    #     sum=(sum+( hist[j]*(n-hist[j])*b )%MOD )%MOD
    #     b*=2

    return sum

if __name__=='__main__':
    n,l=readinput()
    ans=main(n,l)
    print(ans)

Submission status: Runtime Error

Solution code:
N = int(input())
aaa = map(int, input().split())
ans = 0
MOD = 1_000_000_007
for i in range(N-1):
    for j in range(i + 1, N):
        ans += aaa[i] ^ aaa[j]
        ans %= MOD
print(ans)

Submission status: Runtime Error

Solution code:
def cmb(n, r, p):
  if (r < 0) or (n < r):
    return 0
  r = min(r, n - r)
  return fac[n]*finv[r]*finv[n-r]%p

def perm(n,r,p):
  if (r < 0) or (n < r):
    return 0
  return fac[n]*finv[n-r]%p

N = 31000
MOD = pow(10,9)+7

fac = [-1]*(N+1); fac[0] = 1; fac[1] = 1 #階乗
finv = [-1]*(N+1); finv[0] = 1; finv[1] = 1 #階乗の逆元
inv = [-1]*(N+1); inv[0] = 0; inv[1] = 1 #逆元
for i in range(2,N+1):
  fac[i] = fac[i-1]*i%MOD
  inv[i] = MOD - inv[MOD%i]*(MOD//i)%MOD
  finv[i] = finv[i-1]*inv[i]%MOD

M = int(input())
A = list(map(int,input().split()))
MAX = 63
L = [0]*MAX

for i in range(M):
  for j in range(MAX):
    if A[i]>>j&1:
      L[j] += 1
#print(L)
ans = 0
for i in range(MAX):
  base = pow(2,i)
  kosu = cmb(M,2,MOD)-cmb(L[i],2,MOD)-cmb(M-L[i],2,MOD)
  ans += base*kosu%MOD
print(ans%MOD)

Submission status: Runtime Error

Solution code:
def cmb(n, r, p):
  if (r < 0) or (n < r):
    return 0
  r = min(r, n - r)
  return fac[n]*finv[r]*finv[n-r]%p

def perm(n,r,p):
  if (r < 0) or (n < r):
    return 0
  return fac[n]*finv[n-r]%p

N = 31000
MOD = pow(10,9)+7

fac = [-1]*(N+1); fac[0] = 1; fac[1] = 1 #階乗
finv = [-1]*(N+1); finv[0] = 1; finv[1] = 1 #階乗の逆元
inv = [-1]*(N+1); inv[0] = 0; inv[1] = 1 #逆元
for i in range(2,N+1):
  fac[i] = fac[i-1]*i%MOD
  inv[i] = MOD - inv[MOD%i]*(MOD//i)%MOD
  finv[i] = finv[i-1]*inv[i]%MOD

M = int(input())
A = list(map(int,input().split()))
MAX = 60
L = [0]*MAX

for i in range(M):
  for j in range(MAX):
    if A[i]>>j&1:
      L[j] += 1
#print(L)
ans = 0
for i in range(MAX):
  base = pow(2,i)
  kosu = cmb(M,2,MOD)-cmb(L[i],2,MOD)-cmb(M-L[i],2,MOD)
  ans += base*kosu%MOD
print(ans%MOD)

Submission status: Runtime Error

Solution code:
#include<iostream>
#include<iomanip>
#include<cmath>
#include<string>
#include<vector>
#include<list>
#include<algorithm>
#include<map>
#include<set>
#include<queue>
#include<stack>
using namespace std;
typedef long long ll;
#define fi first
#define se second
#define mp make_pair
#define rep(i, n) for(int i=0;i<n;++i)
#define rrep(i, n) for(int i=n;i>=0;--i)
const int inf=1e9+7;
const ll mod=1e9+7;
const ll big=1e18;
const double PI=2*asin(1);

ll DP[61][300005];

int main() {
  int N;
  cin>>N;
  ll A[N];
  ll two;
  for(int i=0;i<N;++i) cin>>A[i];
  for(int i=0;i<N;++i) {
    two = 1;
    for(int bit=0;bit<61;++bit) {
      if((A[i]&two)!=0) DP[bit][i]++;
      two *= 2;
    }
  }
  for(int bit=0;bit<61;++bit) {
    for(int i=1;i<N;++i) {
      DP[bit][i] += DP[bit][i-1];
    }
  }
  /**
  for(int bit=0;bit<61;++bit) {
    for(int i=0;i<N;++i) {
      cout<<DP[bit][i]<<" ";
    }
    cout<<endl;
  }
  **/
  ll ans = 0;
  for(int i=0;i<N;++i) {
    two = 1;
    for(int bit=0;bit<61;++bit) {
      if((A[i]&two)!=0) {
        ans += two%mod*(N-1-i-(DP[bit][N-1]-DP[bit][i]))%mod;
        ans %= mod;
      }
      else {
        ans += two%mod*(DP[bit][N-1]-DP[bit][i])%mod;
        ans %= mod;
      }
      two *= 2;
    }
  }
  cout<<ans<<endl;
}

Submission status: Runtime Error

Solution code:
import math

def main():
    mod = 1000000007
    N = int(input())
    A = list(map(int, input().split()))

    A_max = sorted(A)[-1]
    bit_max = int(math.ceil(math.log2(A_max)))

    i = 0
    bit = 1
    res = 0
    while i <= bit_max:
        c_zero = 0
        c_one = 0
        for j in range(N):
            if A[j] & bit == 0:
                c_zero += 1
            else:
                c_one += 1
        m_bit = bit % mod
        res += m_bit*c_zero*c_one
        res %= mod
        i += 1
        bit<<=1
    print(res)

if __name__ == "__main__":
    main()

Submission status: Runtime Error

Solution code:
N, *A = map(int, open(0).read().split())
A = np.array(A, dtype=np.int64)
mod = 10**9 + 7
 
ans = 0
for i in range(60):
    mask = 1 << i
    cnt = np.count_nonzero(A&mask)
    x = cnt * (N-cnt)
    x *= mask % mod
    ans += x
    ans %= mod
 
print(ans)

Submission status: Runtime Error

Solution code:
import math

N = int(input())
A = list(map(int, input().split()))

Sum = 0
mod = (10 ** 9) + 7

for i in range(int(math.log2(max(A))) + 1):
    Sum_1 = 0
    for j in range(N):
        #print(i, j)
        if ((A[j] >> i) & 1):
            Sum_1 += 1

    Sum_0 = N - Sum_1

    Sum = (Sum + ((Sum_0 * Sum_1) % mod * (2 ** i)) % mod) % mod
    # print(Sum_0,Sum_1)

print(Sum)

Submission status: Runtime Error

Solution code:
n = int(input())
a = list(map(int,input().split()))
MOD = 10 ** 9 + 7
digit = 60
o=[0]*digit
z=[0]*digit

for i in a:
  for j in range(digit):
    if (i >> j) & 1:
      o[j] += 1
    else:
      z[j] += 1
ans = 0
for j in range(digit):
  ans += (o[j]*z[j]*2**j
print(ans % MOD)

Submission status: Runtime Error

Solution code:
from math import log2,floor
N = int(input())
A = list(map(int,input().split()))
L = max([floor(log2(x)) for x in A])+1
bits = [0]*L
for x in A:
    for i in range(L):
        if (x>>i)&1:
            bits[i] += 1
mod = 10**9+7
ans = 0
for i in range(L):
    b = bits[i]
    ans = (ans+b*(N-b)*(2**i))%mod
print(ans)

Submission status: Runtime Error

Solution code:
import math

N = 10
ARR = [3, 1, 4, 1, 5, 9, 2, 6, 5, 3]

N = 10
ARR = [3, 14, 159, 2653, 58979, 323846, 2643383, 27950288, 419716939, 9375105820]

# N = 3
# ARR = [1, 2, 3]

# N = 5
# ARR = [3, 6, 8, 9, 10]

N = int(input())
ARR = list(map(int,input().split()))


def calculate(n, arr):
    mathNum = math.ceil(math.log(max(arr), 2)) + 1
    result = 0
    for i in range(mathNum):

        oneSum = 0
        zeroSum = 0
        for j in range(n):
            if ((arr[j] >> i) & 1) == 0:
                zeroSum += 1
            else:
                oneSum += 1

        result += 2 ** i * (zeroSum * oneSum)

    print(result % (10**9 + 7))


calculate(N, ARR)

Submission status: Runtime Error

Solution code:
import numpy as np
n = int(input())
a = np.array(list(map(int, input().split())))
#print(a)
bit = [0] * 60
mod = 10 ** 9 + 7
ans = 0
for i in range(60):
    n1 = np.count_nonzero((a >> i) & 1)
    n0 = n - n1
    ans += (2 ** i) * n1 * n0 % mod
print(ans % mod)

Submission status: Runtime Error

Solution code:
# import sys
# sys.setrecursionlimit(10 ** 6)
# import bisect
# from collections import deque
# from decorator import stop_watch
# 
# 
# @stop_watch
def solve(N, As):
    import math
    x = math.ceil(math.log2(max(As)))
    ans = 0
    for i in range(x):
        count0 = 0
        count1 = 0
        for A in As:
            if (A >> i) % 2 == 0:
                count0 += 1
            else:
                count1 += 1
        # print(i, count0, count1)
        ans += count0 * count1 * (2 ** i)
        ans = ans % (10 ** 9 + 7)
    print(ans)


if __name__ == '__main__':
    N = int(input())
    As = [int(i) for i in input().split()]
    # N = 3 * 10 ** 5
    # import random
    # As = [random.randint(0, 2 ** 60) for _ in range(N)]
    solve(N, As)

Submission status: Runtime Error

Solution code:
N = int(input())
A = list(map(int,input().split()))
mod = 10**9+7
for i in range(N):
    for j in range(i,N):
        ans += (i^j)%mod
print(ans%mod)

Submission status: Runtime Error

Solution code:
n = int(input())
a = list(map(int,input().split()))
mod = 10e9+7
ans = 0
for i in range(60):
    x = 1 << i
    n = len([1 for j in a if j & X])
    ans += x * n * (N-n) % mod
    ans %= mod
print(ans)

Submission status: Runtime Error

Solution code:
n = int(input())
dig = 50
A = list(map(lambda x:bin(int(x))[2:].zfill(dig), input().split()))
MOD = 10 ** 9 + 7
ans = 0
d = {i: [0, 0] for i in range(dig)}
for a in A:
    for i in range(len(a)):
        if a[-(i+1)] == '0':
            d[i][0] += 1
        else:
            d[i][1] += 1
for i in range(dig):
    ans += d[i][0] * d[i][1] * (2 ** i)
    ans %= MOD
print(ans)

Submission status: Runtime Error

Solution code:
import math
N = int(input())
li = list(map(int,input().split()))	
big = math.floor(math.log2(max(li))) + 1
ans = 0
for i in range(big):
    one = sum([1 if (l >> i) & 1 else 0 for l in li])
    t = (2**i) % (10**9+7)
    ans += t * one * (N-one)
print(ans % (10**9+7))

Submission status: Runtime Error

Solution code:
import math
N = int(input())
li = list(map(int,input().split()))	
big = math.floor(math.log2(max(li))) + 1
ans = 0
for i in range(big):
    one = 0
    for l in li:
        if (l >> i) & 1:
            one += 1
    t = (2**i) % (10**9+7)
    ans += t * one * (N-one)
print(ans % (10**9+7))

Submission status: Runtime Error

Solution code:
import math
N = 10**9+7
n = int(input())
a = list(map(int,input().split()))

ans = 0

ma = int(math.log2(max(a)))
if ma<0:
    ma=0
for i in range(ma+2):
    sum=0
    for j in range(n):
        sum+=(a[j]>>i) & 1
    ans+=sum*(n-sum)*pow(2,i,N)
    ans%=10**9+7
print(ans)

Submission status: Runtime Error

Solution code:
import math
n = int(input())
a = list(map(int,input().split()))

ans = 0
for i in range(int(math.log2(max(a)))+2):
    sum=0
    for j in range(n):
        sum+=(a[j]>>i) & 1
    ans+=sum*(n-sum)*(2**i)
    ans%=10**9+7
print(ans)

Submission status: Runtime Error

Solution code:
from sys import stdin
import math
def I(): return int(stdin.readline().rstrip())
def LI(): return list(map(int,stdin.readline().rstrip().split()))

if __name__=='__main__':
    mod = 1000000007
    n = I()
    a = LI()
    a.sort(reverse=True)
    ans = 0
    dig = int(math.log2(a[0])) + 1
    for i in range(dig):
        c0 = 0
        c1 = 0
        for rep in a:
            if (rep>>i)&1:
                c1 += 1
            else:
                c0 += 1
        ans += (c0*c1*2**i)%mod
    ans %= mod
    print(ans)

Submission status: Runtime Error

Solution code:
from sys import stdin
import math
def I(): return int(stdin.readline().rstrip())
def LI(): return list(map(int,stdin.readline().rstrip().split()))

if __name__=='__main__':
    mod = 1000000007
    n = I()
    a = LI()
    a.sort(reverse=True)
    ans = 0
    dig = int(math.log2(a[0])) + 1
    for i in range(dig):
        c0 = 0
        c1 = 0
        for rep in a:
            if (rep>>i)&1:
                c1 += 1
            else:
                c0 += 1
        ans += (c0*c1*2**i)%mod
    	ans %= mod
    print(ans)

Submission status: Runtime Error

Solution code:
from sys import stdin
import math
from collections import deque
def I(): return int(stdin.readline().rstrip())
def LI(): return list(map(int,stdin.readline().rstrip().split()))

def main():
    mod = 10**9+7
    n = I()
    a = LI()
    a.sort(reverse=True)
    ans = 0
    dig = int(math.log2(a[0])) + 1
    for i in range(dig):
        c0 = 0
        c1 = 0
        for rep in a:
            if (rep>>i)&1:
                c1 += 1
            else:
                c0 += 1
        ans += c0*c1*2**i
    ans %= mod
    print(ans)
    return

if __name__=='__main__':
    main()

Submission status: Runtime Error

Solution code:
def str2bitstr(chs):
    val = int(chs)
    tmp = bin(val)[2:]
    tmp2 = '0' * (59 - len(tmp))
    return tmp2 + tmp


n = int(input())
a = list(map(str2bitstr, input().split()))

cnts = [0] * 59

for item in a:
    for i, ch in enumerate(item):
        if ch == '1':
            cnts[i] += 1

ret = 0
now = 1

for i in range(1, 60):
    kumi = cnts[-i] * (n - cnts[-i]) % (10 ** 9 + 7)
    ret += kumi * now % (10 ** 9 + 7)
    now *= 2

print(ret % (10 ** 9 + 7))

Submission status: Runtime Error

Solution code:
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
 
const int mod = 1000000007;
 
int main() {
  int n;
  cin >> n;
  vector<ll> a(n);
  rep(i,n) cin >> a[i];
  ll ans = 0;
  rep(i,60) {
    ll x = 0;
    rep(j,n) if (a[j]>>i&1) ++x;
    ll now = x*(n-x)%mod;
    rep(j,i) now = now*2%mod;
    ans += now;
    ans %= mod;
  }
  cout << ans << endl;
  return 0;
}
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;

const int mod = 1000000007;

int main() {
  int n;
  cin >> n;
  vector<ll> a(n);
  rep(i,n) cin >> a[i];
  ll ans = 0;
  rep(i,60) {
    ll x = 0;
    rep(j,n) if (a[j]>>i&1) ++x;
    ll now = x*(n-x)%mod;
    rep(j,i) now = now*2%mod;
    ans += now;
    ans %= mod;
  }
  cout << ans << endl;
  return 0;
}

Submission status: Runtime Error

Solution code:
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
 
const int mod = 1000000007;

int main() {
  int n;
  cin >> n;
  vector<ll> a(n);
  rep(i,n) cin >> a[i];
  ll ans = 0;
  rep(i, 60) {
    ll x = 0;
    rep(j,n) if (a[j]>>i&1) ++x;
    ll now = x*(n-x)%mod;
    rep(j,i) now = now*2%mod;
    ans += now;
    ans %= mod;
  }
  cout << ans << endl;
  return 0;
}

Submission status: Runtime Error

Solution code:
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef ll = long long;

const int mod = 1000000007;

int main() {
  int n;
  cin >> n;
  vector<ll> a(n);
  rep(i,n) cin >> a[i];
  ll ans = 0;
  rep(i, 60) {
    ll x = 0;
    rep(j,n) if (a[j]>>i&1) ++x;
    ll now = x*(n-x)%mod;
    rep(j,i) now = now*2%mod;
    ans += now;
    ans %= mod;
  }
  cout << ans << endl;
  return 0;
}

Submission status: Runtime Error

Solution code:
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;

const int mod = 1000000007;

int main() {
  int n;
  cin >> n;
  vector<ll> a(n);
  rep(i,n) cin >> a[i];
  ll ans = 0;
  rep(i, 60) {
    ll x = 0;
    rep(j,n) if (a[j]>>i&1) ++x;
    ll now = x*(n-x)%mod;
    rep(j,i) now = now*2%mod;
    ans += now;
    ans %= mod;
  }
  cout << ans << endl;
  return 0;
}

Submission status: Runtime Error

Solution code:
import sys
input = sys.stdin.readline
def main():
  n=int(input())
  #a=list(map(lambda x:list(map(int,list(bin(int(x))[2:]))),input().split()))
  a=list(map(int,input().split()))
  mod=pow(10,9)+7
  bit=[]
  for ai in a:
    for j in range(61):
      if ((ai>>j)&1):
        bit[j]+=1
  for i in range(61):# 2^iの位
    ans+=(pow(2,i,mod)*bit[i]*(n-bit[i]))%mod
    ans%=mod
  print(ans)
if __name__=='__main__':
  main()

Submission status: Runtime Error

Solution code:
import sys
input = sys.stdin.readline
def main():
  n=int(input())
  a=list(map(int,lambda x:list(map(int,list(bin(int(x))[2:]))),input().split()))
  mod=pow(10,9)+7
  ans=0
  len_ai=[]
  for ai in a:
    len_ai.append(len(ai))
  for i in range(61):# 2^iの位
    bit1=0
    for j in range(n):
      if len_ai[j]>=i+1:
        bit1+=a[j][-i-1]
    ans+=(pow(2,i,mod)*bit1*(n-bit1))%mod
    ans%=mod
  print(ans)
if __name__=='__main__':
  main()

Submission status: Runtime Error

Solution code:
import sys
import math

input = lambda: sys.stdin.readline().rstrip()
mod = 10**9 + 7


def solve():
    N = int(input())
    A = list(map(int, input().split()))

    a_max = max(A)
    a_len = len(A)
    keta = int(math.log2(a_max) + 1)

    t = [[0 for _ in range(keta)] for _ in range(2)]

    for k in range(keta):
        for a in A:
            a = a & (2**k)
            a = a >> k
            t[a][k] += 1

    ans = 0
    for k in range(keta):
        ans += (t[0][k] * t[1][k]) * pow(2, k, mod)
        ans %= mod

    print(ans)


if __name__ == '__main__':
    solve()

Submission status: Runtime Error

Solution code:
import sys
import math

input = lambda: sys.stdin.readline().rstrip()
mod = 10**9 + 7


def solve():
    N = int(input())
    A = list(map(int, input().split()))

    a_max = max(A)
    a_len = len(A)
    keta = math.ceil(math.log2(a_max))

    t = [[0 for _ in range(keta)] for _ in range(2)]

    for k in range(keta):
        for a in A:
            a = a & (2**k)
            a = a >> k
            t[a][k] += 1

    ans = 0
    for k in range(keta):
        ans += (t[0][k] * t[1][k]) * pow(2, k, mod)
        ans %= mod

    print(ans)


if __name__ == '__main__':
    solve()

Submission status: Runtime Error

Solution code:
#!/usr/bin/python3
# -*- coding: utf-8 -*-

import sys
#import bisect
#from collections import deque
import math

#############################
#         59 58 57     1
# Ai = 0xbi bi bi ... bi
# 
#############################

#############################
#   N-1 N
#   Σ   Σ     (Ai xor Aj)
#   i=1 j=i+1
#
#   59  N-1 N       d      d
# = Σ   Σ   Σ     (bi xor bj) * 2^(d-1)
#   d=1 i=1 j=i+1
#############################

#############################
#   N-1 N       d      d
#   Σ   Σ     (bi xor bj)
#   i=1 j=i+1
#
# = (bx のうち 1 の数) * (bx のうち 0 の数)
#############################

def input():
    return sys.stdin.readline().rstrip('\n')

N = int(input())
A = list(map(int, input().split()))

s = 0 #sum

for d in range(60):
    B = [1 & (a >> d)) for a in A]
    s += B.count(1) * B.count(0) * (2**d)
    #print(d,B,B.count(1),B.count(0),2**(d-1),s)

#print(s)
print(s % (10**9+7))

Submission status: Runtime Error

Solution code:
import numpy as np

N = int(input())
A = np.array(list(map(int, input().split())))

mod = 10**9 + 7
ans = 0

for i in range(60):
    c = len(A[A&1==1])
    a >>= 1
    ans = (ans + c*(N-c)*pow(2,i,mod))%mod

print(ans)

Submission status: Runtime Error

Solution code:
import numpy as np

N = int(input())
A = np.array(list(map(int, input().split())))

mod = 10**9 + 7
ans = 0

for i in range(60):
    c = len(A[A&1==1])
    ans = (ans + c*(N-c)*pow(2,i,mod))%mod
    a = a >> 1

print(ans)

Submission status: Runtime Error

Solution code:
#!/usr/bin/env python3

# mod = 10**9+7

# n = int(input())
# a = list(map(int, input().split()))

# max_digit = 61

# count_0 = [0 for _ in range(max_digit)]
# count_1 = [0 for _ in range(max_digit)]

# for i in range(len(a)):
#     num_str = bin(a[i])[2:]
#     # print(num_str)
#     for j in range(len(num_str)):
#         # print(num_str[-j-1])
#         if num_str[-j-1] == "1":
#             count_1[-j-1] += 1

# # for i in range(max_digit):
# #     count_0[i] = n-count_1[i]

# ans = 0
# count = 1
# for i in range(61):
#     # tmp = count_0[-i-1]*count_1[-i-1]
#     tmp = count_1[-i-1]*(n-count_1[-i-1])
#     ans += tmp*count
#     count = (count*2) % mod
# print(ans % mod)


n = int(input())
a = list(map(int, input().split()))

mod = 10**9+7
max_digit = 61

ans = 0
m = 1
for _ in range(max_digit):
    bit = sum(x&m x in a)
    bit //= m
    non_bit = n - bit
    ans = (ans+bit*nonbit*m)%mod
    m <<= 1
print(ans)

Submission status: Runtime Error

Solution code:
n,*a=map(int,open(0).read().split());c=0;i=1
for _ in[0]*61:i**=2;t=sum(i&b and 1for b in a);c+=t*(n-t)*i;c%=10**9+7
print(c

Submission status: Runtime Error

Solution code:
n = int(input())
a = list(map(int, input().split()))
c1_list = [0]*n
for i in range(n):
  b = format(a[i], '060b')
  for j in b:
    if j == "1":
      c1_list[j] += 1
count = 0
for i in range(n):
  count = (count + c1_list[i]*(n-c1_list[i])*2**(60-i)) % 1000000007
print(count)

Submission status: Runtime Error

Solution code:
n = int(input())
aa = list(map(int, input().split()))
mod = 10**9+7
res = 1
pow2 = 1
ans = 0
for i in range(60):
    cnt = np.count_nonzero(np.array(aa)&2)
    ans = (ans + cnt * (n-cnt) * res)%mod
    res = (res*2)%mod
    pow2*=2
print(ans)

Submission status: Runtime Error

Solution code:
n=int(input())
a=list(map(int,input().split()))

for b in a:
    for i in range(60):
        counts[i]+=b%2
        b//=2

ans=0
mod = 10**9+7
for i in range(60):
    c=counts[i]
    comb=c*(n-c)
    ans=(ans+(1<<i)*comb)%mod
print(ans)

Submission status: Runtime Error

Solution code:
MOD = (10**9) + 7
n = int(input())
a = list(map(int,intput().split()))

cnt = [0] * 60

for num in a:
  for j in range(60):
    cnt[j] += (num >> j) % 2
ans = 0
for b in range(60):
  ans += cnt[b] * (n-cnt[b]) << b
  
ans %= MOD
print(ans)

Submission status: Runtime Error

Solution code:
MOD = (10**9) + 7
n = int(input())
a = list(map(int,intput().split()))

cnt = [0] * 60

for num in a:
  for j in range(60):
    cnt[j] += num >> j
ans = 0
for b in range(60):
  ans += cnt[b] * (n-cnt[b]) << b % 2
  
ans %= MOD
print(ans)

Submission status: Runtime Error

Solution code:
MOD = (10**9) + 7
n = int(input())
a = list(map(int,intput().split()))

cnt = [0] * 60

for num in a:
  for j in range(60):
    cnt[j] += num >> j
ans = 0
for b in range(60):
  ans += cnt[b] * (n-cnt[b]) << b
  
ans %= MOD
print(ans)

Submission status: Runtime Error

Solution code:
n = int(input())
alist = []
xy = [[] for i in range(n)]
ans = 0
for i in range(n):
    xy[i] =  []
for i in range(n):
    alist.append(int(input()))
    for j in range(alist[i]):
        a,b=input().split()
        xy[i].append([int(a), int(b)])
g = [[] for i in range(2**n-1)]
for i in range(1,2**n):
    for j in range(n):
        if list(format(i,'0b').zfill(n))[j] == '1':
            g[i-1].append(xy[j])
def lie(xy,p):
    z = list(format(p,'0b').zfill(n)) 
    for i in range(len(xy)):
        for j in range(len(xy[i])):
            if str(xy[i][j][1]) == z[xy[i][j][0]-1]:
                continue
            else:
                return 'No'
                break
    return 'Yes'
for k in range(2**n-1):
    if lie(g[k],k+1) == 'Yes':
        ans = max(ans,list(str(format(k+1,'0b'))).count('1'))
print(ans)

Submission status: Runtime Error

Solution code:
import sys
 
# 改行またはスペース区切りの入力をすべて読み込んでイテレータを返します。
def get_all_int():
    return map(int, open(0).read().split())
 
def log(*args):
    print("DEBUG:", *args, file=sys.stderr)
 
def int_to_bits(x):
    return [ 1 if 2**i & x != 0 else 0 for i in range(60) ]
 
def inv(x, MOD):
    return pow(x, MOD-2, MOD)
 
MOD = 10**9+7
 
n,*A = get_all_int()
 
pow2 = [1] * 61
for i in range(1,61):
    pow2[i] = pow2[i-1] * 2
 
# ビットごとの出現回数 2**i
bits = [0] * 60
 
for a in A:
    for i in range(60):
        if pow2[i] & a != 0:
            bits[i] += 1

ans = 0
 
for a in A:
    for i in range(60):
        ans += pow(2,i,MOD) * abs(bits[i] - (1 if 2**i & a != 0 else 0) *n)
 
print(ans*inv(2) % MOD)

Submission status: Runtime Error

Solution code:
import sys
import numpy as np

# 改行またはスペース区切りの入力をすべて読み込んでイテレータを返します。
def get_all_int():
    return map(int, open(0).read().split())

def log(*args):
    print("DEBUG:", *args, file=sys.stderr)

def int_to_bits(x):
    return [ 1 if 2**i & x != 0 else 0 for i in range(60) ]

def inv(x, MOD):
    return pow(x, MOD-2, MOD)

MOD = 10**9+7

debug = False

if debug:
    n = 50000
    A = list(range(n))
else:
    n,*A = get_all_int()




# ビットごとの出現回数 2**i
bits = [0] * 60

for a in A:
    for i in range(60):
        if 2**i & a != 0:
            bits[i] += 1

# log("bits:", bits)

ans = 0

for a in A:
    a_bits = int_to_bits(a)

    for i in range(60):
        ans += 2**i * abs(bits[i] - a_bits[i]*n)

    # a_dash = list(map(lambda a: a*(n-1), a_bits))

    # log("a_dash", a_dash)

    # bits_dash = [ bits[i] - a_bits[i] for i in range(60)]
    # log("bits_dash", bits_dash)
    # ans += sum( ( 2**i * abs(bits_dash[i]-2*a_dash[i])) for i in range(60) )

    # ans += sum( ( 2**i * abs(bits[i]-2*a_dash[i])) for i in range(60) )

    # for i in range(60):
    #     ans = (ans + 2**i * abs(bits_dash[i] - a_dash[i])) % MOD
    # log(a, ans)

print(ans//2 % MOD)

Submission status: Runtime Error

Solution code:
import numpy as np
n = int(input())
a = list(map(int,input().split()))
mod = 10**9+7
ans = 0
now = 1

sum = np.zeros(60,dtype=int)
for i in a:
    ii = i
    for j in range(60):
        if ii%2 == 1:
            sum[j] += 1
        ii //= 2
        if ii == 0:
            break
    sum += aa

for i in range(60):
    k = (sum[i]*(n-sum[i]))%mod
    ans = (ans+(k*now)%mod)%mod
    now = (now*2)%mod

print(ans)

Submission status: Runtime Error

Solution code:
def main():
  import sys
  input = sys.stdin.readline
  n=int(input())
  a=sorted(list(map(int,input().split())))
  mod=pow(10,9)+7
  x=[0]*61
  for i in a:
    i=bin(i)
    l=len(i)
    for j in range(1,l-1):
      if i[-j]=='1':
        x[j]+=1
  ans=0
  for i in range(1,l+1):
    if x[i]>0:
      ans+=pow(2,i-1,mod)*(x[i]%mod)*((n-x[i])%mod)%mod
      ans%=mod
  print(ans)
if __name__=='__main__':
  main()

Submission status: Runtime Error

Solution code:
n, *A = map(int, open(0).read().split())
A = [a%mod for a in A]
mod = 10**9 + 7
ans = 0
d = 1
while any(A):
  c = 0
  for i in range(n):
    q, r = divmod(A[i], 2)
    A[i] = q
    c += r
  ans += c*(n-c) * d
  ans %= mod
  d *= 2
print(ans % mod)

Submission status: Runtime Error

Solution code:
N = int(input())
A = list(map(int,input().split()))

n = 30
D = [0]*n

for i in range(N):
    s = list(bin(A[i])[2:])[::-1]
    for j in range(len(s)):
        D[j] += int(s[j])
ans = 0
for i in range(n):
    ans += D[i]*(N-D[i])*2**i
    ans %= 10**9+7
print(ans)

Submission status: Runtime Error

Solution code:
N = int(input())
A = list(map(int,input().split()))

n = len(bin(N))-2
D = [0]*n

for i in range(N):
    s = list(bin(A[i])[2:])[::-1]
    for j in range(len(s)):
        D[j] += int(s[j])
ans = 0
for i in range(n):
    ans += D[i]*(N-D[i])*2**i
    ans %= 10**9+7
print(ans)

Submission status: Runtime Error

Solution code:
import sys


input = sys.stdin.readline

def main():
    N = int(input().rstrip())
    A = list(map(int, input().rstrip().split()))
    M = max(A).bit_length()
    B = [0] * M
    p = 10 ** 9 + 7
    ans = 0

    for n in range(N):
        a = bin(A[n])[:1:-1]
        l = len(a)
        for i in range(l):
            B[i] += int(a[i])

    for m in range(M):
        tmp = B[m] * (N - B[m]) * 2 ** m
        tmp %= p
        ans = ans + tmp
        ans %= p

    print(ans)


if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
N=int(input())
import math
A=list(map(int,input().split()))
b=math.ceil(math.log(max(A),2)) 
B=[0 for i in range(b)] #0のリスト
C=[0 for i in range(b)] #1のリスト
for i in A:
  for j in range(b):
    if ((i>>j) & 1):
      C[j]+=1
    else:
      B[j]+=1
 # print(B,C,i)
mod =10**9+7
ans=[(B[i]*C[i])*2**i % mod for i in range(b)]
print(sum(ans)%mod)