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

''':'
docker run --rm -it -v $(cd $(dirname $0) && pwd):/vo:ro pypy:3-2.4.0 /bin/bash -c "pypy3 /vo/$(basename $0) < /vo/g.inp"; exit $?
exit 0
'''
import sys

def _i(): return int(sys.stdin.readline().strip())
def _ia(): return [ int(x) for x in sys.stdin.readline().strip().split() ]
mod = 10**9 + 7

n= _i()
a= _ia()
z = [ 0 ] * 60
o = [ 0 ] * 60

for ai in a:
    b = bin(ai)[2:]
    for i,c in enumerate(reversed(b)):
        if c=="0": z[i]+=1
        else: o[i]+=1
    
    for i in range(len(b),60): z[i]+=1

ans = 0
base = 1
for zz,oo in zip(z,o):
    ans = ( ans + ( base * zz*oo ) ) % mod
    base = (base * 2) % mod

print(ans)

Solution (Python):
from sys import stdout
printn = lambda x: stdout.write(x)
inn = lambda : int(input())
inl   = lambda: list(map(int, input().split()))
inm   = lambda:      map(int, input().split())
DBG = True 
BIG = 999999999
R = 10**9 + 7

def ddprint(x):
  if DBG:
    print(x)

n = inn()
a = inl()
b = [ [0]*n for i in range(60) ]
acc = [ [0]*n for i in range(60) ]
sums = [0]*60
for bit in range(60):
    for i in range(n):
        b[bit][i] = (a[i]>>bit)&1
    acc[bit][n-1] = b[bit][n-1]
    for i in range(n-2,-1,-1):
        acc[bit][i] = acc[bit][i+1] + b[bit][i]
    for i in range(n-1):
        sums[bit] += acc[bit][i+1] if b[bit][i]==0 else \
                     (n-1-i-acc[bit][i+1])

x = 0
for bit in range(60):
    x = (x + sums[bit]*(2**bit)) % R
print(x)

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

Solution (Python):
mod=10**9+7
def num2bi(x, k):
  
  out=format(x, '0'+str(k)+'b')
  return out

N=int(input())
A=list(map(int, input().split()))
ma=max(A)
keta=1
while ma>=2**keta:
  keta+=1
  
onekazu=[0 for i in range(keta)]
k=str(keta)
for i in range(N):
  temp=format(A[i], '0'+str(k)+'b')
  onekazu=[onekazu[j]+1 if temp[j]=='1' else onekazu[j] for j in range(keta)]
    
out=0
out=sum([(onekazu[i]*(N-onekazu[i])%mod)*(2**(keta-1-i))%mod for i in range(keta)])
out%=mod  
print(out)

Solution (Python):

mod=10**9+7

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

b=[[0 for i in range(N)] for k in range(60)] 
d0=[0 for k in range(60)]
d1=[0 for k in range(60)]

for i in range(N):
    for k in range(60):
        if A[i]>>k&1:
            d1[k]+=1
        else:
            d0[k]+=1

ans2=0
for k in range(60):
    ans2+=2**k*d0[k]*d1[k]

print(ans2%mod)

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

ans = 0
for i in range(60 + 1):
    cnt = 0
    for a in A:
        if a >> i & 1:
            cnt += 1
    ans = (ans + 2 ** i * cnt * (N - cnt)) % (10 ** 9 + 7)
print(ans)

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

MOD = 10**9+7

sum_num = 0
for i in range(60):
    o = 0
    for a in A:
        o += (a>>i)%2
    z = N - o
    sum_num = (sum_num + (o*z)*(1<<i)) % MOD

print(sum_num)

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

    N = int(input())
    A = list(map(int, input().split()))
    mod = pow(10, 9) + 7

    ones = [0 for _ in range(60)]

    for i in range(N):
        for j in range(60):
            if (A[i] >> j) % 2 == 1:
                ones[j] += 1
    ans = 0
    for j in range(60):
        ans += pow(2, j) * ones[j] * (N - ones[j])
        ans %= mod

    return ans % mod


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

