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):
N = int(input())
A = list(map(int, input().split()))

result = 0
for i in range(60):
    target = 1 << i
    on = sum([target & a for a in A]) >> i
    result += (on * (N - on)) << i
    result %= ((10**9) + 7)

print(result)

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

Solution (Python):
m = 10**9 + 7
n = int(input())
seq = [bin(int(x))[2:].zfill(61) for x in input().split()]
cnt = [[0,0] for i in range(61)]
for s in seq:
    for i in range(len(s)):
        if s[i] == '0':
            cnt[i][0] += 1
        else:
            cnt[i][1] += 1
ans = 0
for i in range(61):
  ans += cnt[-i-1][0]*cnt[-i-1][1]*(2**i)
  ans = ans % m
print(ans)

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

mod = 10**9+7

array = [0] * 60

for i in a:
    for j in range(len(bin(i))-2):
        
        array[j] += (i >> j) & 1

ans = 0


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

print(ans % mod)

Solution (Python):
import numpy as np

N = int(input())
A = np.fromstring(input(), dtype = np.int64, sep = ' ')

result = 0
for bit in range(60):
    c = int((A & 1).sum())
    A >>= 1
    result = (result + c * (N - c) * (1 << bit)) % 1000000007
print(result)

Solution (Python):
import numpy as np

N = int(input())
A = np.fromiter(map(int, input().split()), np.int64)

result = 0
for bit in range(60):
  c = int((A & 1).sum())
  A >>= 1
  result = (result + c * (N - c) * (1 << bit)) % 1000000007
print(result)

Solution (Python):
import logging
import numpy as np


logging.basicConfig(level=logging.INFO, format="%(message)s")


Mod = 10 ** 9 + 7

def main():
    N = int(input())
    arr_1 = np.array(list(map(int, input().split())))
    logging.info("Hello!")

    ans = 0

    for i in range(64):
        num_of_1 = np.count_nonzero(arr_1 & 1)
        ans += (2 ** i) * (num_of_1 * (N - num_of_1))
        arr_1 >>= 1
        
    print(ans % Mod)
    
    
if __name__ == "__main__":
    main()

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

result = 0
for bit in range(60):
    m = 1 << bit
    c = sum(a & m for a in A) >> bit
    result += (c * (N - c)) << bit
    result %= 1000000007
print(result)

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

result = 0
for bit in range(60):
    m = 1 << bit
    c = sum(a & m for a in A)
    c >>= bit
    result += (c * (N - c)) << bit
    result %= 1000000007
print(result)

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

result = 0
for bit in range(60):
    m = 1 << bit
    c = sum((a & m for a in A))
    c >>= bit
    result += (c * (N - c)) << bit
    result %= 1000000007
print(result)

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

result = 0
for bit in range(60):
    m = 1 << bit
    bits = sum((a & m for a in A))
    bits >>= bit
    result += (bits * (N -  bits)) << bit 
    result %= 1000000007
print(result)

Solution (Python):
n = int(input())
a = list(map(int,input().split()))
import numpy as np
a=np.array(a)
mod = 10**9+7
md = len(bin(max(a)))
ans = 0
for d in range(md):
    cnt1 = np.count_nonzero((a>>d)&1)
    ans += cnt1 * (n-cnt1) * (1<<d)          
    ans %= mod                               
    
print(ans%mod)

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

Solution (Python):
import numpy as np

N = int(input())
A = np.fromiter(map(int, input().split()), np.int64)

result = 0
for b in range(60):
  bs = int(((A >> b) & 1).sum())
  result = (result + bs * (N - bs) * (1 << b)) % 1000000007
print(result)

Solution (Python):
mod = 10**9+7
from collections import defaultdict
N = int(input())
A = list(map(int,input().split()))
d = defaultdict(lambda:0)
ans = 0
for a in A:
    a = bin(a)[2:]
    for i in range(len(a)):
        if a[-i-1]=='1':
            d[i] += 1

for i in range(60):
    ans += pow(2,i,mod)*d[i]*(N-d[i])

ans %= mod
print(ans)

Solution (Python):
import numpy as np

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

