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) .

Solution (Python):
if __name__ == '__main__':
    MOD = 10 ** 9 + 7
    n = int(input())
    a = list(map(int, input().split()))
    res = 0
    two_factor = 1

    for d in range(60):
        even, odd = 0, 0
        for i in range(n):
            if a[i] & (1 << d):
                odd += 1
            else:
                even += 1
        add = (odd * even) % MOD * two_factor % MOD
        res = (res + add) % MOD
        two_factor = two_factor * 2 % MOD

    print(res)

Solution (Python):
K = 1000000007
N = int(input())
A = [int(a) for a in input().split()]
li = [0] * 60
for n in range(N):
    li = [li[i] + (A[n] >> i & 1) for i in range(60)]
ans = 0
for i in range(60):
    ans += (1 << i) * li[i] * (N - li[i])
    ans %= K
print(ans)

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

from collections import Counter
s = []

for i in range(n):
    b = bin(a[i])[2:]
    c = len(b)
    s.append("0"*(60-c) + b)
    
ans = 0
for i in range(60):
    zero = 0
    one = 0
    for j in range(n):
        if s[j][i] == "0":
            zero += 1
        else:
            one += 1
            
    temp = zero * one * (2 ** (59-i)) % MOD
    
    ans = (ans + temp) % MOD
    
print(ans)

Solution (Python):

import sys
import math
from bisect import bisect_left
from bisect import bisect_right
import collections
import copy
import heapq
from collections import defaultdict
from heapq import heappop, heappush
import itertools
input = sys.stdin.readline
from collections import defaultdict
from heapq import heappop, heappush

from decimal import *
































def inputInt(): return int(input())
def inputMap(): return map(int, input().split())
def inputList(): return list(map(int, input().split()))
def inputStr(): return input()[:-1]

inf = float('inf')
mod = 1000000007




def main():
	N = inputInt()
	A = inputList()

	A_list = []
	for vol in A:
		target = bin(vol)
		target = target[2:]
		target = target[::-1]
		A_list.append(target)

	ans = 0
	for k in range(60):
		conts_0 = 0
		conts_1 = 0
		for i,val in enumerate(A_list):
			if len(val) >= k+1:
				if "1" == val[k]:
					conts_1 += 1
				else:
					conts_0 += 1
			else:
				conts_0 += 1

		ans = (ans + (conts_1 * conts_0 * (2**k)) % mod ) % mod

	print(ans)






def combination(n, r, mod=10**9+7):
    r = min(r, n-r)
    res = 1
    for i in range(r):
        res = res * (n - i) * modinv(i+1, mod) % mod
    return res


def modinv(a, mod=10**9+7):
    return pow(a, mod-2, mod)

def egcd(a, b):
    if a == 0:
        return b, 0, 1
    else:
        g, y, x = egcd(b % a, a)
        return g, x - (b // a) * y, y



def H(n, r, mod=10**9+7):
	
	
    return combination(n+r-1, r, mod)

class Combination:
    """
    O(n)の前計算を1回行うことで，O(1)でnCr mod mを求められる
    n_max = 10**6のとき前処理は約950ms (PyPyなら約340ms, 10**7で約1800ms)
    使用例：
    comb = Combination(1000000)
    print(comb(5, 3))  
    """
    def __init__(self, n_max, mod=10**9+7):
        self.mod = mod
        self.modinv = self.make_modinv_list(n_max)
        self.fac, self.facinv = self.make_factorial_list(n_max)

    def __call__(self, n, r):
        return self.fac[n] * self.facinv[r] % self.mod * self.facinv[n-r] % self.mod

    def make_factorial_list(self, n):
        
        
        fac = [1]
        facinv = [1]
        for i in range(1, n+1):
            fac.append(fac[i-1] * i % self.mod)
            facinv.append(facinv[i-1] * self.modinv[i] % self.mod)
        return fac, facinv

    def make_modinv_list(self, n):
        
        modinv = [0] * (n+1)
        modinv[1] = 1
        for i in range(2, n+1):
            modinv[i] = self.mod - self.mod//i * modinv[self.mod%i] % self.mod
        return modinv

if __name__ == "__main__":
	main()

Solution (Python):
import numpy as np
import sys, math
from itertools import permutations, combinations
from collections import defaultdict, Counter, deque
from math import factorial
from bisect import bisect_left 
sys.setrecursionlimit(10**7)
enu = enumerate
MOD = 10**9+7
def input(): return sys.stdin.readline()[:-1]
def pri(x): print('\n'.join(map(str, x)))

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


cnt = 0
for i in range(61):
    B = (A>>i)&1
    z = np.count_nonzero(B)
    cnt += z*(N-z)*(2**(i))
    cnt %= MOD

print(cnt)

Solution (Python):
if __name__ == "__main__":
    n = int(input())
    a = list(map(int, input().split()))
    ans = 0
    mod = 1000000007

    for i in range(60):
        x = 0
        for j in range(n):
            if a[j] >> i & 1:
                x += 1
        
        now = x * (n - x) % mod
        for j in range(i):
            now = now * 2 % mod
        ans += now
        ans %= mod
    print(ans)

Solution (Python):
n, *A = map(int, open(0).read().split())
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)