Solution (Python):
from sys import stdin

N = int(stdin.readline().rstrip())
A = [int(x) for x in stdin.readline().rstrip().split()]

inf = 10 ** 9 + 7

cnt = [0] * 60

for a in A:
    s = bin(a)[2:].zfill(60)
    s = s[::-1]
    for i in range(60):
        if s[i] == '1':
            cnt[i] += 1

ans = 0
for i in range(60):
    ans += (cnt[i] * (N - cnt[i])) * (2 ** i)
    ans %= inf

print(ans)

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


def solve(n, a):
    m = 61
    b = [('0'*m + bin(a[i])[2:])[-1:-m:-1] for i in range(n)]
    cnt_bit = [0] * m
    for i in range(n):
        for j, c in enumerate(b[i]):
            if c == '1':
                cnt_bit[j] += 1
    total = 0
    k = 1
    for i in range(m - 1):
        t = 0
        for j in range(n):
            if b[j][i] == '0':
                t += k * cnt_bit[i]
            if b[j][i] == '1':
                t += k * (n - cnt_bit[i])
        t //= 2
        total += t
        k = (k*2 % MOD)
    return total % MOD


def bf(n, a):
    total = 0
    for i in range(n - 1):
        for j in range(i + 1, n):
            total += (a[i] ^ a[j])
    return total % MOD


if __name__ == "__main__":
    n = int(input())
    a = list(map(int, input().split()))

    print(solve(n, a))

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

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

num = [0] * 60
for i in a:
    temp = bin(i + 2 ** 60)[3:]
    for i in range(len(temp)):
        if temp[i] == "1":
            num[i] += 1
ans = 0
for i in range(60):
    ans += (num[i] * (n - num[i]) * (2 ** (59 - i)))
    ans %= mod
print(ans)

Solution (Python):
n=int(input())
a=list(map(int, input().split()))
for i in range(n):
	a[i]=format(a[i],'b')


total=0
count1=0
for k in range(60):
	count1=0
	for i in range(n):
		if k<len(a[i]):
			if a[i][-1-k]=='1':
				count1+=1
	total+=count1*(n-count1)*(2**k)
	total=total%(10**9+7)
print(total)

Solution (Python):
N = int(input())
a = list(map(int,input().split()))
ma = max(a)
maketa = len(bin(ma))-2

res = 0
dic = {}
for i in range(maketa):
    dic[i] = 0
for i in range(0,maketa):
    num = 0
    for j in range(N):
        
        dic[i] += int((a[j] & (2**i))>>i)
        
for i in range(maketa):
    num = dic[i]
    res += num*(N-num)*(2**(i))
print(res%(10**9+7))

Solution (Python):
import numpy as np
n = int(input())
N = 60


