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):
import numpy as np
import sys
input = sys.stdin.readline

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

A = np.array(A,np.int64)

mod = 10**9 + 7

res = 0

for i in range(60):
    count = np.count_nonzero(A & 1)
    res += (N - count) * count * 2 ** i
    res %= mod
    A >>= 1

print(res)

Solution (Python):
N = int(input())

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

ones = [0] * 60
m = 10 ** 9 + 7

for Ai in A:
    for digit in range(len(bin(Ai)) - 2):
        ones[digit] += ((Ai >> digit) & 1)

res = 0
for i, num in enumerate(ones):
    res += (1 << i) * num * (N - num)

print(res % m)

Solution (Python):

from collections import defaultdict,deque
from heapq import heappush, heappop
from bisect import bisect_left, bisect_right
import sys, random, itertools, math
sys.setrecursionlimit(10**5)
input = sys.stdin.readline
sqrt = math.sqrt
def LI(): return list(map(int, input().split()))
def LF(): return list(map(float, input().split()))
def LI_(): return list(map(lambda x: int(x)-1, input().split()))
def II(): return int(input())
def IF(): return float(input())
def LS(): return list(map(list, input().split()))
def S(): return list(input().rstrip())
def IR(n): return [II() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def FR(n): return [IF() for _ in range(n)]
def LFR(n): return [LI() for _ in range(n)]
def LIR_(n): return [LI_() for _ in range(n)]
def SR(n): return [S() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
mod = 1000000007
inf = float('INF')


def solve():
    n = II()
    a = LI()
    maxa = max(a)
    bitmax = len(bin(maxa)) - 2
    ans = 0
    for i in range(bitmax):
        zero_num = 0
        one_num = 0
        for ai in a:
            if ai & (1 << i):
                one_num += 1
            else:
                zero_num += 1
        ans += (one_num * zero_num * (1 << i)) % mod
        ans %= mod
    print(ans)

    return



if __name__ == '__main__':
    solve()

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

import numpy as np

MOD = 10 ** 9 + 7

N = int(readline())
A = np.array(read().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):

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

if __name__ == '__main__':
    main()

Solution (Python):
import numpy as np

n=int(input())



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


max=60
mod=10**9+7
ans=0
cnt1=0
cnt0=0


for i in range(max):
    new_a=(a>>i & 1)

    cnt1=np.count_nonzero(new_a)
    cnt0=n-cnt1
    ans=(ans+cnt1*cnt0*(2**i))%mod
    cnt1=0
    cnt0=0
print(ans)

Solution (Python):
N=int(input())
bin_a="".join(["{:060b}".format(a) for a in map(int, input().split())])
mod=10**9+7
xor=0
for d in range(60):
  ones=bin_a[59-d::60].count('1')
  xor+=2**d*ones*(N-ones)    
print(xor%mod)

Solution (Python):
N = int(input())

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

num = [[0, 0] for _ in range(60)]

for Ai in A:
    for digit in range(60):
        if (Ai >> digit) & 1:
            num[digit][1] += 1
        else:
            num[digit][0] += 1

res = 0
for i, p in enumerate(num):
    res += (1 << i) * p[0] * p[1]

m = 10 ** 9 + 7
print(res % m)

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


def main():
    N = int(input())
    A = list(map(int, input().split()))
    B = [0]*60
    for a in A:
        for i in range(len(B)):
            if (a >> i) & 1:
                B[i] += 1
    ans = 0
    for i, b in enumerate(B):
        ans += 2**i * b * (N-b)
        ans %= 10**9+7
    print(ans)


if __name__ == '__main__':
    main()

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


def read_ints():
    return list(map(int, read().split()))


def read_a_int():
    return int(read())


def read_matrix(H):
    '''
    H is number of rows
    '''
    return [list(map(int, read().split())) for _ in range(H)]


def read_map(H):
    '''
    H is number of rows
    文字列で与えられた盤面を読み取る用
    '''
    return [read()[:-1] for _ in range(H)]


def read_col(H, n_cols):
    '''
    H is number of rows
    n_cols is number of cols

    A列、B列が与えられるようなとき
    '''
    ret = [[] for _ in range(n_cols)]
    for _ in range(H):
        tmp = list(map(int, read().split()))
        for col in range(n_cols):
            ret[col].append(tmp[col])

    return ret


n = 60
N = read_a_int()
A = read_ints()


def ret_binary(a: int):  
    ret_r = [0] * n
    for i in range(n):
        bit = a % 2
        a = a // 2
        ret_r[i] = bit
    return ret_r


MOD = 10**9 + 7

n_1_max = 0
n_1_ls = [0] * n
ans = 0
for a in A:
    tmp = ret_binary(a)
    for i in range(n):
        n_1_ls[i] += tmp[i]


for i, n_1 in enumerate(n_1_ls):
    num_sonoketa = n_1 * (N - n_1)
    ans += (((2**i) % MOD) * num_sonoketa)
    ans %= MOD
print(ans)

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


def main():
    N = int(input())
    A = list(map(int, input().split()))
    B = [0]*60
    for a in A:
        for i in range(len(B)):
            if (a >> i) & 1:
                B[i] += 1
    ans = 0
    for i, b in enumerate(B):
        ans += 2**i * b * (N-b)
    ans %= 10**9+7
    print(ans)


if __name__ == '__main__':
    main()

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


def main():
    N = int(input())
    A = list(map(int, input().split()))
    B = [0]*60
    for a in A:
        for i in range(len(B)):
            if a & (2**i):
                B[i] += 1
    ans = 0
    for i, b in enumerate(B):
        ans += 2**i * b * (N-b)
    ans %= 10**9+7
    print(ans)


if __name__ == '__main__':
    main()

Solution (Python):

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

P = 10**9+7
bit = [0 for i in range(60)]


for a in A:
    S = bin(a)
    for j in range(1,len(S)-1):
        if S[-1*j] == '1':
            bit[j-1] += 1


ans = 0
for i,a in enumerate(bit):
    ans += a*(N-a)*(2**i)
    ans %= P

print(ans)

Solution (Python):
def main():
    import sys

    input = sys.stdin.readline

    mod = 10 ** 9 + 7

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

    ret = 0
    for j in range(60):
        cnt1 = sum((x >> j) & 1 for x in a)
        cnt0 = n - cnt1
        ret = (ret + cnt0 * cnt1 * (1 << j)) % mod

    print(ret)


if __name__ == '__main__':
    main()

Solution (Python):
def main():
  N = int(input())
  A = list(map(int, input().split()))
  MOD = 10 ** 9 + 7
  ones = [sum(1 for a in A if a&(1<<i)) for i in range(60)]
  res = 0
  for i in range(60):
    res += ones[i] * (N - ones[i]) * ((2 ** i) % MOD)
    res %= MOD
  print(res)
if __name__ == "__main__":
    main()

Solution (Python):
N = int(input())
L = [0 for i in range(60)]
As = list(map(int, input().split()))
mod = 1000000007
ans = 0

for A in As:
    for i in range(60):
        if A >> i & 1 == 1:
            L[i] += 1

acc = 1
tmps = []
for i in range(60):
    tmps.append(acc)
    acc = acc * 2 % mod

for i in range(60):
    tmp = tmps[i]
    a = L[i] % mod
    b = (N - a) % mod
    ans += (tmp * a * b) % mod

ans = ans % mod
print(ans)

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 = 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] // 2

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

        
        _sum = _sum + idsum
        _sum %= MOD

    return _sum


def main():
    N = I()
    A = list(MI())
    print(sumXOR(A, len(A)))


if __name__ == '__main__':
    main()

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




MOD = (10**9) +7
result = 0

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)

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

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