Solution (Python):
import sys
input = sys.stdin.readline
rs = lambda: input().strip()
ri = lambda: int(input())
rl = lambda: list(map(int, input().split()))
mod = 10**9 + 7

N = ri()
A = rl()

b = [0] * 60

def count(a, b):
	i = len(b)-1
	while a:
		b[i] += a % 2
		a //= 2
		i -= 1
	return i+1

def sum_xor(a, b, l, left):
	i = len(b)-1
	e = 1
	s = 0
	while a or left <= i:
		if a % 2 == 0:
			s = (s + b[i] * e) % mod
		else:
			s = (s + (l-(b[i])) * e) % mod
		a //= 2
		e = e * 2 % mod
		i -= 1
	return s

ans = 0
min_left = 60
for i in range(N):
	if i > 0:
		ans = (ans + sum_xor(A[i], b, i, min_left)) % mod
	left = count(A[i], b)
	min_left = min(min_left, left)
print(ans)

Solution (Python):
n = int(input())
ns = list(map(int, input().split()))
d = [0] * 60
ans = 0
mod = 10 ** 9 + 7
for i in range(60):
    for num in ns:
        d[i] += (num >> i) & 1
    ans = (ans + d[i] * (n-d[i]) * 2 ** i) % mod
print(ans)

Solution (Python):
import sys
input=sys.stdin.readline




















import numpy as np
from collections import defaultdict
MOD = pow(10,9)+7
N = int(input())
d = [[N,0] for _ in range(60)]
A = list(map(int,input().split()))
A = np.array(A)
ans = 0
for m in range(60):
    B = (A >> m) & 1
    x = np.count_nonzero(B)
    x *= (N-x)
    x *= pow(2,m,MOD)
    ans += x
print(ans%MOD)

Solution (Python):
import sys
input=sys.stdin.readline



















from collections import defaultdict
MOD = pow(10,9)+7
N = int(input())
d = [[N,0] for _ in range(60)]
A = list(map(int,input().split()))
for k in A:
    c = 0
    while k > 0:
        if k % 2 == 1:
            d[c][0] -= 1
            d[c][1] += 1
        k = k // 2
        c += 1
s = 0
for i in range(60):
    li = d[i]
    s += (li[0]*li[1]*pow(2,i,MOD))%MOD
print(s%MOD)

Solution (Python):
import sys
import math  
import bisect  
import queue  


def input():
    return sys.stdin.readline().rstrip()


def main():
    _ = int(input())
    A = list(map(int, input().split()))

    D = [[0, 0] for _ in range(70)]
    for a in A:
        for i in range(70):
            if (a >> i) & 1:
                D[i][1] += 1
            else:
                D[i][0] += 1

    res = 0
    for i in range(70):
        res += D[i][0] * D[i][1] * 2 ** i
        res %= 10 ** 9 + 7
    print(res)


if __name__ == '__main__':
    main()

Solution (Python):
mod = 1000000007
n = int(input())
a = list(map(int, input().split()))

lap = 0
big = max(a)
while big > 0:
    big //= 2
    lap += 1

xor = [0 for _ in range(lap)]
for i in a:
    num = 0
    for j in range(lap):
        if i % 2 == 1:
            xor[num] += 1
        i //= 2
        num += 1

ans = 0
for i in range(lap):
    ans += pow(2, i, mod) * xor[i] * (n - xor[i]) % mod
    ans %= mod

print(ans)

Solution (Python):
N = int(input())
A = list(map(int,input().split()))
mod = 10 ** 9 + 7
cnt = [0 for _ in range(60)]
for a in A:
    for i in range(60):
        cnt[i] += a & 1
        a >>= 1