result = 0
for b in range(60):
  bs = int(((A >> b) & 1).sum())
  result = (result + bs * (N - bs) * (1 << b)) % 1000000007
print(result)

Solution (Python):
import numpy as np
M = 10**9+7
N = int(input())
A = np.array(list(map(int,input().split())),dtype='int64')
ans = 0

maxA = np.amax(A)
K = len(str(bin(maxA)))-2

for k in range(K):
    N1 = 0
    N1 = np.sum((A >> k) & 1)
    N0 = N-N1
    ans += (((1<<k)%M) *N0%M) *N1%M
    ans %= M

print(ans)

Solution (Python):
N = int(input())
As = str(input()).split(' ')
a_s = [int(a) for a in As]

import numpy as np
a_s = np.array(a_s)
sum = 0
index = 0
for n in range(60):
  b = (a_s >> n) & 1
  x = np.count_nonzero(b)
  y = N - x
  ans = x * y
  for _ in range(n):
    ans *= 2
  sum += ans
  
print(sum%(10**9+7))

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

ans = 0
m = 1
for i in range(60):
    bits = sum((a & m for a in A))
    bits //= m
    ans += (bits * (N - bits) * m)
    ans %= MOD
    m <<= 1
print(ans % MOD)

Solution (Python):
import numpy as np

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

mod = 10 ** 9 + 7

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

print(ans%mod)

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

ans = 0
for k in range(61):
    N1 = 0
    N1 = sum([1 for a in A if ( (a >> k) & 1)])
    ans += (((1<<k)) *(N-N1) *N1)
    ans %= M    

print(ans)

Solution (Python):

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


import numpy as np
dp = np.array(A) 

answer = 0
for i in range(60):
    a = np.count_nonzero(dp & 1)
    answer += 2**i*a*(N-a)
    dp >>= 1

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

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

k=[0]*60
K=[0]*60
for i in range(N):
  t=A[i]
  for j in range(60):
    if t%2==1:
      k[j]+=1
    t=t//2
    if t<1:
      break
a=1
sumxor=0
for i in range(60):
  K[i]=k[i]*(N-k[i])
  a=a%(10**9+7)
  sumxor=(sumxor+K[i]*a%(10**9+7))%(10**9+7)
  a=a*2
print(sumxor)

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

ctr = [0] * 60
for a in A:
    for i in range(60):
        if (a>>i) & 1:
            ctr[i] += 1

ans = 0
for d, num1 in enumerate(ctr):
    num0 = n - num1
    ans += num0 * num1 * 2**d
    ans %= MOD

print(ans)

Solution (Python):
import sys
input=sys.stdin.readline
import numpy as np
n=int(input())
a=np.array([int(j) for j in input().split()],dtype=np.int64)
ans=0
mod=10**9+7
for i in range(61):
    b=(a>>i)&1
    c=np.count_nonzero(b)
    ans+=(2**i)*c*(n-c)
    ans%=mod
print(ans)

Solution (Python):
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(len(bin(max(A))[2:])):
	a = (A>>i)&1
	a = np.count_nonzero(a)
	b = n-a
	a *= b
	a = a<<i%mod
	ans = (ans+a)%mod
print(ans)

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

mod = 10 ** 9 + 7
n = int(input())
a = list(map(lambda x: format(int(x), "b").zfill(60), input().split()))

ans = 0
for i in range(60):
    cnt = 0
    for j in a:
        if j[- i - 1] == "1":
            cnt += 1
    tmp = cnt * (n - cnt)
    for _ in range(i):
        tmp = tmp * 2 % mod
    ans += tmp
print(ans % mod)

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

mod = 10 ** 9 + 7
n = int(input())
a = list(map(lambda x: format(int(x), "b").zfill(60), input().split()))

ans = 0
for i in range(60):
    cnt = 0
    for j in a:
        if j[- i - 1] == "1":
            cnt += 1
    tmp = cnt * (n - cnt)
    for _ in range(i):
        tmp = tmp * 2 % mod
    ans += tmp
print(ans % mod)

Solution (Python):
MOD = 10**9+7

N   = int(input())
A   = list(map(int,input().split()))
A2   = [0]*N
BitNum = [0]*(61)