d = np.array(list(map(int, input().split())))
nums = (((d[:, None] & (1 << np.arange(N)))) > 0).astype(int)
res = 0
MOD = int(1e9+7)
k = np.full(N, (n*(n-1)/2) % MOD)
n1 = nums.sum(0) % MOD
n0 = (n-nums.sum(0)) % MOD
k -= (n1*(n1-1)//2) % MOD
k -= (n0*(n0-1)//2) % MOD
k %= MOD

res = 0
for i, kk in enumerate(k):
    res += ((1 << i)*kk) % MOD
    res %= MOD


print(int(res))

Solution (Python):

inf = 10**9 + 7

n = int(input())
a = list(map(int, input().split()))
count = [0] * 70
for i in range(n):
    tmp = list(str(bin(a[i])[2:]))[::-1]
    
    for j in range(len(tmp)):
        if tmp[j] == '1':
            k = 69 - j
            count[k] += 1



ans = 0
for i in range(70):
    k = 2 ** (69 - i)
    k %= inf
    x = count[i] % inf
    y = (n - x) % inf
    ans += (x * y * k) % inf
    ans %= inf

ans %= inf
print(ans)

Solution (Python):
import sys

def solve():
    input = sys.stdin.readline
    N = int(input())
    A = [int(a) for a in input().split()]
    mod = 7 + 10 ** 9

    bit = dict()
    pow_list = dict()
    for j in range(60): 
        bit[j] = 0
        pow_list[j] = pow(2, j, mod)

    first = A[0]
    for j in range(60):
        bit[j] = first % 2
        first //= 2
    
    ans = 0
    for i in range(1, N):
        num = A[i]
        for j in range(60):
            if num % 2 == 1:
                ans += (i - bit[j]) * pow_list[j]
                ans %= mod
            else:
                ans += bit[j] * pow_list[j]
                ans %= mod
            bit[j] += (num % 2)
            num //=2
            
    print(ans)

    return 0

if __name__ == "__main__":
    solve()

Solution (Python):
n = int(input())
mod = 10**9+7
num = [ int(v) for v in input().split() ]
bits = [ 0 for i in range(100) ]

for i in num:
    j = 0
    while i > 0:
        if i % 2 == 1:
            bits[j] += 1
        i //= 2
        j += 1


binmax = 0
for i in range(100):
    if bits[i] > 0:
        binmax = i
binmax += 2


pow_2_list = []
q = 1
for i in range(100):
    pow_2_list.append(q)
    q *= 2
    q %= mod


ans = 0
for i, v in enumerate(bits[:binmax]):
    ans += v * (n-v)  * pow_2_list[i] 
print(ans % mod)

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

Solution (Python):
N=int(input())
A=[int(x) for x in input().split()]
A.sort()

mod = 10**9 + 7
def mulmod(s):
    r = 1
    for i in s:
        r = r*i%mod
    return r


ans = 0
k=1
while A[-1]>0:
    t = 0
    for i in range(N):
        t+=A[i]%2
        A[i]//=2
    r = [N-t, t, pow(2, k-1, mod)]
    ans = (ans + mulmod(r))%mod
    k +=1
print(ans)

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

MOD = 10 ** 9 + 7

ans = 0
for i in range(60):
    n = sum([(a >> i) & 1 for a in A])
    ans = (ans + n * (N - n) * (2 ** i)) % MOD

print(ans)

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

ans = 0
bitcnt = [0] * 60
for Ai in A:
    Ai_tmp = Ai
    for j in range(60):
        bitcnt[j] += (Ai_tmp % 2)
        Ai_tmp >>= 1







ans = 0
for i in range(60):
    ans_cnt = (bitcnt[i] * (N - bitcnt[i])) % (10 ** 9 + 7)
    ans_lvl = (1 << i) % (10 ** 9 + 7)
    ans_tmp = (ans_cnt * ans_lvl) % (10 ** 9 + 7)
    ans = (ans + ans_tmp) % (10 ** 9 + 7)

print(ans)

Solution (Python):
import sys

read = sys.stdin.buffer.read
input = sys.stdin.buffer.readline
inputs = sys.stdin.buffer.readlines

mod=10**9+7


import numpy as np

def main():
	n=int(input())
	A=np.array(read().split(), np.int64)
	n=len(A)
	ans=0
	
	for i in range(62):
		B=A%2
		k=np.count_nonzero(B)
		A=A//2
		ans+=(2**i)*(k*(n-k))
		ans%=mod
	print(ans)
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
if __name__ == "__main__":
	main()

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

bits = [0 for _ in range(60)]
for i in range(n):
    for b in range(60):
        if a[i] & 2 ** b > 0:
            bits[b] += 1

ans = 0
for i, b in enumerate(bits):
    if b > 0:
        ans += (2 ** i) * (b * (n-b))
        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):
    n1 = sum([1 for a in A if (a>>i)&1])
    ans += (1<<i)*n1*(N-n1)
    ans %= mod
print(ans)

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

for i in range(N):
    n=A[i]
    
    for j in range(60):
        L[j]+=n//(2**(59-j))
        n%=(2**(59-j))
        

ans=0
for i in range(60):
    ans+=(N-L[i])*(L[i])*2**(59-i)
    ans%=(10**9+7)
print(ans)

Solution (Python):
N = int(input())
MOD = 10**9+7
a = [int(c) for c in input().split()]
M = max(a).bit_length()
ls = [0]*M
for i in range(N):
  m = a[i]
  for j in range(M):
    if m%2==1:
      ls[j] += 1
    m >>= 1

ans = 0
x = 1
for i in range(M):
  ans += x*(ls[i]*(N-ls[i]))
  ans %= MOD
  x *= 2
  x %= MOD
print(ans)

Solution (Python):
import sys
def input():
    return sys.stdin.readline()[:-1]
N = int(input())
A=list(map(int,input().split()))
l=[0]*60
for i in A:
    s=str(bin(i))[2:]
    for j in range(len(s)):
        if s[-j-1]=="1":
            l[j]+=1
a=0
for i in range(60):
    a=(a+2**i*l[i]*(N-l[i]))%(10**9+7)
print(a)

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

dp0 = [0]*61
dp1 = [0]*61
for a in As:
    bins = format(a,"061b")[::-1]
    for i,b in enumerate(bins):
        if b == "0":
            dp0[i] += 1
        else:
            dp1[i] += 1
ans = 0
for i,(zero,one) in enumerate(zip(dp0,dp1)):
    ans += (zero*one*2**i)%mod
print(ans%mod)

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

Solution (Python):
MOD = 10**9 + 7
N = int(input())
*A, = map(int, input().split())
ans = 0
for i in range(60):
    bit_0, bit_1 = 0, 0
    for a in A:
        if (a >> i) & 1: 
            bit_1 += 1
        else:
            bit_0 += 1
    ans += bit_1 * bit_0 * pow(2, i, MOD)
    ans %= MOD
print(ans)

Solution (Python):
import collections
import sys

input = sys.stdin.readline

ri = lambda: int(input())
rs = lambda: input().rstrip()
ril = lambda: list(map(int, input().split()))
rsl = lambda: input().rstrip().split()
ris = lambda n: [ri() for _ in range(n)]
rss = lambda n: [rs() for _ in range(n)]
rils = lambda n: [ril() for _ in range(n)]
rsls = lambda n: [rsl() for _ in range(n)]

MOD = 10**9 + 7

n = ri()
ls = ril()
counter = collections.defaultdict(int)
for a in ls:
    i = 0
    while a > 0:
        if a % 2 == 1:
            counter[i] += 1
        a //= 2
        i += 1
res = 0
for k, v in counter.items():
    res += (n - v) * v * 2**k % MOD
    res %= MOD
print(res)

Solution (Python):
def sumXOR( arr,  n): 
    sum = 0
    for i in range(0, 100): 
        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%=10**9+7
    return sum

n=int(input())
arr=list(map(int,input().split()))
sum = sumXOR(arr, n); 
sum%=10**9+7
print(sum)

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

nums = []

inputs = input()
for i in inputs.split(" "):
    nums.append(int(i))

count = 0
m = 10 **9 + 7
for i in range(0, 64):
    one = 0
    zero = 0

    for j in range(0, n):
        if (nums[j] % 2 == 1):
            one += 1
        else:
            zero += 1

        nums[j] //= 2
    
    count += (zero * one * (1 << i)) % m

print(count % m)

Solution (Python):
import sys
from collections import deque
readline = sys.stdin.readline

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

P = 10**9 + 7

ans = 0

for i in range(60):
    c = 0
    for a in A:
        c += ((a >> i) & 1)
    
    ad = c * (N - c) % P
    ans += ad * (1 << i)
    ans %= P

print(ans)

Solution (Python):
N=int(input())
A=list(map(int,input().split()))
P=10**9+7
ans=0
BIN=[0]*N
for h in range(N):
    BIN[h]=bin(A[h])[2:].zfill(60)

for i in range(60):
    inc=0
    one=0
    zero=0
    for j in range(N):
        if BIN[j][59-i]=="0":
            zero+=1
        else:
            one+=1
    ans+=zero*one*2**i
print(ans%P)

Solution (Python):
n = int(input())
str_a = ''.join(['{:060b}'.format(a) for a in map(int, input().split())])
mod = 10**9 + 7

rest = 0
for d in range(60):
  ones = str_a[59-d::60].count('1')
  rest = (rest + 2**d * ones * (n - ones)) % mod
    
print(rest)

Solution (Python):
import sys
input=sys.stdin.readline
n=int(input())
a=list(map(int,input().split()))
mod=10**9+7
cnt=[]
q=set()
for i in range(n):
	q.add(i)
for i in range(60):
	p=0
	l=[]
	for j in q:
		if a[j]%2==1:
			p+=1
		a[j]//=2
		if a[j]==0:
			l.append(j)
	for j in range(len(l)):
		q.remove(l[j])
	cnt.append(p)
ans=0
for i in range(60):
	ans+=(n-cnt[i])*cnt[i]*(2**i)
	ans%=mod
print(ans)

Solution (Python):
import sys
sys.setrecursionlimit(10**9)
INF=10**18
MOD=10**9+7
def input():
    return sys.stdin.readline().rstrip()

def main():
    N=int(input())
    A=list(map(int,input().split()))
    z=len(bin(max(A)))-2
    l=[0]*z
    for x in A:
        for i in range(z):
            if (x >> i) & 0b1 == 1:
                l[i]+=1
    ans=0
    for i in range(z):
        ans+=l[i]*(N-l[i])*(2**i)
        ans%=MOD
    print(ans)
    
                    
if __name__ == '__main__':
    main()

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

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

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


if __name__ == '__main__':
    main()

Solution (Python):











import sys
sys.setrecursionlimit(10**6)
input=sys.stdin.readline
from math import floor,ceil,sqrt,factorial,log 
from heapq import heappop, heappush, heappushpop
from collections import Counter,defaultdict,deque
from itertools import accumulate,permutations,combinations,product,combinations_with_replacement
from bisect import bisect_left,bisect_right
from copy import deepcopy
inf=float('inf')
mod = 10**9+7
def pprint(*A): 
    for a in A:     print(*a,sep='\n')
def INT_(n): return int(n)-1
def MI(): return map(int,input().split())
def MF(): return map(float, input().split())
def MI_(): return map(INT_,input().split())
def LI(): return list(MI())
def LI_(): return [int(x) - 1 for x in input().split()]
def LF(): return list(MF())
def LIN(n:int): return [I() for _ in range(n)]
def LLIN(n: int): return [LI() for _ in range(n)]
def LLIN_(n: int): return [LI_() for _ in range(n)]
def LLI(): return [list(map(int, l.split() )) for l in input()]
def I(): return int(input())
def F(): return float(input())
def ST(): return input().replace('\n', '')

class ModInt:
    def __init__(self, x):
        self.x = x % mod
    
    def __str__(self):
        return str(self.x)
    
    __repr__ = __str__

    def __add__(self, other):
        if isinstance(other, ModInt):
            return ModInt(self.x + other.x)
        else:
            return ModInt(self.x + other)

    __radd__ = __add__
        
    def __sub__(self, other):
        if isinstance(other, ModInt):
            return ModInt(self.x - other.x)
        else:
            return ModInt(self.x - other)

    def __rsub__(self, other):
        if isinstance(other, ModInt):
            return ModInt(other.x - self.x)
        else:
            return ModInt(other - self.x)

    def __mul__(self, other):
        if isinstance(other, ModInt):
            return ModInt(self.x * other.x)
        else:
            return ModInt(self.x * other)

    __rmul__ = __mul__

    def __truediv__(self, other):
        if isinstance(other, ModInt):
            return ModInt(self.x * pow(other.x, mod-2,mod))
        else:
            return ModInt(self.x * pow(other, mod - 2, mod))
            
    def __rtruediv(self, other):
        if isinstance(other, self):
            return ModInt(other * pow(self.x, mod - 2, mod))
        else:
            return ModInt(other.x * pow(self.x, mod - 2, mod))
            

    def __pow__(self, other):
        if isinstance(other, ModInt):
            return ModInt(pow(self.x, other.x, mod))
        else:
            return ModInt(pow(self.x, other, mod))
            

    def __rpow__(self, other):
        if isinstance(other, ModInt):
            return ModInt(pow(other.x, self.x, mod))
        else:
            return ModInt(pow(other, self.x, mod))

def main():
    N=I()
    A=LI()
    max_bit = 60
    BITs_1 = [0]*max_bit
    BITs_0 = [0]*max_bit
    ans = ModInt(0)
    for i,a in enumerate(A):
        for j in range(max_bit):
            if (1<<j)&a:
                ans += (1<<j)*BITs_0[j]
                BITs_1[j]+=1
            else:
                ans += (1<<j)*(BITs_1[j])
                BITs_0[j]+=1
    print(ans)
if __name__ == '__main__':
    main()

Solution (Python):

import sys

MOD = 1000000007  


def solve(N: int, A: "List[int]"):
    ones = [0 for _ in range(60)]
    for a in A:
        for i in range(60):
            if (a >> i) & 1:
                ones[i] += 1

    res_l = [0 for _ in range(60)]
    for a in A:
        for i in range(60):
            if (a >> i) & 1:
                res_l[i] += (N-ones[i])
            else:
                res_l[i] += ones[i]
    res = 0
    for i in range(60):
        res += res_l[i] << i
        res %= MOD
    if res % 2 == 1:
        res += MOD
    print(res // 2)
        
    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):
n = int(input())
a = list(map(int, input().split()))
mod = 1000000007
b = 2 ** 60
ret = 0
while b > 0:
    c0, c1 = 0, 0
    for ai in a:
        if ai & b != 0:
            c1 += 1
        else:
            c0 += 1
    ret = (ret + c1 * c0 * b) % mod
    b //= 2
print(ret)

Solution (Python):
n=int(input())
l=list(map(int,input().split()))
l=[format(i,"b").zfill(61) for i in l]
ans=0
MOD=10**9+7
la=[0 for i in range(61)]
for i in l:
    for num,j in enumerate(str(i)):
        if j=="1":
            la[60-num]+=1
for num,i in enumerate(la):
    ans+=2**num*i*(n-i)
    ans%=MOD
print(ans)

Solution (Python):
import math
import random
from operator import itemgetter
import re
import sys
from itertools import accumulate
from collections import defaultdict
from collections import deque
from bisect import bisect_left,bisect
from heapq import heappop,heappush
from fractions import gcd
from copy import deepcopy
input = sys.stdin.readline
N  = int(input())
A = [int(i) for i in input().split()]
keta = [0] * 60
for i in range(N):
    a = 0
    while A[i] != 0:
        if A[i]%2 == 1:
            keta[a] += 1
        A[i] = A[i]//2
        a +=1
ans = 0
for i in range(60):
    ans += (N-keta[i])*keta[i]*(2**i)
    ans = ans%1000000007
print(ans)

Solution (Python):

import sys
sys.setrecursionlimit(10**6)
input = sys.stdin.readline
MOD = 10**9 + 7

def sumXOR(arr, n): 
    sumation = 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) 
        sumation = sumation + idsum
        sumation %= MOD
      
    return sumation
  