cnt = [x * (N - x) % mod for x in cnt]
power = 1
ans = 0
for i in range(60):
    ans += power * cnt[i]
    power *= 2
    power %= mod
ans %= mod
print(ans)

Solution (Python):
N=int(input())
A=list(map(int,input().split()))
MOD=10**9+7
ans=0
for i in range(60):
    a,b=0,0
    for j in range(N):
        if A[j]%2==0:
            a=a+1
        else:
            b=b+1
        A[j]=A[j]//2
    ans=(ans+(a*b)*2**i)%MOD
print(ans)

Solution (Python):
N = int(input())
MOD = 1e+9 + 7
shift = 70
a = [int(i) for i in input().split()]

b = [0 for _ in range(shift)]

for i in a:
  for j in range(shift):
    b[j] += (i >> j) & 1

ans = 0
for i, j in enumerate(b):
  ans += ((j * (N - j)) * 2**i) % MOD
  
print(int(ans%MOD))

Solution (Python):
N = int(input())
A = list(map(int, input().split()))
count = [0] * 60
m = 1000000007
def pow_k(x, n):
    if n == 0:
        return 1
    K = 1
    while n > 1:
        if n % 2 != 0:
            K = (K * x) % 1000000007
        x = (x * x) % 1000000007
        n //= 2
    return (K * x) % 1000000007
mul = [pow_k(2,59-i) for i in range(60)]
for a in A:
    b = bin(a)
    for i in range(1,len(b)-1):
        if b[-i] == '1':
            count[-i] += 1
print(sum([count[i]*(N-count[i])*mul[i]%m for i in range(60)])%m)

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

nonzero = [0]*60

for i in range(N):
    for j in range(60):
        tmp = (A[i] >> j) & 1
        if tmp != 0:
            nonzero[j] += 1

ans = 0
MOD = 10**9+7

for i in range(60):
    ans += ((N-nonzero[i])*nonzero[i]*(2**i))%MOD
    
print(ans%MOD)

Solution (Python):
from sys import stdin
import numpy as np
mod = 10**9+7
N = int(stdin.readline().rstrip())
A = [int(x) for x in stdin.readline().rstrip().split()]
A = np.array(A)
ans = 0
d = 1

while d < (1 << 60):
    cnt = np.count_nonzero(A & d)
    ans += (N - cnt) * cnt * d
    ans %= mod
    d <<= 1
print(ans)

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

n = 62
D = [0]*n

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

Solution (Python):
import sys
import numpy as np


input = sys.stdin.readline

def main():
    N = int(input().rstrip())
    A = np.array(input().rstrip().split(), dtype=np.int64)
    M = 60
    p = 10 ** 9 + 7
    ans = 0

    for m in range(M):
        B = (A >> m) & 1
        x = np.count_nonzero(B)
        x *= N-x
        
        x *= 2 ** m
        x %= p
        ans += x

    print(ans % p)


if __name__ == '__main__':
    main()

Solution (Python):

import math
import fractions
import collections
import itertools
import heapq
import string
import sys
import copy
import numpy as np
from decimal import *
from collections import deque
sys.setrecursionlimit(10**7)
MOD = 10**9+7
INF = float('inf') 
def gcd(a,b):return fractions.gcd(a,b) 
def lcm(a,b):return (a*b) // fractions.gcd(a,b) 
def iin(): return int(sys.stdin.readline()) 
def ifn(): return float(sys.stdin.readline()) 
def isn(): return sys.stdin.readline().split() 
def imn(): return map(int, sys.stdin.readline().split()) 
def imnn(): return map(lambda x:int(x)-1, sys.stdin.readline().split()) 
def fmn(): return map(float, sys.stdin.readline().split()) 
def iln(): return list(map(int, sys.stdin.readline().split())) 
def iln_s(): return sorted(iln()) 
def iln_r(): return sorted(iln(), reverse=True) 
def fln(): return list(map(float, sys.stdin.readline().split())) 
def perm(l, n): return itertools.permutations(l, n) 
def perm_count(n, r): return math.factorial(n) // math.factorial(n-r) 
def comb(l, n): return itertools.combinations(l, n) 
def two_distance(a, b, c, d): return ((c-a)**2 + (d-b)**2)**.5 
def m_add(a,b): return (a+b) % MOD
def lprint(l): print(*l, sep='\n')

N = iin()
A = np.array(sys.stdin.readline().split(), np.int64)