for i in range(1,61):
    A2 = [0] * N
    for j in range(N):
        A2[j] = A[j] % 2
        A[j] //= 2
    BitNum[i] = sum(A2)

ans = 0
beki = 0
for i in range(1,61):
    x = BitNum[i]
    y = N - x
    ans += (x*y)*(2**beki)
    ans %= MOD
    beki += 1
print(ans)

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

mod = 10**9 + 7
total = 0
for i in range(60):
  cnt = sum([1 for a in A if (a>>i & 1)])
  total += cnt * (n-cnt) * (1 << i)
  total %= mod
print(total)

Solution (Python):
from heapq import heappush, heappop, heapify
from collections import deque, defaultdict, Counter
import itertools
from itertools import permutations, combinations, accumulate
import sys
import bisect
import string
import math
import time
from fractions import gcd



def I(): return int(input())


def MI(): return map(int, input().split())


def LI(): return [int(i) for i in input().split()]


def LI_(): return [int(i)-1 for i in input().split()]


def StoI(): return [ord(i)-97 for i in input()]


def ItoS(nn): return chr(nn+97)


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


def show(*inp, end='\n'):
    if show_flg:
        print(*inp, end=end)


YN = ['No', 'Yes']
MOD = 10**9+7
inf = float('inf')
IINF = 10**10
l_alp = string.ascii_lowercase
u_alp = string.ascii_uppercase
ts = time.time()
sys.setrecursionlimit(10**6)
nums = ['1', '2', '3', '4', '5', '6', '7', '8', '9', '10']


show_flg = True
show_flg = False





def sumXOR(arr,  n):
    _sum = 0
    for i in range(0, 64):
        zc = 0
        oc = 0

        
        idsum = 0
        for j in range(0, n):
            if (arr[j] % 2 == 0):
                zc = zc + 1
            else:
                oc = oc + 1
            arr[j] = arr[j] >> 1

        
        idsum = oc * zc * (1 << i)
        print(zc, oc, idsum)

        
        _sum = _sum + idsum
        _sum %= MOD

    return _sum


def main():
    N = I()
    A = list(MI())
    BIT = 61
    C = [[0] * BIT for i in range(N+1)]
    pows = [pow(2, i, MOD) for i in range(BIT)]
    ans = 0

    for i in range(N):
        bit = 1
        for j in range(BIT):
            if A[i] & bit:
                C[i+1][j] = C[i][j] + 1
            else:
                C[i+1][j] = C[i][j]
            bit = bit << 1

    for i in range(N):
        bit = 1
        for j in range(BIT):
            oc = C[N][j] - C[i][j]
            
            if A[i] & bit:
                zc = N - i - oc
                ans += pows[j] * zc
            elif oc != 0:
                ans += pows[j] * oc
            ans %= MOD
            bit = bit << 1
            

    print(ans)


if __name__ == '__main__':
    main()

Solution (Python):




import sys








def I(): return int(input())


def MI(): return map(int, input().split())


def LI(): return [int(i) for i in input().split()]


def LI_(): return [int(i)-1 for i in input().split()]


def StoI(): return [ord(i)-97 for i in input()]


def ItoS(nn): return chr(nn+97)


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


def show(*inp, end='\n'):
    if show_flg:
        print(*inp, end=end)



MOD = 10**9+7










show_flg = False































def main():
    N = I()
    A = list(MI())
    BIT = 61
    C = [[0] * BIT for i in range(N+1)]
    pows = [pow(2, i, MOD) for i in range(BIT)]
    ans = 0

    for i in range(N):
        bit = 1
        for j in range(BIT):
            if A[i] & bit:
                C[i+1][j] = C[i][j] + 1
            else:
                C[i+1][j] = C[i][j]
            bit = bit << 1

    for i in range(N):
        bit = 1
        for j in range(BIT):
            oc = C[N][j] - C[i][j]
            
            if A[i] & bit:
                zc = N - i - oc
                ans += pows[j] * zc
            elif oc != 0:
                ans += pows[j] * oc
            ans %= MOD
            bit = bit << 1
            

    print(ans)


if __name__ == '__main__':
    main()