n = int(input())
a = [int(item) for item in input().split()]
  
print(sumXOR(a, n))

Solution (Python):
n=int(input())
a=[int(i) for i in input().split()]
cnt=[0 for i in range(64)]
mask=1
for i in range(64):
    for j in a:
        if j|mask==j: 
            cnt[i]+=1
    mask*=2
x=1
res=0
for i in range(64):
    res+=cnt[i]*(n-cnt[i])*x
    res%=1000000007
    x*=2
print(res)

Solution (Python):
def main():
    def accumulate(array):
        for i in range(len(array) - 1):
            array[i + 1] += array[i]
        return array

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

    X = [[0] * N for i in range(61)]
    for i, a in enumerate(A):
        for j in range(61):
            if (1 << j) & a:
                X[j][i] = 1

    for i in range(61):
        X[i] = accumulate(X[i])


    ans = 0
    for i, a in enumerate(A):
        for j in range(61):
            x = X[j][-1] - X[j][i]
            if (1 << j) & a:
                ans += ((1 << j) % MOD) * ((N - i - 1) - x)
                ans %= MOD

            else:
                ans += ((1 << j) % MOD) * x
                ans %= MOD


    print(ans % MOD)


if __name__ == '__main__':
    main()

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

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

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

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

Solution (Python):
N=int(input())
A=list(map(int,input().split()))
d=[[0]*N for i in range(60)]
for i,a in enumerate(A):
    for j in range(60):
        d[j][i]=a%2
        a>>=1