A=[bin(i)[2:] for i in A]

nowdata=[0 for i in range(60)]
data=[0 for i in range(60)]



for i in range(N-1):
    S=A[i]

    for a in range(len(S)):
        if S[-a-1]=="1":
            nowdata[a]+=1
    S=A[i+1]
    for a in range(len(S)):
        if S[-a-1]=="0":
            data[a]+=nowdata[a]
        else:
            data[a]+=i+1-nowdata[a]
    


num=0

for i in range(60):
    num+=data[i]* (2**i)
    num%=mod

print(num)

Solution (Python):
n  = int(input())
m  = 10 ** 9 + 7
xs = [int(x) for x in input().split()]
bs = [0] * 60
b  = 1

for x in xs:
	e = 0
	
	while 0 < x:
		if x % 2 == 1:
			bs[e] += 1
			
		e  += 1
		x //= 2

b = 1
r = 0

for i in range(0, 60):
	r  += ((n - bs[i]) * bs[i]) * b
	b <<= 1
	
print(r % m)

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

d = [0 for k in range(61)]

for e in A:
    t = bin(e)[2:]
    for k in range(len(t)):
        if t[-k-1] == "1":
            d[k] += 1

MOD = 10**9 + 7
ans = 0
for k in range(61):
    ans += (2**k)*d[k]*(N-d[k])
    ans %= MOD