Solution (Python):
def sol():
    mod=1000000007
    ans=0
    n=int(input())
    a=[int(i) for i in input().split()]
    x=[[0]*61 for i in range(n+1)]
    l=[pow(2,i,mod) for i in range(61)]
 
    for i in range(n):
        d=a[i]
        cnt=0
        for j in range(61):
            if d&1:
                x[i+1][cnt]=x[i][cnt]+1
            else:
                x[i+1][cnt]=x[i][cnt]
            cnt+=1
            d=d>>1
 
    for i in range(1,n):
        for j in range(61):
            p=x[i][j]-x[i-1][j]
            if p:
                ans+=l[j]*((n-i)-(x[-1][j]-x[i][j]))
            else:
                ans+=l[j]*(x[-1][j]-x[i][j])
            ans%=mod
    print(ans)
 
if __name__=="__main__":
    sol()

Solution (Python):
inpl = lambda: list(map(int,input().split()))
MOD = 10**9+7
N = int(input())
A = inpl()
K = len(bin(max(A)))-2
unit = 1
ans = 0
for k in range(K):
    c = 0
    for n in range(N):
        c += A[n] % 2
        A[n] //= 2
    ans += c*(N-c)*unit
    ans %= MOD
    unit = unit * 2 % MOD
print(ans)

Solution (Python):
n = int(input())
x = list(map(int,input().split()))
mod = 10 ** 9 + 7
ans = 0
m = 1
for _ in range(60):
    bit = sum(a & m for a in x) 
    bit //= m 
    non_bit = n - bit 
    ans = (ans + bit * non_bit * m) % mod 
    m <<= 1 
print(ans)

Solution (Python):



def main():
    import numpy as np

    n = int(input())
    
    a = np.array([int(ai) for ai in input().split()])
    mod = 10 ** 9 + 7
    ans = 0

    
    
    
    
    

    
    
    
    for i in range(60):
        

        
        
        
        count = np.count_nonzero(a & 1)
        
        ans += (2 ** i) * (n - count) * count
        
        
        
        a >>= 1

    print(ans % mod)


if __name__ == '__main__':
    main()

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

    t = [0]*60

    for a in a_list:
        for count, i in enumerate(reversed(format(a, "b"))):
            if i == "1":
                t[count] += 1

    sum = 0
    for i, count in enumerate(t):
        sum += 2 ** i * count * (N - count)
    print(sum % mod)


if __name__ == '__main__':
    main()

Solution (Python):
MOD = 10**9 + 7

n = int(input())

A = list(map(int, input().split()))
A = [format(a, 'b').zfill(60) for a in A]

ans = 0
for i in range(60):
    lst = [a[i] for a in A]
    num_1 = lst.count('1')
    num_0 = lst.count('0')

    ans = (ans + (2**(59 - i) * (num_0 * num_1)) % MOD) % MOD

print(ans)

Solution (Python):
import numpy as np

n = int(input())
A = np.array([int(i) for i in input().split()])
ans = 0



for i in range(60):
    
    c = np.count_nonzero(A & 1) 
    
    
    ans += 2**i*c*(n-c) 
    
    A >>= 1 
print(ans%(10**9+7))

Solution (Python):



def main():
    import numpy as np

    n = int(input())
    a = np.array([int(ai) for ai in input().split()])
    mod = 10 ** 9 + 7
    ans = 0

    
    
    

    
    
    for i in range(60):
        count = np.count_nonzero(a & 1)
        ans += (2 ** i) * (n - count) * count
        a >>= 1

    print(ans % mod)


if __name__ == '__main__':
    main()

Solution (Python):
n=int(input())
a=[int(i) for i in input().split()]
amax=max(a)
m=len( bin(amax)[2:] )
bin_a = [bin(aa)[2:].zfill(m) for aa in a]

ans=0
mod=10**9+7
for i in range(m):
    sum0 = sum( bi[-1-i]=="0" for bi in bin_a )
    sum1 = n-sum0
    ans += sum0*sum1*2**i % mod
print(ans%mod)

Solution (Python):
import numpy as np

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

divider = 10**9+7