two_factor = 1
ans = 0
for i in range(60):
    B = A >> i & 1
    ones = np.count_nonzero(B)
    zeros = N - ones
    zeroone_cmb = ones*zeros%MOD
    ans = (ans + (zeroone_cmb*two_factor%MOD))%MOD
    two_factor = (two_factor*2)%MOD

print(ans)

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

Solution (Python):
N = int(input())
A = list(map(int, input().split()))
MOD = 10 ** 9 + 7

bucket = [0] * 61
for num in A:
    for j in range(60):
        if (num >> j) & 1:
            bucket[j] += 1


ans = 0
res = 1
for i, one in enumerate(bucket):
    temp = (bucket[i] * (N - bucket[i]) * res) % MOD
    
    ans = (ans + temp) % MOD
    res = (res * 2) % MOD
print(ans)

Solution (Python):
n, *a = map(int, open(0).read().split())
ans = 0
mod = 10 **9 + 7
for k in range(61):
	m = 1 << k
	c = 0
	for x in a:
		if m & x:
			c += 1
	ans +=c * (n - c) * m
	ans %= mod
print(ans)

Solution (Python):
import sys

sys.setrecursionlimit(10 ** 5 + 10)


def input(): return sys.stdin.readline().strip()


def resolve():
    N = int(input())
    A = list(map(int, input().split()))
    mod = 10 ** 9 + 7
    ans = 0

    for k in range(60):
        
        x0 = 0
        x1 = 0
        for i in range(N):
            x = A[i] >> k & 1  
            if x == 0:
                x0 += 1
            else:
                x1 += 1
        ans += (x0 * x1) * (2 ** k)
    print(ans % mod)


resolve()

Solution (Python):
n = int(input())
a = list(map(int, input().split()))
a.sort()
ans=0
cnt=0
fin=False
while not fin:
    fin=True
    z_cnt=0
    o_cnt=0
    for i in range(len(a)):
        q,mod = divmod(a[i],2)
        a[i]=q
        if q!=0:
            fin=False
        if mod==0:
            z_cnt+=1
        else:
            o_cnt+=1

    ans+=(z_cnt*o_cnt) * pow(2,cnt)
    ans%=10**9+7
    cnt+=1
print(ans)

Solution (Python):

import sys

MOD = 1000000007  


def solve(N: int, A: "List[int]"):
    A = [format(a, "b")[::-1] for a in A]
    a_sum = [int()]*60

    for a in A:
        for i, r_a in enumerate(a):
            if r_a == "1":
                a_sum[i] += 1

    a_sum = [a_s_*(2**i)%MOD for i, a_s_ in zip(range(60), a_sum)]
    a_acc_sum = [_ for _ in a_sum]

    for x in range(1,60):
        a_acc_sum[x] = a_acc_sum[x-1] + a_acc_sum[x] 
    
    ans = 0
    for a in A:
        for i, r_a in enumerate(a):
            if r_a == "0":
                ans += a_sum[i]
        
        ans += a_acc_sum[59] - a_acc_sum[i]
        ans %= MOD

    print(ans%MOD)

    return



def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  
    A = [int(next(tokens)) for _ in range(N)]  
    solve(N, A)

if __name__ == '__main__':
    main()

Solution (Python):

import sys

MOD = 1000000007  


def solve(N: int, A: "List[int]"):
    A = [format(a, "b")[::-1] for a in A]
    a_sum = [int()]*60

    for a in A:
        for i, r_a in enumerate(a):
            if r_a == "1":
                a_sum[i] += 1

    a_sum = [a_s_*(2**i)%MOD for i, a_s_ in zip(range(60), a_sum)]
    a_acc_sum = [_ for _ in a_sum]
    
    for x in range(1,60):
        a_acc_sum[x] = a_acc_sum[x-1] + a_acc_sum[x] 
    
    ans = 0
    for a in A:
        for i, r_a in enumerate(a):
            if r_a == "0":
                ans += a_sum[i]
        
        ans += a_acc_sum[59] - a_acc_sum[i]

        
            
            

    print(ans%MOD)

    return



def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  
    A = [int(next(tokens)) for _ in range(N)]  
    solve(N, A)

if __name__ == '__main__':
    main()

Solution (Python):
import numpy as np
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

n = int(readline())
a = np.array(read().split(), np.int64)

mod = 10 ** 9 + 7
ans = 0

for i in range(61):
    b = a >> i & 1
    x = np.count_nonzero(b)
    y = n - x
    z = x * y
    z *= 2 ** i
    z %= mod
    ans += z