m=10**9+7
r=0
for i in range(60):
    s=sum(d[i])
    r=(r+(N-s)*s*pow(2,i,m))%m
print(r%m)

Solution (Python):


Q = 10**9 + 7
def main():
    N = int( input())
    A = list( map( int, input().split()))
    T = [[0]*60 for _ in range(N)]
    P = [0]*60
    for i in range(N):
        a = A[i]
        for j in range(60):
            T[i][j] = a%2
            P[j] += a%2
            a //= 2
    ans = 0
    for i in range(60):
        plus = P[i]
        minus = N - plus
        ans = (ans + plus*minus%Q*pow(2,i,Q))%Q
    print(ans)
        
if __name__ == '__main__':
    main()

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


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


ans = 0
for i in range(60):
  
  sn = (N-p[i]) * p[i]
  ans = (ans + (sn << i)) % MOD

print(ans)

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

n = int(input())
a = list(map(int,input().split()))
mod = 10**9+7

cnt = [0]*65

for e in a:
    for i in range(65):
        if (e>>i)&1 == 1:
            cnt[i] += 1

res = 0
p = 1

for e in cnt:
    res = (res+p*e*(n-e)%mod)%mod
    p = p*2%mod

print(res)

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

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

ans = 0
for i in range(60):
    N1 = sum([1 for a in Abi if a[-(i + 1)] == '1'])
    ans = (ans + (2 ** i) * N1 * (N - N1)) % MOD