print(ans)

Solution (Python):
import sys
import bisect
from math import ceil, floor, sqrt
readline = sys.stdin.buffer.readline
MOD = int(1e9 + 7)

def LL():
    return list(map(int, readline().split()))

n = int(readline())
A = LL()

counter = [0] * 60
ans = 0
for i in range(60):
    for v in A:
        counter[i] += (v >> i) & 1
    ans += pow(2, i, MOD) * (n - counter[i]) * counter[i]
    ans %= MOD
print(ans)

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

from collections import defaultdict

cnt = defaultdict(int)

for i in range(N):
    for j in range(61):
        if a_list[i] & (1 << j):
            cnt[j] += 1


ans = 0
mod = 10 ** 9 + 7

for i in range(61):
    ans += cnt[i] * (N - cnt[i]) * (1 << i)
    ans %= mod
print(ans)

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

N = int(input())
A = list(map(int,input().split()))
X = [0]*60
sumA = 0
for i in A:
    for j in range(60):
        if i >> j & 1 == 1:
            X[j] += 1
    sumA += i
ans = 0
for i in range(N):
    sumA -= A[i]
    ans += sumA
    for j in range(60):
        if A[i] >> j & 1 == 1:
            X[j] -= 1
            ans += ((2**j) * (N-i-1-X[j]*2))%MOD
    ans %= MOD

print(ans)

Solution (Python):
N = int(input())
A = list(map(int, input().split()))
MOD = 10 **9 + 7
 
ni = [0 for _ in range(60)]
for i in range(N):
    tmp = A[i]
    count = 0
    while(True):
        if tmp % 2 == 1:
            ni[count] += 1
        count += 1
        tmp = tmp // 2
        if tmp == 0:
            break
ans = 0
for j in range(60):
    ans += (ni[j] * (N-ni[j])) * 2 ** j 
 
print(ans%MOD)

Solution (Python):

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

ans = 0
P = 10**9+7
bit = [0 for i in range(70)]


for i in range(N):
    S = bin(A[i])
    for j in range(1,len(S)-1):
        if S[-1*j] == '1':
            bit[j-1] += 1


for i in range(70):
    ans += (2**i)*bit[i]*(N-bit[i])
    ans %= P

print(ans)

Solution (Python):
def main():
    n = int(input())
    a = list(map(int, input().split()))
    maxa = max(a)
    k = 0
    while 2 ** k <= maxa:
        k += 1
    mod = 10 ** 9 + 7
    mo2 = [1]
    for _ in range(k):
        mo2.append(mo2[-1] * 2)

    p = [[0, 0] for i in range(k)]
    for sa in a:
        for j in range(k):
            if mo2[j] & sa != 0:
                p[j][1] += 1
            else:
                p[j][0] += 1
    res = 0
    for i in range(k):
        res += (p[i][0] * p[i][1] * mo2[i]) % mod
    print(res % mod)


main()

Solution (Python):
mod = 10 ** 9 + 7
fac = [1]
caf = [1]


def pow(n, p):
    res = 1
    while p > 0:
        if p % 2 == 0:
            n = n ** 2 % mod
            p //= 2
        else:
            res = res * n % mod
            p -= 1
    return res % mod