ans = 0
for shift in range(0, 60):
    one_num = np.count_nonzero(A & 1)
    ans += (2**shift)*one_num*(N-one_num)
    A >>= 1
print(ans%divider)

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

Solution (Python):
import sys


def solve():
    input = sys.stdin.readline
    mod = 10 ** 9 + 7
    n = int(input().rstrip('\n'))
    a = list(map(int, input().rstrip('\n').split()))
    ls = [0] * 65
    for i in range(65):
        for v in a:
            ls[i] += v >> i & 1
    t = 0
    for i in range(65):
        t += ls[i] * (n - ls[i]) * 2 ** i
        t %= mod
    print(t % mod)


if __name__ == '__main__':
    solve()

Solution (Python):
import numpy as np
MOD = 10**9 + 7
n = int(input())
A = np.array(list(map(int, input().split())))

answer = 0
for i in range(60):
    n_ones = np.count_nonzero(A & 1)
    answer += 2 ** i * (n - n_ones) * n_ones
    A >>= 1

print(answer % MOD)

Solution (Python):
mod = 10**9 + 7

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

B = [0] * 60
C = [0] * 60

for a in A:
    for j in range(60):
        if (a >> j) & 1:
            B[j] += 1
        else:
            C[j] += 1

ans = 0

for j in range(60):
    ans += (1 << j) * B[j] * C[j]

ans %= mod
print(ans)

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

Solution (Python):
MOD = 10 ** 9 + 7

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

res = 0

for k in range(60):
    cnt = [0, 0]
    for i in range(N):
        cnt[(A[i] >> k) & 1] += 1
    res = (res + cnt[0] * cnt[1] * pow(2, k)) % MOD

print(res)

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


N = int(input())
A = np.array([int(i) for i in input().split()])
maxA = max(A)

MOD = 10**9 + 7

answer = 0

i = 0
power_of_2 = 1
while maxA:
    B = (A >> i) & 1
    
    count1 = np.count_nonzero(B)
    
    count0 = N - count1
    
    count = count0 * count1
    answer = (answer + count * power_of_2) % MOD

    i += 1
    maxA >>= 1

    power_of_2 = (power_of_2 * 2) % MOD

print(answer)

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

Solution (Python):
import numpy as np
mod=10**9+7
n=int(input())
A=np.array(list(map(int,input().split())))

ans=0

for i in range(60):
    cnt=np.count_nonzero(A&1)
    ans +=2**i*cnt*(n-cnt)
    A >>=1

print(ans%mod)

Solution (Python):
import numpy as np

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

mod = 10 ** 9 + 7

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

print(ans%mod)

Solution (Python):
import sys
input=sys.stdin.readline
n=int(input())
mod=10**9+7
a=list(map(int,input().split()))
s=[0]*61
for i in range(n):
  c=format(a[i], 'b')
  L=len(c)
  for j in range(L)[::-1]:
    s[L-j-1]+=int(c[j])
ans=0
for i in range(61):
  ans+=2**(i)*(s[i])*(n-s[i])
  ans%=mod
print(ans)

Solution (Python):
N, *A = map(int, open(0).read().split())

MOD = 10 ** 9 + 7
ans = 0
for bit in range(60):
    ctr = [0, 0]
    for i in range(N):
        ctr[A[i] >> bit & 1] += 1
    ans += (1 << bit) * (ctr[0] * ctr[1])
    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(61):
    bit = 1 << i
    count = 0
    for j in range(N):
        if bit & A[j]:
            count += 1
    ans += 2**i * count * (N-count) % mod
print(ans % mod)

Solution (Python):
import math

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

ans = 0
fil = 1
for i in range(60):
    num1 = len([1 for j in range(N) if A[j] & fil])
    num0 = N - num1
    ans += (num1 * num0) * fil
    fil <<= 1

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

Solution (Python):
import numpy as np
N=int(input())
A=np.array(list(map(int,input().split())))
l=len(format(A.max(),'b'))
MOD=10**9+7

tei=1
ans=0
for i in range(l):
  B=(A >> i) & 1
  one=np.count_nonzero(B)
  zero=N-one
  ans+=tei*one*zero
  tei*=2
print(ans%MOD)

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