ans %= mod

print(ans)

Solution (Python):
MOD = 10**9+7
n = int(input())
A = ['{:060b}'.format(a)[::-1] for a in map(int, input().split())]
c = [a.count('1') for a in zip(*A)]
print(sum(c[d]*(n-c[d])*pow(2, d, MOD) %
          MOD for d in range(60)) % MOD)

Solution (Python):
MOD = 10**9+7
n = int(input())
A = list(map(int, input().split()))
n_bit = 60
bit_cnt = [0]*n_bit
for i in range(n):
    for d in range(n_bit):
        if (A[i] >> d) & 1:
            bit_cnt[d] += 1

ans = 0
for d, one_cnt in enumerate(bit_cnt):
    ans = ans + one_cnt*(n-one_cnt)*pow(2, d, MOD) % MOD
print(ans % MOD)

Solution (Python):
MOD = 10**9+7
n = int(input())
A = ['{:060b}'.format(a)[::-1] for a in map(int, input().split())]
A_d = []
for col in zip(*A):
    one_cnt = col.count('1')
    A_d.append(one_cnt*(n-one_cnt))

ans = 0
for d in range(60):
    ans = ans + A_d[d]*pow(2, d, MOD) % MOD
print(ans % MOD)

Solution (Python):
MOD = 10**9+7
n = int(input())
A = ['{:060b}'.format(a)[::-1] for a in map(int, input().split())]
A_d = []
for col in zip(*A):
    zero_cnt = col.count('0')
    A_d.append(zero_cnt*(n-zero_cnt))

ans = 0
for d in range(60):
    ans = ans + A_d[d]*pow(2, d, MOD) % MOD
print(ans % MOD)

Solution (Python):
import numpy as np
 
mod = 10**9 + 7
 
N = int(input())
A = np.array(list(map(int, input().split())))
 
 
ans = 0
for n in range(len(bin(max(A)))):   
    n_1 = np.count_nonzero((A >> n)&1)   
    n_0 = N - n_1                       
    ans += ((2 ** n)*n_1*n_0) % mod

print(ans%mod)

Solution (Python):
import numpy as np
 
mod = 10 ** 9 + 7
 
N = int(input())
A = np.array(list(map(int, input().split())))
 
 
ans = 0
for n in range(len(bin(max(A)))):   
    num_1 = np.count_nonzero((A >> n)&1)   
    num_0 = N - num_1                      
    mul = num_1 * num_0   
    ans += ((2 ** n)*mul) % mod
ans %= mod
print(ans)

Solution (Python):
import numpy as np
 
data = int(input())
array = np.fromiter(map(int, input().split()), np.int64)
 
result = 0
for bit in range(60):
    array01 = int((array & 1).sum())
    result = (result + array01 * (data - array01) * (1 << bit)) % 1000000007
    array >>= 1
print(result)

Solution (Python):
def powmod(x, y, mod):
    if y == 0:
        return 1
    return (((powmod(x, y >> 1, mod) ** 2) % mod) * x ** (y & 1)) % mod


n = int(input())
a = tuple(map(int, input().split()))
mod = 10**9 + 7
cnt = [0] * 60
for i in range(n):
    r = a[i]
    for j in range(60):
        if r & 1:
            cnt[j] += 1
        r >>= 1

ans = 0
for i in range(60):
    ans += powmod(2, i, mod) * cnt[i] * (n-cnt[i])
    ans %= mod
print(ans)

Solution (Python):
N = int(input())
M = list(map(int, input().split()))
M = [bin(m)[2:] for m in M]
max_len = max([len(m) for m in M])
M = ["0"*(max_len-len(m))+m for m in M]
MOD = 10**9+7
result = 0
for i in range(1, max_len+1):
  zero = len([m[-i] for m in M if m[-i]=="0"])
  one = len(M) - zero
  
  result += (((one * zero) % MOD) * ((2 ** (i-1)) % MOD) % MOD)
  result %= MOD
print(result)

Solution (Python):
n = int(input())
a = list(map(int, input().split()))
mod = 10**9 + 7
d = [0]*60
for i in range(n):
    for j in range(60):
        if a[i] >> j & 1 == 1:
            d[j] += 1

ans = 0
for j in range(60):
    ans += 2**j * d[j] * (n - d[j]) % mod

print(ans % mod)

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

MOD = 10**9 + 7

dig = 60
Abn = [[0]*dig for _ in range(n)]