print(ans)

Solution (Python):
import sys
input=sys.stdin.readline
n=int(input())
a_list=list(map(int,input().split()))
INF=10**9+7
ans=0
for i in range(60):
    o=0
    for j in range(n):
        if a_list[j]%2==0:
            o+=1
        a_list[j]=a_list[j]>>1
    t=o*(n-o)
    ans=(ans+t*2**i)%INF
print(ans)

Solution (Python):
N = int(input())
A = [int(a) for a in input().split()]


L = [0]*61

for i in range(N):
    b = bin(A[i])
    for j in range(2, len(b)):
        if b[j] == "1":
            L[len(b)-j-1] += 1

ans = 0
mod = 10**9+7

for i in range(61):
    c = 2**i*(L[i]*(N-L[i]))
    ans += c
    ans %= mod
    
print(ans)

Solution (Python):
import sys
sys.setrecursionlimit(10000000)

from bisect import *
from collections import *
from heapq import *
import functools
import itertools
import math
INF = float('inf')
MOD = 10**9+7

M = 60
N = int(input())
A = [int(x) for x in input().split()]
f = [[0] * M for i in range(N+1)]
for i in range(N):
    a = A[i]
    for j in range(M):
        f[i+1][j] = f[i][j] + (a & 1)
        a >>= 1
