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()))
ans=0
cnt0=[0]*60
cnt1=[0]*60
mod=10**9+7
tp=[0]*60
for i in range(60):
  tp[i]=(1<<i)%mod
for i in range(60):
    x=1<<i
    one=sum(1 for j in a if j&x)
    ans+=tp[i]*one*(n-one)
print(ans%mod)

Solution (Python):
import sys
import numpy as np

sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

MOD = 10 ** 9 + 7
N = ir()
A = np.array(lr(), np.int64)
answer = 0
limit = int(A.max()).bit_length()
for i in range(limit):
    B = (A >> i) & 1
    x = np.count_nonzero(B)
    y = N - x
    add = (x*y) * 2 ** i % MOD
    answer += add

print(answer%MOD)

Solution (Python):
import sys

sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

MOD = 10 ** 9 + 7
N = ir()
A = lr()
bit = [0 for _ in range(60)]
for a in A:
    for i in range(a.bit_length()):
        if (a >> i) & 1:
            bit[i] += 1

answer = 0
for i, x in enumerate(bit):
    answer += x * (N-x) * 2 ** i

print(answer%MOD)

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

def myinput():
    return map(int,readline().split())

n = int(readline())
a = list(myinput())
mod = 10**9 + 7
ans = 0

for j in range(60):
    k = 2**j
    one = 0
    zero = 0
    for i in range(n):
        if (a[i]&k)!=0:
            one += 1
        else:
            zero += 1
    ans_bit = zero * one
    ans += (ans_bit)*(2**j) 
    ans %= mod   

print(ans%mod)

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

def myinput():
    return map(int,readline().split())

n = int(readline())
a = list(myinput())
mod = 10**9 + 7
ans = 0

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

print(ans%mod)

Solution (Python):
n=int(input())
l=[int(c) for c in input().split()]
ans=0
mod=10**9+7
for i in range(60):
  s=sum(a>>i&1 for a in l)
  ans+=s*(n-s)<<i%mod
  ans%=mod
print(ans)

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

p = 10**9+7
ans = 0
for i in range(60):
    x = 1<<i
    one = sum(1 for j in a if j&x)
    ans += pow(2,i,p)*one*(n-one)

print(ans%p)

Solution (Python):
MOD = 10**9 + 7
n = int(input())
a = list(map(int, input().split()))
 
one_count = [0] * 61
for v in a:
  count = 0
  while v != 0:
    if v % 2 == 1:
      one_count[count] += 1
      
    count += 1
    v //= 2
  
 
ans = 0
for i in range(len(one_count)):
  ans += (one_count[i] * (n - one_count[i]) * (2 ** i))
  ans %= MOD
  
print(ans)

Solution (Python):
N=int(input())
a=input().split()
A=[int(b) for b in a]
B=[format(a,'b').zfill(60) for a in A]
mod=pow(10,9)+7
answer=0
for i in range(60):
    zero=0
    one=0
    kotae=1
    for j in B:
        if j[i]=='0':
            zero+=1
        elif j[i]=='1':
            one+=1
    kotae=zero*one
    for _ in range(60-i-1):
        kotae*=2
    answer+=kotae
print(answer%mod)

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(60):
    cnt = np.count_nonzero((A >> i) & 1)
    ans += (2**i * cnt*(N-cnt)) % MOD
    ans %= MOD
print(ans)

Solution (Python):
import math
n=int(input())
a=list(map(int,input().split()))
mod=10**9+7
if max(a)==0:
  print(0)
  exit()
m=math.floor(math.log(max(a),2))+1
ans=0
for i in range(m):
  cnt0=0
  cnt1=0
  for j in range(n):
    if a[j]>>i&1:
      cnt1+=1
    else:
      cnt0+=1
  ans+=(2**i)*(cnt1*cnt0)
  ans%=mod
print(ans)

Solution (Python):
n = int(input())
a = [int(i) for i in input().split()]
ans = 0
mod = 10**9+7
for i in range(60):
    x = 0
    for j in range(n):
        if a[j] >> i & 1: x += 1 
    now = x*(n-x)%mod 
    for _ in range(i): now = now*2%mod 
    ans += now
    ans %= mod
print(ans)

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

Solution (Python):