b0 = [0]*dig
b1 = [0]*dig
for i in range(n):
  for j in range(dig):
    if A[i]>>j&1:
      b1[j] += 1
    else:
      b0[j] += 1
      
pow2 = [pow(2, i, MOD) for i in range(dig)]

ans = 0
for i in range(dig):
  ans += b1[i]*b0[i]*pow2[i]%MOD
  
print(ans%MOD)

Solution (Python):
from sys import stdin
import numpy as np
def main():
    n = int(stdin.readline().rstrip())
    a = list(map(int,stdin.readline().rstrip().split()))
    a = np.array(a)
    mod = 10**9+7
    point = 0
    for i in range(61):
        b = (a >> i)&1
        x = np.count_nonzero(b)
        y = n-x
        point += x*y*(2**i)%mod
    print(point%mod)
if __name__ == "__main__":
    main()

Solution (Python):
from sys import stdin
def main():
    n = int(stdin.readline().rstrip())
    a = list(map(int,stdin.readline().rstrip().split()))
    mod = 10**9+7
    point = 0
    for i in range(61):
        now = sum(1 for j in a if(j >> i)&1)
        point += now*(n-now)*(2**i)%mod
        point %= mod
    print(point)
if __name__ == "__main__":
    main()

Solution (Python):
n = int(input())
a = list(map(int,input().split()))
mod = 10**9+7
point = 0
for i in range(61):
    now = 0
    for j in a:
        now += (j >> i&1)
    now *= n-now
    now %= mod
    for k in range(i):
        now *= 2
        now %= mod
    point += now
    point %= mod
print(point)

Solution (Python):
M = 10 ** 9 + 7
N = int(input())
A = list(map(int, input().split()))
pow2 = [2 ** i % M for i in range(60)]
ans = 0
a1 = [(A[0] >> i) & 1 for i in range(60)]
a0 = [1 - x for x in a1]
for i in range(1, N):
    a = A[i]
    for j in range(60):
        b1 = a & 1
        a >>= 1
        if b1:
            ans += pow2[j] * a0[j] % M
            a1[j] += 1
        else:
            ans += pow2[j] * a1[j] % M
            a0[j] += 1
        ans %= M
print(ans)

Solution (Python):
M = 10 ** 9 + 7
N = int(input())
A = list(map(int, input().split()))

zero = [0] * 60
one = [1] * 60
pow2 = [2 ** i % M for i in range(60)]


def bitcnt(a):
    j = 0
    bits = [0] * 60
    while a:
        bits[j] = a & 1
        a >>= 1
        j += 1
    return bits


ans = 0
a1 = bitcnt(A[0])
a0 = [(x + 1) % 2 for x in a1]
for i in range(1, N):
    a = A[i]
    for j in range(60):
        b1 = a & 1
        a >>= 1
        if b1:
            ans += pow2[j] * a0[j] % M
            a1[j] += 1
        else:
            ans += pow2[j] * a1[j] % M
            a0[j] += 1
        ans %= M

print(ans)

Solution (Python):
n=int(input())
a=list(map(int,input().split()))
g=[0]*60
mod=10**9+7
for i in range(n):
    for j in range(60):
        if (a[i]>>j)&1==1:
            g[j]+=1

cnt=0
for i in range(60):
    now=g[i]
    cnt+=now*(n-now)*(2**i)
    cnt%=mod

print(cnt)

Solution (Python):
n = int(input())
A = list(map(int, input().split()))
bits = [0] * 60
MOD = 10**9 + 7

for a in A:
    div = a
    i = 0
    while True:
        div, mod = div // 2, div % 2
        bits[i] += mod
        i += 1
        if div == 0:
            break

ans = 0
for i in range(60):
    ans += bits[i] * (n-bits[i]) * 2 ** i % MOD
print(ans % MOD)

Solution (Python):
N = int(input())
A = list(map(int,input().split()))
p = 1000000007
max_n = len(bin(max(A)))-2
mask = 1
s = 0
for i in range(max_n):
  s0 = 0
  s1 = 0
  for j in range(N):
    s0 += (A[j] & (mask << i)) >> i
    s1 += (~(A[j] | ~(mask << i))) >> i
  s += ((2**i)*s0*s1)%p
print(s%p)

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

mod = 10 ** 9 + 7
digits = [0] * 60
ans = 0
for ai in a:
    temp = ai
    num = len(bin(temp)) - 2
    for i in range(num):
        if (temp >> i) & 1:
            digits[i] += 1
    ans += (n - 1) * temp
    ans = ans % mod