ans = 0
for i in range(N):
    k = 1
    for j in range(M):
        if (A[i]>>j) & 1:
            ans += k * (N - i - 1 - f[N][j] + f[i+1][j])
        else:
            ans += k * (f[N][j] - f[i+1][j])
        ans %= MOD
        k <<= 1
        k %= 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):
n = int(input())
a = list(map(int, input().split()))

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

result = 0
for i in range(60):
    result = (result + 2**i * resl[i] * (n-resl[i])) % mod
print(result)

Solution (Python):






N = int(input())
A = [int(x) for x in input().split()]
MOD = 10 ** 9 + 7





count = [0] * 60
for i in range(N):



    for j in range(60):
        count[j] += A[i] % 2
        A[i] //= 2











ans = 0
for d in range(60):
    ans = (ans + count[d] * (N - count[d]) * 2 ** (d)) % MOD





print(ans)

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

N = int(input())
A = list(map(int, input().split()))
MOD = 10**9+7
A = [format(Ai, 'b') for Ai in A]
L = max(len(Ai) for Ai in A)
A = ['0'*(L-len(Ai))+Ai for Ai in A]
ans = 0

for i in range(L):
    one, zero = 0, 0
    
    for j in range(N):
        if A[j][i]=='1':
            one += 1
        else:
            zero += 1
    
    add = pow(2, L-i-1, MOD)*one*zero%MOD
    ans += add
    ans %= MOD