n=int(raw_input())
a=map(int,raw_input().split())
mod=10**9+7
res=0
for i in range(60):
 cnt=sum([1 for x in a if (x>>i & 1)])
 res+=cnt*(n-cnt)*(1<<i)
 res=res%mod
print res

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

ans=0
for i in range(60):
    ones=str_a[59-i::60].count("1")
    ans+= pow( 2, i ,mod)* ones *(N-ones)
print(ans%mod)

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

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


mod = 10**9+7
ans = 0


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

Solution (Python):
n = int(input())
a = [int(x) for x in input().split()]

d0 = [0]*100
d1 = [0]*100
for i in range(n):
    for j in range(61):
        if a[i] & (1<<j):
            d1[j] += 1
        else:
            d0[j] += 1

x = 1
ans = 0
mod = 10**9+7
for i in range(100):
    ans += x * d0[i] * d1[i] %mod
    x = x * 2 % mod
    ans %= mod
print(ans)

Solution (Python):

def submit():
    n = int(input())
    alist = list(map(int, input().split()))
    modp = 10**9 + 7

    d = 1
    ans = 0
    for i in range(60):
        bit_test = [a & d > 0 for a in alist]
        on_count = sum(bit_test)
        off_count = n - on_count
        ans += d * on_count * off_count
        ans %= modp
        d = d<<1

    print(ans)


submit()

Solution (Python):
def iip():
    ret = [int(i) for i in input().split()]
    if len(ret) == 1:
        return ret[0]
    return ret

n = iip()
al = iip()


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

for a in al:
    b = bin(a)[2:].zfill(60)
    
    for i in range(60):
        if b[i] == "1":
            num1[i] += 1

result = 0
for i, a in enumerate(num1):
    a1 = 2**(59-i) % mod
    a2 = (a * (n-a)) % mod
    result += a1*a2 % mod
    result = result % mod



print(result)

Solution (Python):
import sys

def input(): return sys.stdin.readline().rstrip()
sys.setrecursionlimit(10 ** 7)

MOD = 10**9+7

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

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

Solution (Python):