for i in range(1, 3):
    fac.append((fac[i - 1] * i) % mod)
    caf.append(pow(fac[i], mod - 2))


def main():
    n = int(input())
    a = list(map(int, input().split()))
    maxa = max(a)
    k = 0
    while 2 ** k <= maxa:
        k += 1
    mod = 10 ** 9 + 7
    mo2 = [1]
    for _ in range(k):
        mo2.append(mo2[-1] * 2)

    p = [[0, 0] for i in range(k)]
    for sa in a:
        for j in range(k):
            if mo2[j] & sa != 0:
                p[j][1] += 1
            else:
                p[j][0] += 1
    res = 0
    for i in range(k):
        res += (p[i][0] * p[i][1] * mo2[i]) % mod
    print(res % mod)


main()

Solution (Python):
import sys
input = sys.stdin.readline
N = int(input())
a = list(map(int, input().split()))
mod = 10 ** 9 + 7
mxbit = 0
for i in range(N):
  mxbit = max(mxbit, a[i].bit_length())
cs = [0] * mxbit
for i in range(N):
  for j in range(mxbit):
    t = 1 << j
    
    x = (a[i] & t) > 0
    cs[j] += x
res = 0


for i in range(N):
  t = 0
  for j in range(mxbit):
    x = 1 << j
    if a[i] & x != 0:
      x %= mod
      
      t += x * (N - (cs[j]))
    else:
      x %= mod
      
      t += x * cs[j]
    
    t %= mod
  res += t
  res %= mod
print(res % mod * pow(2, mod - 2, mod) % mod)

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

Solution (Python):
import sys
n = int(input())
a_ls = [bin(int(i))[2:].zfill(60)[::-1] for i in sys.stdin.readline().split()]
MOD = 10**9 + 7

memo_ls = [[0 for j in range(60)] for i in range(n+1)]
ct = {i : 0 for i in range(60)}
for i, a in enumerate(a_ls[::-1], 1):
    for j, k in enumerate(a):
        if k == "1":
            ct[j] += 1

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

Solution (Python):
N = int(input())
A = list(map(int, input().split()))
mod = 10**9 + 7
cnt = [[0,0] for i in range(61)]
for i in range(61):
    for j in range(N):
        if ((A[j] >> i) & 1):
            cnt[i][1] += 1
        else:
            cnt[i][0] += 1

ans = 0
for i in range(61):
    ans += (cnt[i][0] * cnt[i][1]) * (2**i)
    ans %= mod
print(ans)

Solution (Python):
N=int(input())
bin_a="".join(["{:060b}".format(a) for a in map(int, input().split())])
mod=10**9+7
xor=0
for d in range(60):
  ones=bin_a[59-d::60].count('1')
  xor+=2**d*ones*(N-ones)    
print(xor%mod)

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

import numpy as np

MOD = 10 ** 9 + 7

N = int(readline())
A = np.array(read().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):
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)

MOD = 10**9+7
N = int(input())
A = list(map(int, input().split()))
B = [0]*60
C = [0]*60

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

ans = 0
for i in range(60):
    ans += B[i]*C[i]*2**i%MOD
print(ans%MOD)

Solution (Python):
import numpy as np

mod = 10 ** 9 + 7

N = int(input())
 
AList = np.array(input().split(), dtype=np.int64)
count = 0
for i in range(60):
    Plus = np.count_nonzero(AList >> i & 1)
    count += 2 ** i * (Plus * (N - Plus))
print(count % mod)

Solution (Python):
import sys
inputs = sys.stdin.readlines()

n = int(inputs[0])
A = list(map(int, inputs[1].split()))
MOD = 10 ** 9 + 7

bit = len(format(max(A), 'b'))
ans = 0
for i in range(bit):
    nb_1 = sum(((a >> i) & 1 for a in A))
    ans += (nb_1 * (n - nb_1)) << i
    ans %= MOD
    
print(ans)

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


def main():
    N = int(input())
    A = list(map(int, input().split()))
    B = [0]*60
    for a in A:
        for i in range(len(B)):
            if a & (2**i):
                B[i] += 1
    ans = 0
    for i, b in enumerate(B):
        ans += 2**i * b * (N-b)
        ans %= 10**9+7
    print(ans)