def main():
    N = int(input())
    vA = list(map(int, input().split()))
    MOD = 10**9 + 7
    BMAX = 61

    vC = [0,]*BMAX
    for a in vA:
        d = 0
        while a:
            vC[d] += a&1
            d += 1
            a >>= 1
    res = 0
    for i,c in enumerate(vC):
        x = pow(2,i) * c * (N-c) % MOD
        res = (res + x) % MOD
    print(res)


if __name__ == "__main__":
    main()

Solution (Python):
MOD = 10**9 + 7
n = int(input())
a = list(map(int, input().split()))
s = 0
m = 1
for i in range(60):
    c = sum(ai & m for ai in a)
    c //= m
    s = (s + m*c*(n-c))%MOD
    m <<= 1
print(s)

Solution (Python):
import numpy as np

n = int(input())
a = np.array([int(x) for x in input().split()])
inf = 10**9+7

ans = 0
p = 1
for i in range(61):
    a, b = a//2, a%2
    key = int(b.sum())
    ans += p*(n-key)*key
    ans = ans%inf
    p *= 2
    p %= inf
print(ans)

Solution (Python):
N = 60
MOD = 10**9 + 7
n = int(input())
c0 = [0 for _ in range(N)]
c1 = [0 for _ in range(N)]

a = list(map(int,input().split()))
for i in range(n):
    for j in range(N):
        if a[i] & (1 << j) == 0:
            c0[j] += 1
        else:
            c1[j] += 1

ans = 0
for i in range(n-1):
    for j in range(N):
        if a[i] & (1 << j) == 0:
            c0[j] -=1
        else:
            c1[j] -=1
    for j in range(N):
        if a[i] & (1 << j) == 0:
            ans += (1<<j) * c1[j]
        else:
            ans += (1<<j) * c0[j]

print(ans % MOD)

Solution (Python):
N = 60
MOD = 10**9 + 7
n = int(input())

c1 = [0 for _ in range(N)]

a = list(map(int,input().split()))
for i in range(n):
    for j in range(N):
        if a[i] & (1 << j) != 0:
            c1[j] += 1
        
        

ans = 0
for i in range(n-1):
    for j in range(N):
        if a[i] & (1 << j) != 0:
            c1[j] -=1
        
        
    for j in range(N):
        if a[i] & (1 << j) != 0:
            ans += (1<<j) * (n-i-1-c1[j])
        else:
            ans += (1<<j) * c1[j]
            

print(ans % MOD)

Solution (Python):
import sys
lines = sys.stdin.readlines()
n = int(lines[0])
arr = list(map(int, lines[1].split(' ')))

maxi = 62
mod = int(1e9) + 7
ones = [0 for _ in range(maxi)]
for num in arr:
    for idx, val in enumerate(range(maxi)):
        ones[idx] += (num >> idx ) & 1

ans = 0
for idx, val in enumerate(ones):
    ans += ((pow(2, idx) % mod) * (((n - val)%mod) * (val%mod))) % mod

    ans %= mod

print(ans)

Solution (Python):
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
N = int(readline())
A = list(map(int, readline().split()))
B1 = [0 for i in range(60)]
for x in A:
    bA = format(x,"b").zfill(60)
    for i in range(60):
        if bA[i] == "1":
            B1[i] += 1
ans = 0
for i,x in enumerate(B1):
    ans = (ans + 2**(59-i)*x*(N-x)) % (10**9+7)
print(ans)

Solution (Python):
mod = 10**9+7
n = int(input())
a = [ int(i) for i in input().split() ]
ans = 0
for i in range(60):
    zero = 0
    one = 0
    if (a[n-1] & (1<<i)) == 0:
        zero += 1
    else:
        one += 1

    for j in range(n-2,-1,-1):
        if (a[j] & (1<<i)) == 0:
            ans += one * (1<<i)
            ans %= mod
            zero += 1
        else:
            ans += zero * (1<<i)
            ans %= mod
            one += 1


print(ans)