a = int(input())
b = list(map(int,input().split()))
z_o_cnt = []
max_b = max(b)
base = 0
while True:
    z_o_cnt.append(sum(list(map(lambda x:x%2,b))))
    b = list(map(lambda x:x//2,b))
    max_b //=2
    if max_b==0:
        break
ret = 0
for i,v in enumerate(z_o_cnt):
    ret+=(2**i*(v * (a-v)))%(10**9+7)
print(ret%(10**9+7))

Solution (Python):
MOD = 10**9+7
N = int(input())
L = list(map(lambda x: bin(int(x))[2:], input().split()))
max_len = max([len(v) for v in L])
padL = ["0"*(max_len-len(v))+v for v in L]
cnt = [0]*max_len
for i in range(max_len):
    for l in padL:
        cnt[i] += 1 if l[i] == "1" else 0

ans = 0
v = 1
for i in range(max_len):
    ans += v*cnt[max_len-1-i]*(N-cnt[max_len-i-1])
    ans %= MOD
    v *= 2

print(ans)

Solution (Python):
MOD = 10**9+7
N = int(input())
L = list(map(lambda x: bin(int(x))[2:], input().split()))
max_len = max([len(v) for v in L])
padL = ["0"*(max_len-len(v))+v for v in L]
cnt = [0]*max_len
for i in range(max_len):
    for l in padL:
        cnt[i] += 1 if l[i] == "1" else 0

ans = 0
v = 1
for i in range(max_len):
    ans += v*cnt[max_len-1-i]*(N-cnt[max_len-i-1])
    ans %= MOD
    v *= 2

print(ans)

Solution (Python):






import sys
input = sys.stdin.readline

import math
from collections import deque
from fractions import gcd
from functools import lru_cache






MOD = 10**9 +7
INF = float('inf')






def inputI(): return int(input().strip())
def inputS(): return input().strip()
def inputIL(): return list(map(int,input().split()))
def inputSL(): return list(map(str,input().split()))
def inputILs(n): return list(int(input()) for _ in range(n))
def inputSLs(n): return list(input().strip() for _ in range(n))
def inputILL(n): return [list(map(int, input().split())) for _ in range(n)]
def inputSLL(n): return [list(map(str, input().split())) for _ in range(n)]


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


kaijo_memo = []
def kaijo(n):
  if(len(kaijo_memo) > n):
    return kaijo_memo[n]
  if(len(kaijo_memo) == 0):
    kaijo_memo.append(1)
  while(len(kaijo_memo) <= n):
    kaijo_memo.append(kaijo_memo[-1] * len(kaijo_memo) % MOD)
  return kaijo_memo[n]

gyaku_kaijo_memo = []
def gyaku_kaijo(n):
  if(len(gyaku_kaijo_memo) > n):
    return gyaku_kaijo_memo[n]
  if(len(gyaku_kaijo_memo) == 0):
    gyaku_kaijo_memo.append(1)
  while(len(gyaku_kaijo_memo) <= n):
    gyaku_kaijo_memo.append(gyaku_kaijo_memo[-1] * pow(len(gyaku_kaijo_memo),MOD-2,MOD) % MOD)
  return gyaku_kaijo_memo[n]

def nCr(n,r):
  if(n == r):
    return 1
  if(n < r or r < 0):
    return 0
  ret = 1
  ret = ret * kaijo(n) % MOD
  ret = ret * gyaku_kaijo(r) % MOD
  ret = ret * gyaku_kaijo(n-r) % MOD
  return ret


def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append([i, cnt])
    if temp!=1:
        arr.append([temp, 1])

    if arr==[]:
        arr.append([n, 1])
    return arr


def lcm(a, b):
    return a * b // gcd (a, b)





N = inputI()
l = inputIL()

ans = 0
for n in range(60):
  count_0 = 0
  count_1 = 0
  for i in l:
    if (pow(2,n)&i)>>n:
      count_1 += 1
    else:
      count_0 += 1
  ans = (ans + count_0*count_1*pow(2,n,MOD))%MOD
  
print(ans)

Solution (Python):
import sys
sys.setrecursionlimit(10 ** 6)
input = sys.stdin.readline

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

ans = 0
two = 1
for i in range(61):
  n = len([ a for a in A if (a >> i) & 1 ])
  ans += (n * (N - n) * two % MOD)
  two *= 2 
print(ans%MOD)

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

ans = 0
M = 10**9+7
for i in range(60):
    x = 0
    for j in range(N):     
        if A[j]>>i & 1:
            x += 1
    now = x * (N - x) % M
    for j in range(i):
        now = now * 2 % M
    ans += now
    ans %= M
print(ans)

Solution (Python):
import sys
sys.setrecursionlimit(10**9)

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

    ans = 0
    for mask in range(60): 
        one_sum = 0
        for a in A:
            one_sum += (a >> mask) & 1

        ans += one_sum * (N - one_sum) * 2**mask

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

if __name__ == "__main__":
  main()

Solution (Python):









mod = 10**9 + 7

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

ans = 0
for i in range(n):
    a[i] = bin(a[i])[2:].zfill(60)

for i in range(60):
    count = 0
    for j in range(n):
        count += 1 if a[j][i] == '1' else 0

    ans += (pow(2, 59-i, mod) * count * (n-count)) % mod

print(ans % mod)

Solution (Python):
n = int(input())
a = [int(i) for i in input().split()]
mod = 10 ** 9 + 7
ans = 0
i = 1
for _ in range(60):
    b = 0
    c = 0
    for j in a:
        if j & i != 0:
            b += 1
        else:
            c += 1
    ans += b * c * i % mod
    i *= 2
print(ans%mod)

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

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

Solution (Python):
import numpy as np
MOD = 10 ** 9 + 7
N = int(input())
A = list(map(int,input().split()))
cnt = []
A = np.array(A)
for _ in range(60):
    ad = A % 2
    cnt.append(int(np.sum(ad)))
    A = A // 2
ans = 0
for i in range(60):
    num0 = N - cnt[i]
    num1 = cnt[i]
    ans += ((num0 * num1) * (2 ** i)) % MOD
    ans %= MOD
print(ans)

Solution (Python):

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

for i in range(60):
    s = sum([(a >> i) & 1 for a in A])
    ans = (ans + s * (n-s) * pow(2,i,mod)) % mod
print(ans)

Solution (Python):
mod = 10**9+7
N = int(input())
A = list(map(int,(input().split())))
bi = [[0]*2 for _ in range(60)]
for i in range(N):
    c = 0
    while c < 60:
        if A[i] & 1 == 0:
            bi[c][0] += 1
        else:
            bi[c][1] += 1
        A[i] >>= 1
        c += 1
ans = 0
for i in range(60):
    ans += bi[i][0] * bi[i][1] * pow(2,i)
    ans %= mod
print(ans)

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

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

mod = 10 ** 9 + 7
ans = 0
ni = 1

for i in range(60):
    x = sum([1 for j in range(N) if (A[j] >> i) & 1])
    buff = x * (N - x) * ni
    ans += buff
    ni = ni * 2

print(ans % mod)

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(60):
    b1 = np.count_nonzero(A>>i&1)
    ans += 2**i*b1*(N-b1)
    ans %= mod
print (ans)

Solution (Python):
n = int(input())
L = list(map(int,input().split()))
t = max(L)
maxstr = ''
cur = 1
while t >= cur:
    if t&cur != 0:
        maxstr = '1'+maxstr
    else:
        maxstr = '0'+maxstr
    cur *= 2
calc = [0]*len(maxstr)
for i in range(n):
    cur = 1
    temp = len(maxstr)-1
    while L[i] >= cur:
        if L[i]&cur != 0:
            calc[temp] += 1
        cur *= 2
        temp -= 1
ans = 0
cur = 1
for i in range(len(maxstr)):
    ans += cur*calc[len(maxstr)-i-1]*(n-calc[len(maxstr)-i-1])
    ans %= 10**9+7
    cur *= 2
print(ans)

Solution (Python):
MOD=10**9+7
n=int(input())
x=[0 for i in range(60)]
a=list(map(int,input().split()))

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

Solution (Python):
def main():
    MOD=10**9+7
    n=int(input())
    x=[0 for i in range(60)]
    a=list(map(int,input().split()))

    for i in range(n):
        k=0
        while a[i]>0:
            if a[i]&1:
                x[k]+=1
            a[i]>>=1
            k+=1
    ans=0
    b=1
    for i in range(60):
        ans+=x[i]*(n-x[i])*b
        ans%=MOD
        b=(b*2)%MOD
    print(ans)


if __name__ == '__main__':
    main()

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

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

Solution (Python):
def main():
    import sys 
    input = sys.stdin.readline
    n = int(input())
    l = list(map(int,input().split()))
    
    
    mod = 10**9+7
    ans = 0
    ni = 1
    for j in range(60):
        x = 0
        for i in l:
            if (i >> j) & 1:
                x += 1
        now = x*(n-x)*ni%mod
        ans = (ans+now)%mod
        ni = (ni*2)%mod

    print(ans%mod)
if __name__ == "__main__":
    main()

Solution (Python):
def main():
    import sys 
    input = sys.stdin.readline
    n = int(input())
    l = list(map(int,input().split()))
    c1 = [0]*60
    c0 = [0]*60
    mod = 10**9+7

    for i in l:
        for j in range(60):
            if (i >> j) & 1:
                c1[j] += 1
            else:
                c0[j] += 1

    ans = 0
    ni = 1
    for i in range(60):
        ans += (c1[i]*c0[i]*ni)%mod
        ans %= mod
        ni = ni*2%mod
    print(ans%mod)
if __name__ == "__main__":
    main()

Solution (Python):



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

m = 0
t = 1
for i in range(61):
    count = 0
    for j in range(N):
        count += A[j] % 2
        A[j] //= 2
    m += ((t * (N - count)) % int(1e9+7)) * count % int(1e9+7)
    m %= int(1e9+7)
    t *= 2
    t %= int(1e9+7)
    
print(m)

Solution (Python):
lim = 10**9+7
n=int(input())
A=[int(i) for i in input().split()]
binary = [bin(i)[2:].zfill(60)[::-1] for i in A]

ans=0
for i in range(60):
    l = [s[i] for s in binary]
    
    ans = (ans+ ((l.count("0") * l.count("1"))% lim * 2**i )% lim)% lim
print(ans % lim)

Solution (Python):
def xor_sum(a):
    sum = 0
    d = 10**9+7
    new_a = []
    for j in a:
        new_a.append(str(format(j, 'b')).zfill(60))
    for i in range(60):
        n_0 = 0
        n_1 = 0
        for j in new_a:
            if j[i] == '0':
                n_0 += 1
            else:
                n_1 += 1
        sum += (pow(2, 59-i)*(n_0*n_1))%d
    print(sum%d)

n = int(input())
a = [int(i) for i in input().split()]

xor_sum(a)

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

k=len(bin(max(l)))-2

for i in range(n):
    l[i]=bin(l[i])[2:]

ll=[[0,0] for i in range(k)]
for i in range(n):
    for j in range(k):
        try:
            if l[i][-1-j]=="1":
                ll[j][1]+=1
            if l[i][-1-j]=="0":
                ll[j][0]+=1
        except IndexError:
            ll[j][0]+=1

m=0
for i in range(k):
    m+=ll[i][0]*ll[i][1]*(2**i)
print(m%(10**9+7))

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

print(ans)

Solution (Python):
import numpy as np

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

A = np.array(A)
mod = 10 ** 9 + 7
ans = 0
for i in range(60):
    b = np.count_nonzero(A >> i & 1)
    ans += 2 ** i * b * (N - b)
    ans %= mod
print(ans)

Solution (Python):
import numpy as np
N = int(input())
A = np.array(list(map(int, input().split())))

K = len(bin(np.max(A))) - 2

ans = 0
mod = 10 ** 9 + 7
N %= mod

for i in range(K):
    bit = np.count_nonzero(A >> i & 1) % mod
    ans += pow(2, i, mod) * bit * (N - bit)
    ans %= mod
    
print(ans)

Solution (Python):
import numpy as np
N = int(input())
A = np.array(list(map(int, input().split())))

K = len(bin(np.max(A))) - 2

ans = 0
mod = 10 ** 9 + 7
N %= mod

for i in range(K):
    bit = np.count_nonzero(A >> i & 1) % mod
    ans += pow(2, i, mod) * bit * (N - bit)
    ans %= mod
    
print(ans)

Solution (Python):
import numpy as np
N = int(input())
A = np.array(list(map(int, input().split())))

K = len(bin(np.max(A))) - 2

ans = 0
mod = 10 ** 9 + 7
N %= mod

for i in range(K):
    bit = np.count_nonzero(A >> i & 1) % mod
    ans += 2 ** i * bit * (N - bit)
    ans %= mod
    
print(ans)

Solution (Python):
MOD = 1000000007

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

ans = 0
for k in range(60):
    mask = 1<<k
    cnt1 = sum(1 for x in a if x&mask != 0)
    ans += cnt1*(n-cnt1)*(1<<k)
print(ans%MOD)

Solution (Python):
N = int(input())
A = list(map(int,input().split()))
ans = 0
for i in range(60):
    x = 1<<i
    o = sum(1 for j in A if j&x)
    ans += x*o*(N-o)
    ans %= 10**9+7
print(ans)

Solution (Python):


import numpy as np
N = int(input())
A = np.array(input().split(), dtype=np.int64)
mod = 10 ** 9 + 7

ans = 0
dmax = 61
for d in range(dmax):
    B = np.right_shift(A, d)
    one = np.count_nonzero(np.bitwise_and(B, 1))
    zero = N - one
    add = pow(2, d, mod) * one * zero
    ans = (ans + add) % mod

print(ans)

Solution (Python):
import sys

n=int(input())
alst=list(map(int,sys.stdin.readline().strip().split()))

cumsum=[[0]*(n+1) for i in range(60)]

md=10**9+7

for i in range(1,n+1):
    a=alst[i-1]
    dig=0
    while dig<60:
        bit=a%2
        cumsum[dig][i]=cumsum[dig][i-1]+bit
        dig+=1
        a//=2

ans=0
ceff=1

for d in range(60):
    ret=0
    for i in range(1,n):
        ret+=(cumsum[d][i]-cumsum[d][i-1])*(n-i-cumsum[d][n]+cumsum[d][i])
        ret+=(1-cumsum[d][i]+cumsum[d][i-1])*(cumsum[d][n]-cumsum[d][i])
    ans=(ans+ceff*ret)%md
    ceff=(2*ceff)%md

print(ans)

Solution (Python):
'''
結局この計算は Ai のすべての組み合わせ(Ai 自身同士は含まない)の 
XOR の合計なので、Ai のあるビットの立っている数の合計を c とすると、
Ai のあるビットが0であった場合により計算結果に立つビットの数は 
c、Ai のあるビットが1であった場合により計算結果に立つビットの数は 
N - c になるので、あるビットに関する計算結果は c * (N -c) の
ビットシフトした値になる. 結果として以下の計算で解ける.
'''
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())
l1=[0]*61
l=list(map(int,input().split()))
for j in range(n):
  s=list(str(bin(l[j])))
  for i in range(61):
    if i==len(s)-2:
      break
    if s[-i-1]=='1':
      l1[i]+=1
c=0
for i in range(61):
  c+=pow(2,i,10**9+7)*(n-l1[i])*l1[i]%(10**9+7)
print(c%(10**9+7))

Solution (Python):
M=10**9+7
N=int(input())
la=list(map(int,input().split()))
ans=0
for i in range(60):
    n0=0
    n1=0
    for j in range(N):
        if la[j]&1:
            n1+=1
        else:
            n0+=1
        la[j]>>=1
    ans=(ans+n0*n1%M*(2**i%M))%M
print(ans)

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

len_max = len(list(format(max(a), 'b')))

bin_list = [0]*len_max

for a_ in a:
    for i in range(1,len_max+1):
        if a_ & (1<<(i-1)):
            bin_list[-i] += 1

ans = 0
for i in range(1,len_max+1):
    num_1 = bin_list[-i]%p
    ans += 2**(i-1)%p * num_1 * (n-num_1)%p

print(ans%p)

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

Solution (Python):
N=int(input())
A=list(map(int,input().split()))
B=[]
M=0
for a in A:
    b=bin(a)
    if M<len(b[2:]):
        M=len(b[2:])
    B.append(b[2:])
ans=0
for i in range(0,M):
    z=0;o=0
    for j in range(0,N):
        if len(B[j])<i+1:
            z+=1
        else:
            index=len(B[j])-i-1
            if B[j][index]=='0':
                z+=1
            else:
                o+=1
    ans+=(2**i*(z*o))%(10**9+7)
print(ans%(10**9+7))

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

bitsum = [0 for _ in range(60)]
for x in a:
    for i in range(60):
        bitsum[i] += bool(x & (1 << i))

ans = 0
for x in a:
    for i in range(60):
        k = bitsum[i]
        if (x & (1 << i)):
            k = n - k
        ans += k << i
    ans %= law
if ans % 2 == 0:
    print(ans // 2)
else:
    print((ans + law) // 2)

Solution (Python):
N = int(input())
A = [int(i) for i in input().split()]
ans = 0
MOD = 10**9 + 7
for i in range(60):
    z = 0
    o = 0
    for j in range(N):
        if A[j]&(2**i):
            o += 1
        else:
            z += 1
    ans += z*o*(2**i)
    ans %= MOD
print(ans)

Solution (Python):
import numpy as np


def main():
    length = int(input())
    numbers = np.array(list(map(int, input().split())))
    mod = 10 ** 9 + 7
    answer = 0
    for d in range(60):
        count_one = np.count_nonzero((numbers >> d) & 1)
        answer = (answer + pow(2, d) * count_one * (length - count_one)) % mod
    print(answer)


if __name__ == '__main__':
    main()

Solution (Python):
import sys
def main():
    input = sys.stdin.readline
    N = int(input())
    A = list(map(int, input().split()))
    d = [0] * 60
    for a in A:
        b = 0
        while a:
            if a&1: d[b] += 1
            a >>= 1
            b += 1

    ans = Mint()
    for i in range(60):
        ans += Mint(d[i]) * (N-d[i]) * (1<<i)
    print(ans)

class Mint:
    def __init__(self, value=0, mod=10**9+7):
        self.value = ((value % mod) + mod) % mod
        self.mod = mod

    @staticmethod
    def get_value(x): return x.value if isinstance(x, Mint) else x

    def inverse(self):
        a, b = self.value, self.mod
        u, v = 1, 0
        while b:
            t = a // b
            b, a = a - t * b, b
            v, u = u - t * v, v
        return (u + self.mod) % self.mod

    def __repr__(self): return str(self.value)
    def __eq__(self, other): return self.value == other.val
    def __neg__(self): return Mint(-self.value, self.mod)
    def __hash__(self): return hash(self.value)
    def __bool__(self): return self.value != 0

    def __iadd__(self, other):
        self.value = (self.value + Mint.get_value(other)) % self.mod
        return self
    def __add__(self, other):
        new_obj = Mint(self.value, self.mod)
        new_obj += other
        return new_obj
    __radd__ = __add__

    def __isub__(self, other):
        self.value = (self.value - Mint.get_value(other) + self.mod) % self.mod
        return self
    def __sub__(self, other):
        new_obj = Mint(self.value, self.mod)
        new_obj -= other
        return new_obj
    def __rsub__(self, other):
        new_obj = Mint(Mint.get_value(other), self.mod)
        new_obj -= self
        return new_obj

    def __imul__(self, other):
        self.value = self.value * Mint.get_value(other) % self.mod
        return self
    def __mul__(self, other):
        new_obj = Mint(self.value, self.mod)
        new_obj *= other
        return new_obj
    __rmul__ = __mul__

    def __ifloordiv__(self, other):
        other = other if isinstance(other, Mint) else Mint(other, self.mod)
        self *= other.inverse
        return self
    def __floordiv__(self, other):
        new_obj = Mint(self.value, self.mod)
        new_obj //= other
        return new_obj
    def __rfloordiv__(self, other):
        new_obj = Mint(Mint.get_value(other), self.mod)
        new_obj //= self
        return new_obj


if __name__ == '__main__':
    main()

Solution (Python):

import sys
n = int(input())
a = list(map(int,input().split()))
ans = 0
mod = (10**9 +7)
for j in range(61):
    num_one = 0
    for i in range(len(a)):
        if a[i] & 2**j: 
            num_one += 1
    
    ans += (2**j % mod) * (n-num_one)*(num_one) % mod
    
print(ans%mod)

Solution (Python):
n = int(input())
a = list(map(int,input().split()))
mod = 10**9+7
ans = 0
for i in range(60):
    mask = 1 << i
    count = sum(1 for j in a if mask & j == 0)
    ans += count * (n-count) * pow(2,i,mod)
print(ans % mod)

Solution (Python):
import sys
input=sys.stdin.readline
n=int(input())
a=tuple(map(int,input().split()))
mod=10**9+7
cnt=[0]*60

for temp in a:
    if temp==0:continue
    digit=len(bin(temp))-2
    for j in range(digit):
        if (temp>>j)&1:
            cnt[j]=cnt[j]+1


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

Solution (Python):

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

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

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

Solution (Python):
from math import log
def main():
    N = int(input())
    A = list(map(int,input().split()))
    mod = 10**9+7
    
    digits_cnt1 = [0]*60
    for ai in A:
        if ai == 0:
            continue
        
        for d in range(int(log(ai)/log(2))+1):
            if ai>>d & 1:
                digits_cnt1[d] += 1
    
    ans = 0
    for i in range(60):
        ans += digits_cnt1[i]*(N-digits_cnt1[i])*pow(2,i,mod)
        ans %= mod
    print(ans)

if __name__ == "__main__":
    main()

Solution (Python):
n = int(input())
a = list(map(int,input().split()))
mod = 10**9+7
ans = 0
for i in range(60):
    mask = 1 << i
    count = sum(1 for j in a if mask & j == 0)
    ans += count * (n-count) * pow(2,i,mod)
print(ans % mod)

Solution (Python):
N = int(input())
A = list(map(int, input().split()))
INF = 1000000007
keta = len(bin(max(A))) - 2
ans = 0
shift = 0
for _ in range(keta):
    num_1 = 0
    for a in A:
        if a>>shift&1:
            num_1 += 1
    ans += num_1 * (N-num_1) * 2 ** shift
    shift += 1
print(ans % INF)

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

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

ans = 0
for i in range(len(format(max(a), 'b'))):
    x = 0
    for j in range(n):
        if a[j] >> i & 1:
            x+=1
    now = x * (n - x) % mod
    for j in range(i):
        now = now * 2 % mod
    ans+=now
    ans%=mod

print(ans)

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

mod = pow(10,9)+7

K = 60
P = [0]*K
Z = [0]*K
for a in A:
    n = a
    for i in range(K):
        b = n%2
        if b:P[i]+=1
        else:Z[i]+=1
        n//=2
ans = 0
for k in range(K):
    ans+=(pow(2,k,mod)*(P[k]*Z[k]))%mod
print(ans%mod)