if __name__ == '__main__':
    main()

Solution (Python):
n=int(input())
a=list(map(int,input().split()))
mod=10**9+7
ct0=[0]*64
ct1=[0]*64
for i in range(n):
  x=format(a[i],'0'+str(64)+'b')
  for j in range(64):
    if x[j]=='0':
      ct0[j]+=1
    else:
      ct1[j]+=1
ct0.reverse()
ct1.reverse()
ans=0
for i in range(64):
  x=(ct0[i]*ct1[i])%mod
  ans+=x*(2**i)
  ans%=mod
print(ans)

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

bits = [0] * 60
p = 10**9 + 7

for b in range(60):
  x = 1 << b
  for i in range(N):
    if A[i] & x:
      bits[b] += 1

ans = 0
for b in range(60):
  ans += (bits[b] * (N - bits[b])) * (1 << b)
  ans %= p

print(ans)

Solution (Python):
import sys
def input():
    return sys.stdin.readline()[:-1]

N = int(input())
l = list(map(int, input().split()))
u = 10**9+7
M = 61
ANS = 0

for i in range(M):
    d = 1 << i
    zero = 0
    for j in range(N):
        k = l[j]
        if (k & d)==0:
            zero += 1
    ANS += zero*(N-zero)*(2**i)
    ANS %= u
print(ANS)

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

n = int(input())
a = list(map(int, 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):
MOD = 10**9+7
N = int(input())
A = list(map(int, input().split()))
s = 0
n = len(bin(max(A))[2:])
for i in range(n):
  b = 1<<i
  N_t = sum([1 for Ai in A if (b&Ai)>0])
  N_f = N-N_t
  s += (1<<i) * N_t * N_f
print(s%MOD)

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

Solution (Python):
import sys

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


if __name__ == '__main__':
    solve()

Solution (Python):
n = int(input())
arrayOfNumber = list(map(int, input().split()))
MOD = 10**9+7
 
res = 0
for dig in range(61):
    one = 0
    for i in arrayOfNumber:
        if i & (1<<dig) != 0:
            one += 1
    res = (res + one*(n-one)*(1<<dig))%MOD
print(res)

Solution (Python):

import sys
import numpy as np

MOD = 1000000007  

def solve(N: int, A: "List[int]"):
    mLEN = len(format(max(A),'b'))

    A = np.array(A)
    ans = 0
    d = 1
    while d < (1 << mLEN):
        cnt = np.count_nonzero(A & d)
        ans += (N - cnt) * cnt * d
        ans %= MOD
        d <<= 1
    print(ans)
    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
mod = 10 ** 9 + 7

n = int(input())
x = np.array([int(a) for a in input().split()])

answer = 0
for d in range(61):
    x, r = x // 2, x % 2
    s = int(r.sum())
    b = (2 ** d) % mod
    answer += (b * s * (n - s)) % mod
print(answer%mod)

Solution (Python):
import sys
from pprint import pprint

mod = 10**9 + 7
def solve(n, a):

    zero_count = [0] * 60
    for a_i in a:
        for j in range(60):
            if a_i >> j & 1:
                zero_count[j] += 1

    ans = 0
    for i, count in enumerate(zero_count):
        
        ans += pow(2, i, mod) * (count % mod) * ((n - count) % mod) 
        ans %= mod
    print(ans)

if __name__ == '__main__':
    n = int(sys.stdin.readline().strip())
    a = map(int, sys.stdin.readline().strip().split(" "))
    
    solve(n, a)

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

res = 0
for dig in range(61):
    one = 0
    for i in a:
        if i & (1<<dig) != 0:
            one += 1
    res = (res + one*(n-one)*(1<<dig))%MOD
print(res)

Solution (Python):
import sys
from pprint import pprint

mod = 10**9 + 7
def solve(n, a):

    zero_count = [0] * 60
    for a_i in a:
        for j in range(61):
            if a_i >> j & 1:
                zero_count[j] += 1

    ans = 0
    for i, count in enumerate(zero_count):
        
        ans += pow(2, i, mod) * (count % mod) * ((n - count) % mod) 
        ans %= mod
    print(ans)

if __name__ == '__main__':
    n = int(sys.stdin.readline().strip())
    a = map(int, sys.stdin.readline().strip().split(" "))
    
    solve(n, a)

Solution (Python):

mod = 10**9 + 7


def main():
    n = int(input())
    A = [int(a) for a in input().split()]
    ans = 0
    for k in range(60):
        a = 0
        for i in range(n):
            a += A[i] & 1
            A[i] >>= 1
        da = (1 << k) % mod
        da *= (n - a)*a
        da %= mod
        ans += da
        ans %= mod
    print(ans)


main()

Solution (Python):
N = int(input())
A = [int(i) for i in input().split()]
mod = 10**9 + 7

ans = 0
for b in range(60):
    c = 0
    for a in A:
        if (a >> b) & 1:
            c += 1
    ans += 2**b*c*(N-c)
    ans %= mod
print(ans)

Solution (Python):
import numpy as np

N = int(input())
A = list(map(int, input().split()))
A = np.array(A, dtype=np.int64)
ans = 0
mod = 10**9+7
i = 1
while i < (1 << 60):
    count = np.count_nonzero(A & i)
    ans += count * (N-count) * i
    ans %= mod
    i <<= 1
print(ans)

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


mod = 10**9 + 7

ans = 0
for i in range(61):
    zero = 0
    one = 0
    for a_ in a:
        if (a_ >> i) & 1:
            one += 1
        else:
            zero += 1
    ans += one * zero * pow(2, i, mod) % mod
    ans %= mod

print(ans)

Solution (Python):

def sumXOR(arr,n): 
      
    sum = 0
    for i in range(0, 65): 
    
        
        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] // 2
          
           
        
        idsum = oc * zc * (1 << i) 
    
        
        sum = sum + idsum;  
      
    return sum%(1000000007)
  
  
  