for i in range(60):
    digit = digits[i]
    temp = digit * (digit - 1) * pow(2, i, mod)
    ans -= temp % mod
print(ans % mod)

Solution (Python):
import numpy as np
from math import ceil,log2
N = int(input())
a = np.array(list(map(int,input().split())),dtype=np.int64)
ans = 0
count = 1
if max(a) == 0:
    x = 1
else:
    x = ceil(log2(max(a)))

for i in range(x):
    b = a%2
    s = np.count_nonzero(b==1)*np.count_nonzero(b==0)*count
    ans +=s
    count *= 2
    a = a//2
    ans %= 10**9+7
print(ans)

Solution (Python):
import numpy as np
 
data = int(input())
array = np.fromiter(map(int, input().split()), np.int64)
 
result = 0
for bit in range(60):
    array01 = int((array & 1).sum())
    result = (result + array01 * (data - array01) * (1 << bit)) % 1000000007
    array >>= 1
print(result)

Solution (Python):
N = int(input())
A = list(map(int, input().split(" ")))
mod = 10 ** 9 + 7

ans = 0
for i in range(61):
    zero, one = 0, 0
    for j in range(N):
        if (A[j] >> i) & 1 == 0:
            zero += 1
        else:
            one += 1
    ans += zero * one * (1 << i)
    ans %= mod
print(ans)

Solution (Python):
import numpy as np

data = int(input())
array = np.array(list(map(int, input().split())))
mod = 10 ** 9 + 7
counter = 0
for i in range(60):
    tmp = array & 1
    array >>= 1
    x = np.count_nonzero(tmp)
    x *= data - x
    counter = (counter + pow(2, i, mod) * x) % mod
print(counter)

Solution (Python):
import numpy as np

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

res=0
mod=10**9+7
for i in range(61):
  cnt=np.count_nonzero(A>>i & 1)
  res+=cnt*(N-cnt)<<i
  res%=mod
print(res)

Solution (Python):

n=int(input())

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

ans=0
mod=10**9+7
for i in range(60):
    x=0
    for j in range(n):
        if (a[j] >>i&1) :x+=1

    now = x*(n-x) % mod

    for j in range(i):
        now = now*2 % mod
    ans += now
    ans %= mod

print(ans)

Solution (Python):
M=10**9+7
n,*l=map(int,open(0).read().split())
a=0
for i in range(60):
  t=sum(j>>i&1 for j in l)
  a+=t*(n-t)*pow(2,i,M)
print(a%M)

Solution (Python):
import numpy as np

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

res = 0
mod = 10**9 + 7
for i in range(61):
    cnt = np.count_nonzero(a >> i & 1)
    res += cnt * (n-cnt) << i
    res %= mod

print(res)

Solution (Python):
from itertools import count

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

d_cumsum = [0] * 60
for v in a:
    for i in count():
        d_cumsum[i] += v % 2
        v //= 2
        if v == 0:
            break

res = 0
mod = 10**9 + 7
for i, d in enumerate(d_cumsum):
    res += (2**i * d * (n-d)) % mod
    res %= mod

print(res)

Solution (Python):



import numpy as np

n=int(input())
a=np.array(list(map(int,input().split())))
res=0
for j in range(60):
  s=0 
  """
  for i in a:
    if (i>>j & 0b1)==0b1:
      s+=1
  """
  s=np.count_nonzero(a>>j&1)
  r=2**j*(n-s)*s
  res=(res+r)%(10**9+7)
print(res)

Solution (Python):
n = int(input())
a = [int(s) for s in input().split()]
d = 0
ans = 0
mod = 10**9+7
for d in range(60):
	c0 = 0
	c1 = 0
	for v in a:
		if v >> d & 1:
			c1 += 1
		else:
			c0 += 1
	ans = (ans + (c0 * c1 << d)) % mod
print(ans)

Solution (Python):
M=10**9+7
n=int(input())
l=list(map(int,input().split()))
a=0
for i in range(60):
  t=sum(j>>i&1 for j in l)
  a+=(t*(n-t)<<i)%M
print(a%M)

Solution (Python):
M=10**9+7
n=int(input())
l=list(map(int,input().split()))
a=0
for i in range(60):
  t=sum((l[j]>>i)%2 for j in range(n))
  a+=(t*(n-t)<<i)%M
print(a%M)