Solution (Python):
def main():
    import sys
    input = sys.stdin.readline
    MAX = 10**9+7

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

    li = [0]*61
    for i in a:
        for j in range(61):
            li[j] += i&1
            i >>= 1
    ans = 0
    bit = 1
    for i in li:
        ans += bit * i * (n-i)
        bit <<= 1
    print(ans%MAX)

if __name__ == '__main__':
    main()

Solution (Python):
from collections import defaultdict
N = int(input())
A = list(map(int, input().split(' ')))
B1 = defaultdict(int)
B0 = defaultdict(int)
for x in A:
    bA = format(x,"b").zfill(60)
    for i in range(60):
        if bA[i] == "1":
            B1[i] += 1
        elif bA[i] == "0":
            B0[i] += 1
ans = 0
for i in range(60):
    ans = (ans + 2**(59-i)*B1[i]*B0[i]) % (10**9+7)
print(ans)

Solution (Python):
N = int(input())
A = list(map(int, input().split(' ')))
B1 = [0 for i in range(60)]
B0 = [0 for i in range(60)]
for x in A:
    bA = format(x,"b").zfill(60)
    for i in range(60):
        if bA[i] == "1":
            B1[i] += 1
        elif bA[i] == "0":
            B0[i] += 1
ans = 0
for i in range(60):
    ans = (ans + 2**(59-i)*B1[i]*B0[i]) % (10**9+7)
print(ans)

Solution (Python):
f = [0 for i in range(64)]
n = int(input())
mod = int(1e9+7)
x = map(int, input().split())
for i in range(n):
    for num in x:
        for j in range(61):
            if num & (1<<j) != 0:
                f[j] += 1
ans = 0
for i in range(64):
    cur = (1<<i) % mod
    ans += cur * (f[i]) * (n-f[i])
    ans = ans % mod
print(int(ans))

Solution (Python):
mod=int(1e9)+7

n=int(input())
a=[int(i) for i in input().split()]
ans=0
for b in range(60)[::-1]:
  ans<<=1
  c=sum(a[i]>>b & 1 for i in range(n))
  ans = (ans + c*(n-c)) % mod
print(ans)

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

INF = 10 ** 9 + 7
N = int(input())
a = list(map(int, input().split()))
cnt = [0] * 60
for i in a:
    for j in range(60):
        tmp = i >> j
        if tmp != 0:
            cnt[j] += tmp % 2
        else:
            break
ans = 0
for b in range(60):
    ans += cnt[b] * (N - cnt[b]) << b
    ans %= INF
print(ans)

Solution (Python):
import numpy as np
 
MOD = 10 ** 9 + 7
 
N = int(input())
A = np.array(list(map(int, input().split())),np.int64)
 
answer = 0
for n in range(63):
    B = (A >> n) & 1
    x = np.count_nonzero(B)
    y = N - x
    x *= y
    for _ in range(n):
        x *= 2
        x %= MOD
    answer += x
answer %= MOD
print(answer)

Solution (Python):
from collections import defaultdict

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

max_A = max(A)
j = 0
while max_A >> j > 0:
    j += 1
max_j = j

ans = 0
MOD = 10 ** 9 + 7
for j in range(max_j):
    c = [0] * 2
    for i in range(N):
        c[A[i] >> j & 1] += 1
    ans += c[0] * c[1] * (1 << j)
    ans %= MOD
print(ans)

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

INF = 10 ** 9 + 7
N = int(input())
a = list(map(int, input().split()))
cnt = [0] * 60
for i in a:
    for j in range(60):
        cnt[j] += (i >> j) % 2
ans = 0
for b in range(60):
    ans += cnt[b] * (N - cnt[b]) << b
    ans %= INF
print(ans)

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

    r = list(range(N - 2, -1, -1))
    result = 0
    for b in range(60):
        t = 0
        bs = (A[N - 1] >> b) & 1
        for i in r:
            if (A[i] >> b) & 1 == 0:
                t += bs
            else:
                t += (N - (i + 1)) - bs
                bs += 1
        result = (result + t * (1 << b)) % 1000000007
    print(result)
main()