sum = 0
n = int(input())
arr = list(map(int,input().split()))
arr.sort()
sum = sumXOR(arr, n); 
print (sum)

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

def sumXOR(arr, n, MOD):
    s = 0
    for i in range(0, 62):
        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] //= 2
        idsum = oc * zc * (1 << i)
        idsum %= MOD
        s = s + idsum
        s %= MOD
    return s

print (sumXOR(A, N, 10**9 + 7))

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

if __name__ == "__main__":
	N = int(input())
	L = list(map(int, input().split()))
	L = np.array(L, np.int64)
	ans = 0
	for i in range(60):
		bit = np.count_nonzero(L & 1)
		ans += bit * (N - bit) * (2 ** i)
		ans %= mod
		L >>= 1
	print(ans % mod)

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

result = 0
base = 1
for _ in range(max_digit + 1):
  a = A % 2
  c = np.count_nonzero(a == 0)
  result = (result + (base*(N - c)*c) % mod) % mod
  A = A >> 1
  base *= 2

print(result)

Solution (Python):

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

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

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

N=int(input())
A=list(map(int,input().split()))
A=[bin(i)[2:] for i in A]
A=[(60-len(i)) * "0" + i for i in A]

nowdata=[0 for i in range(60)]
data=[0 for i in range(60)]



for i in range(N-1):
    S=A[i]
    
    for a in range(len(S)):
        if S[a]=="1":
            nowdata[a]+=1
    S=A[i+1]
    for a in range(len(S)):
        if S[a]=="0":
            data[a]+=nowdata[a]
        else:
            data[a]+=i+1-nowdata[a]


num=0

for i in range(60):
    num+=data[-i-1]* (2**i)
    num%=mod

print(num)

Solution (Python):
MOD = 1000000007
N = int(input())
A = list(map(int,input().split()))
xorsum = 0
for i in range(64):
    zc = 0
    oc = 0
    for j in range(N):
        if A[j]%2 == 0:
            zc += 1
        else:
            oc += 1
        A[j] //= 2
    xorsum += oc*zc*(2**i)
    xorsum %= MOD
print(xorsum%MOD)

Solution (Python):
import sys
import numpy as np