Solution (Python):
import numpy as np
N=int(input())
A=np.array(list(map(int,input().split())))
ans=0
mod=10**9+7
for i in range(61):
    n=np.count_nonzero(A>>i & 1)
    ans+=n*(N-n)<<i
print(ans%mod)

Solution (Python):
N=int(input())
A=list(map(int,input().split()))
ans=0
mod=10**9+7
for i in range(61):
    a=sum([1 for j in A if j>>i & 1])
    ans=ans+a*(N-a)*(2**i)
    ans=ans%mod
print(ans)

Solution (Python):
import sys
import numpy as np
MOD = 10 ** 9 + 7

n = int(sys.stdin.readline().rstrip())
a = np.array(sys.stdin.readline().split(), dtype=np.int64)

def main():
  x = a[:, None] >> np.arange(60) & 1
  x = x.sum(axis=0)
  y = n - x
  res = x * y  % MOD * ((1 << np.arange(60)) % MOD)
  print(res.sum() % MOD)

if __name__ == '__main__':
  main()

Solution (Python):
import sys
import numpy as np
MOD = 10 ** 9 + 7

n = int(sys.stdin.readline().rstrip())
a = np.array(sys.stdin.readline().split(), dtype=np.int64)

def main():
  x = a[:, None] >> np.arange(61) & 1
  x = x.sum(axis=0)
  y = n - x
  res = x * y  % MOD * ((1 << np.arange(61)) % MOD)
  print(res.sum() % MOD)

if __name__ == '__main__':
  main()

Solution (Python):
import numpy as np

n = int(input())
arr = np.array([int(i) for i in input().split()])
mod = 10 ** 9 + 7
s = 0

for i in range(60):
    c1 = np.count_nonzero(arr & 1) 
    s += 2 ** i * c1 * (n - c1)
    arr >>= 1

print(s % mod)

Solution (Python):
import numpy as np
MOD = 10 ** 9 + 7
N = int(input())
A = np.array(list(map(int, input().split())))
ans = 0
for n in range(60): 
    cnt_1 = np.count_nonzero((A>>n)&1)
    cnt_0 = N - cnt_1
    ans += (cnt_1 * cnt_0 * (2 ** n)) % MOD
ans %= MOD
print(ans)

Solution (Python):
mod = 10**9+7
n = int(input())
A = list(map(int,input().split()))
c01 = [[0,0] for i in range(60)]
for a in A:
    for j in range(60):
        if a>>j &1:
            c01[j][1] += 1
        else:
            c01[j][0] += 1
ans = 0
for i in range(60):
    ans += 2**i *c01[i][0]*c01[i][1]
    ans%=mod
print(ans)

Solution (Python):
import numpy as np

n = int(input())
a = np.array(input().split(), np.int64)
MOD = 10**9 + 7

max_num = np.max(a)
max_digit = len(format(max_num, 'b'))

ans = 0

for digit in range(max_digit):
    b = (a >> digit) & 1
    one = np.count_nonzero(b)
    zero = n - one
    ans += 2 ** digit *  (one * zero)
    ans %= MOD

print(ans)

Solution (Python):
n = int(input())
al = list(map(int,input().split()))

pl = [0 for i in range(61)]

for a in al:
    turn = 0
    while a:
        if a % 2 == 1:
            pl[turn] += 1
        a //= 2
        turn += 1

ans = 0
k = 1
for p in pl:
    ans += p * (n - p) * k
    ans %= 10**9 + 7
    k *= 2
    k %= 10 ** 9 + 7

print(ans)

Solution (Python):
import numpy as np
n = int(input())
a = np.array(list(map(int, input().split())))
p = 10**9 + 7
ans = 0
for i in range(60):
  c = np.count_nonzero(a & 1)
  ans = (ans + c*(n-c)*2**i) % p
  a = a >> 1
print(ans)

Solution (Python):
import sys
def input(): return sys.stdin.readline().rstrip()

def main():
    N = int(input())
    A = list(map(int, input().split()))
    MAX_BIT = 60
    MOD = 10 ** 9 + 7

    data = [0] * (MAX_BIT + 2)
    for a in A:
        for bit in range(MAX_BIT + 1):
            if a & (1 << bit):
                data[bit] += 1
    ans = 0
    for i, d in enumerate(data):
        if d == 0:
            continue
        ans += pow(2, i, MOD) * d * (N-d)
        ans %= MOD
    print(ans)

if __name__ == '__main__':
    main()