Solution (Python):
def sol():
    mod=1000000007
    ans=0
    n=int(input())
    a=[int(i) for i in input().split()]
    x=[[0]*61 for i in range(n+1)]
    l=[pow(2,i,mod) for i in range(61)]

    for i in range(n):
        d=a[i]
        cnt=0
        for j in range(61):
            if d&1:
                x[i+1][cnt]=x[i][cnt]+1
            else:
                x[i+1][cnt]=x[i][cnt]
            cnt+=1
            d=d>>1

    for i in range(1,n):
        for j in range(61):
            p=x[i][j]-x[i-1][j]
            if p:
                ans+=l[j]*((n-i)-(x[-1][j]-x[i][j]))
            else:
                ans+=l[j]*(x[-1][j]-x[i][j])
            ans%=mod
    print(ans)

if __name__=="__main__":
    sol()

Solution (Python):
def sol():
    mod=1000000007
    ans=0
    n=int(input())
    a=[int(i) for i in input().split()]
    x=[[0]*63 for i in range(n+1)]
    
    l=[pow(2,i,mod) for i in range(63)]

    for i in range(n):
        d=a[i]
        cnt=0
        for j in range(63):
            if d&1:
                x[i+1][cnt]=x[i][cnt]+1
            else:
                x[i+1][cnt]=x[i][cnt]
            cnt+=1
            d=d>>1

    for i in range(1,n):
        for j in range(63):
            p=x[i][j]-x[i-1][j]
            if p:
                ans+=l[j]*((n-i)-(x[-1][j]-x[i][j]))
            else:
                ans+=l[j]*(x[-1][j]-x[i][j])
            ans%=mod
    print(ans)

if __name__=="__main__":
    sol()

Solution (Python):
import numpy as np
N = int(input())
A = np.array([int(_) for _ in input().split()], dtype=np.int64)
mod = 10**9 + 7
ans = 0
for b in range(60):
    B = (A >> b) & 1
    M = np.count_nonzero(B)
    ans += 2**b * M * (N - M)
    ans %= mod
print(ans)

Solution (Python):
def sol():
    mod=1000000007
    ans=0
    n=int(input())
    a=[int(i) for i in input().split()]
    x=[[0]*63 for i in range(n+1)]
    l=[(2**i)%mod for i in range(63)]

    for i in range(n):
        d=a[i]
        cnt=0
        for j in range(63):
            if d&1:
                x[i+1][cnt]=x[i][cnt]+1
            else:
                x[i+1][cnt]=x[i][cnt]
            cnt+=1
            d=d>>1

    for i in range(1,n):
        for j in range(63):
            p=x[i][j]-x[i-1][j]
            if p:
                ans+=l[j]*((n-i)-(x[-1][j]-x[i][j]))
            else:
                ans+=l[j]*(x[-1][j]-x[i][j])
            ans%=mod
    print(ans)

if __name__=="__main__":
    sol()

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

ans = 0
 
MOD = (10**9+7)
for i in range(62):
    c = 0
    for ai in a:
        if ai&(1<<i): c += 1
    
    r = c*(n-c)
    ans += (1<<i)*r
    ans %= MOD
 
 
print(ans)

Solution (Python):
mod=1000000007
ans=0
n=int(input())
a=[int(i) for i in input().split()]
x=[[0]*63 for i in range(n+1)]
l=[(2**i)%mod for i in range(63)]

for i in range(n):
    d=a[i]
    cnt=0
    for j in range(63):
        if d&1:
            x[i+1][cnt]=x[i][cnt]+1
        else:
            x[i+1][cnt]=x[i][cnt]
        cnt+=1
        d=d>>1

for i in range(1,n):
    for j in range(63):
        p=x[i][j]-x[i-1][j]
        if p:
            ans+=l[j]*((n-i)-(x[-1][j]-x[i][j]))
        else:
            ans+=l[j]*(x[-1][j]-x[i][j])
        ans%=mod
print(ans)

Solution (Python):
import sys
input = sys.stdin.readline
 
N=int(input())
An = list(map(int,input().split()))
MOD = 10**9+7

ans=0
for i in range(60):
  ones,zeros=0,0
  for A in An:
    if (A>>i)%2 == 1:
      ones+=1
    else:
      zeros+=1
  ans+=2**i * ones * zeros
  ans%=MOD

print(ans)