read = sys.stdin.read

N, *A = map(int, read().split())
a = np.array(A, np.int64)
mod = 10 ** 9 + 7
answer = 0
for i in range(60):
    bit = np.count_nonzero(a & 1)
    answer += 2 ** i * bit * (N - bit)
    answer %= mod
    a >>= 1

print(answer)

Solution (Python):
N = int(input())
import collections
d = collections.Counter()
MOD = int(1e9 + 7)

max_i = 0
for a in map(int, input().split()):
  inv_bin = bin(a)[2:][::-1]
  for i, b in enumerate(inv_bin):
    if (b == '1'):
      d[i] += 1
  max_i = max(i, max_i)

ans = 0
for k, v in d.items():
  ans += (N - v) * v * (2 ** k) 
  ans %= MOD
print(ans)

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

def sumXOR(arr, n, MOD):
    ret = 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] //= 2
        idsum = oc * zc * (1 << i)
        ret += idsum
        ret %= MOD
    return ret

print(sumXOR(A, N, 10**9 + 7))

Solution (Python):

MOD = 10**9 + 7
n = int(input())
a = list(map(int, 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 bisect
N = int(input())
An = list(map(int,input().split(' '))) 

bit_list = [1]
for i in range(100000):
    bit_list.append(bit_list[i]*2)
    if bit_list[i+1] > 2**60:
        break
start_point = bisect.bisect_right(bit_list,max(An))
keta_list = [0] *  start_point

for A in An:
    abin = format(A, 'b')
    for i in range(len(abin)):
        if abin[i] == '1':
            keta_list[len(abin)-1-i] += 1
count = 0
for idx,keta_count in enumerate(keta_list):
    count += (N-keta_count) * bit_list[idx] * keta_count
    count = count % (1000000000+7)
print(count)

Solution (Python):
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians, atan, degrees
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
from bisect import bisect

def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

def main():
	N = INT()
	A = LIST()

	upper_len = len("{:b}".format(max(A)))

	cnt = [defaultdict(int) for _ in range(upper_len)]
	for i in range(N):
		num = "{:b}".format(A[i]).zfill(upper_len)
		for j in range(len(num)):
			cnt[upper_len-j-1][num[j]] += 1

	ans = 0
	for i in range(upper_len):
		ans = (ans + (1<<i)*cnt[i]["0"]*cnt[i]["1"])%mod
	print(ans)

if __name__ == "__main__":
	main()

Solution (Python):
import sys
from pprint import pprint

mod = 10**9 + 7

def pow_r(x, n):
    """
    O(log n)
    """
    if n == 0:  
        return 1
    if n % 2 == 0:
        return pow_r(x ** 2, n // 2) % mod
    else:
        return (x * pow_r(x ** 2, (n - 1) // 2)) % mod


def solve(n, a):

    zero_count = [0] * 60
    for a_i in a:
        
        
        
        for j in range(61):
            if a_i >> j & 1:
                zero_count[j] += 1

    ans = 0
    
    for i, count in enumerate(zero_count):
        
        ans += pow_r(2, i) * (count % mod) * ((n - count) % mod) 
        ans %= mod
    print(ans)

if __name__ == '__main__':
    n = int(sys.stdin.readline().strip())
    a = map(int, sys.stdin.readline().strip().split(" "))
    
    solve(n, a)

Solution (Python):
import sys

sys.setrecursionlimit(10**7)
MOD = 10 ** 9 + 7
def LI(): return list(map(int, sys.stdin.readline().split()))
def II(): return int(sys.stdin.readline())

def main():
    n = II()
    a_s = LI()
    kaizyo = [1]
    kaizyo_append = kaizyo.append
    keta = [0 for i in range(60)]
    ans = 0
    for i in range(60):
        kaizyo_append(kaizyo[i] * 2 % MOD)
    for i in a_s:
        for j in range(60):
            v, i = i % 2, i // 2
            keta[j] += v
    for i, v in enumerate(keta):
        c = v * (n-v) % MOD
        ans += c * kaizyo[i] % MOD
        ans = ans % MOD

    print(ans)
if __name__ == '__main__':
    main()