print(ans)

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

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

ans = 0
for d in range(60):
    sumXOR = 0
    num0, num1 = 0, 0
    for A in As:
        if (A>>(59-d))&1:
            num1 += 1
        else:
            num0 += 1

    sumXOR += (num0 * num1) % MOD
    sumXOR %= MOD
    ans *= 2
    ans += sumXOR
    ans %= MOD

print(ans)

Solution (Python):
n = int(input())
a = list(map(int,input().split()))
b = []
for i in range(n):
  tmp = bin(a[i])[2:]
  tmp = '0' * (64-len(tmp)) + tmp
  b.append(tmp)
ans = 0
bit = 1
mod = 10 ** 9 + 7
for k in range(64):
  z1 = 0
  for i in range(n):
    if b[i][-k-1] == '1':
      z1 += 1
  add = z1 * (n-z1) * bit
  add %= mod
  ans += add
  ans %= mod
  bit *= 2
  bit %= mod
  
print(ans)

Solution (Python):
N = int(input())
C1 = [0 for i in range(60)]
C0 = [0 for i in range(60)]

V = list(map(int, input().split()))
for n in V:
    i = 0
    for i in range(60):
        if (n % 2 == 1):
            C1[i] += 1
        else:
            C0[i] += 1
        n //= 2
MOD = int(pow(10, 9) + 7)
total = 0;
for i in range(60):
    total += pow(2, i) * C1[i] * C0[i]
    total %= MOD
print(total)

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

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

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

ans = 0
for i, b in enumerate(B):
    ans += ((N - b) * b % mod) * pow(2, i, mod)
    ans %= mod

print(ans)

Solution (Python):
import sys
import heapq
import bisect
 
mod = 10**9+7
 
def I(): return(int(sys.stdin.readline()))
def LI(): return([int(x) for x in sys.stdin.readline().split()])
def S(): return(list(sys.stdin.readline())[:-1])
 
def main():
    N = I()
    A = LI()
    ans = 0
    count = [0]*62

    for i in range(62):
        mask = 1<<i
        for a in A:
            if a&mask:
                count[i]+=1

    for i in range(62):
        ans += (count[i] * (N-count[i]))*(1<<i)%mod
        ans %= mod


    return(ans)
 
if __name__ == "__main__":
    print(main())

Solution (Python):
N = int(input())
As = list(map(int, input().split()))
r = 0



for i in range(64):
  n = 0
  for A in As:
    if A&(1<<i) != 0:
      n += 1
  
  d = n*(N-n)%1000000007
  d2 = (d<<i)%1000000007
  r = (r+d2)%1000000007
print(r)