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

MOD = 10 ** 9 + 7
ans = 0
m = 1
ans = 0
for _ in range(60):
    one_count = sum(a & m for a in aaa)
    one_count //= m
    zero_count = n - one_count
    ans = (ans + one_count * zero_count * m) % MOD
    m *= 2
        
print(ans)

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

import numpy as np

def main():
  MOD = 10**9+7
  n = int(input())
  A = np.array(input().split(), dtype=np.int64)
  ans = 0
  for j in range(61):
    X = A>>j & 1
    t = np.count_nonzero(X)
    ans += pow(2, j, MOD) * t * (n-t) % MOD
  print(ans%MOD)
  
if __name__ == "__main__":
  main()

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

def main():
  MOD = 10**9+7
  n, *A = map(int, read().split())
  ans = 0
  for j in range(61):
    c = 0
    for i in A:
      if i>>j & 1:
        c += 1
    ans += 2**j*((n-c)*c)
    ans %= MOD
  print(ans%MOD)
  
if __name__ == "__main__":
  main()

Solution (Python):
n=int(input())
a=list(map(int,input().split()))
s=0
for j in range(len(bin(max(a)))-2):
    cnt1=0
    cnt0=0
    for i in range(n):
      if (a[i]>>j)&1:
        cnt1+=1
      else:
        cnt0+=1
    s+=(cnt1*cnt0*2**j)%(10**9+7)
print(s%(10**9+7))

Solution (Python):
n=int(input())
a=list(map(int,input().split()))
mod=10**9+7
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%=mod
print(ans)

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

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

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

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

Solution (Python):
import math
N = int(input())
A = list(map(int,input().split()))
b = [[0]*60 for i in range(2)]

max_a = 60
for i in range(N):
    x = A[i]
    j = 0
    for j in range(max_a):
        b[x % 2][j] += 1
        x //= 2

x = 0
for i in range(max_a):
    x += b[0][i] * b[1][i] * 2**i
    x %= 10 ** 9 + 7

print (x)

Solution (Python):
import numpy as np
n=int(input())
a=np.array([int(i) for i in input().split()])
mod=int(1e9+7)
ans=0
for k in range(60):
  b=(a>>k)&1
  m=np.count_nonzero(b)
  ans+=m*(n-m)*2**k
  ans%=mod
print(ans)

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 elem in a:
        dic[i] += int((elem & (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 sys
import numpy as np
input = sys.stdin.readline

MOD = 10**9 + 7

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

ans = 0
for n in range(64):
	Anb = (A >> n) & 1
	cnt_one = np.count_nonzero(Anb)
	cnt_zero = N - cnt_one
	x = cnt_one * cnt_zero
	for i in range(n):
		x *= 2
		x %= MOD
	ans = (ans+x)%MOD
print(ans)

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

d1 = [[0]*60 for _ in range(N+1)]
mod = 10**9+7

for i, n in enumerate(A, start=1):
    for j in range(60):
        d1[i][j] = d1[i-1][j] + ((n>>j)&1)

ans = 0
for i, n in enumerate(A, start=1):
    for j in range(60):
        a = d1[N][j]-d1[i][j] 
        if (n>>j)&1:
            a = N-a-i 

        ans += a*(1<<j)

print(ans%mod)

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

d1 = [[0]*60 for _ in range(N+1)]
mod = 10**9+7

for i, n in enumerate(A, start=1):
    for j in range(60):
        d1[i][j] = d1[i-1][j] + ((n>>j)&1)

ans = 0
for i, n in enumerate(A, start=1):
    for j in range(60):
        a = d1[N][j]-d1[i][j] 
        if (n>>j)&1:
            a = N-a-i 

        ans += a*(1<<j)
    ans %= mod

print(ans)

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


result = 0
base = 1
for _ in range(max_digit + 1):
  c0 = 0
  for i in range(N):
    a = A[i] % 2
    A[i] >>= 1
    c0 += (a==0)
  
  result = (result + (base*(N - c0)*c0) % MOD) % MOD
  base = base*2 % MOD

print(result)

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 = base*2 % mod

print(result)

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):
    a = (A >> i) & 1
    count0 = np.count_nonzero(a)
    count1 = N - count0
    tmp = 2**i
    n = count0 * count1
    tmp = tmp * n
    ans += tmp
    ans = ans % MOD
print(ans)

Solution (Python):
n,*a=map(int,open(0).read().split())
c=0
for i in range(61):
 i=2**i
 t=sum(i&b and 1for b in a)
 c=(c+t*(n-t)*i)%(10**9+7)
print(c)

Solution (Python):
n,*a=map(int,open(0).read().split())
c=0
for i in range(61):
 i=2**i
 t=sum(i&b and 1for b in a)
 c=(c+t*(n-t)*i)%(10**9+7)
print(c)

Solution (Python):
n,*a=map(int,open(0).read().split())
c=0
for i in range(61):
  i=2**i
  t=sum(i&b and 1 for b in a)
  c=(c+t*(n-t)*i)%(10**9+7)
print(c)

Solution (Python):


N=int(input())

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

two=[2**i for i in range(61)]
two=two[::-1]
log=[0]*61

for i in range(len(A)):
    for j in range(len(two)):
        if A[i]-two[j]>=0:
            A[i]-=two[j]
            log[j]+=1

ans=0
for i in range(len(two)):
    ans+=(N-log[i])*log[i]*two[i]

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

Solution (Python):
import numpy as np

MOD = 10**9 + 7
n = int(input())
a = np.array(input().split(), np.int64)
max_num = np.max(a)
digit_num = len(format(max_num, 'b'))
ans = 0
for digit in range(digit_num):
    b = (a >> digit) & 1
    one = np.count_nonzero(b)
    zero = n - one
    ans += 2 ** digit * (one * zero)
    ans %= MOD

print(ans)

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

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

Solution (Python):

import sys
sys.setrecursionlimit(10000000)
INF = 1<<32

MOD = 1000000007  

def solve(N: int, A: "List[int]"):
    ans = [0] * 60
    
    
    for i in range(60):
        
        
        x0 = 0
        x1 = 0
        for j in range(N):
            if (A[j]>>i)&1:
                x1 += 1
            else:
                x0 += 1

        ans[i] = x0*x1

    x = 0
    for i in range(len(ans)):
        
        x += pow(2, i) * ans[i] % MOD

    print(x%MOD)

    return



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

if __name__ == '__main__':
    main()

Solution (Python):
import sys
from collections import defaultdict
from collections import deque
import numpy as np
import heapq
from heapq import heappush, heappop
import itertools

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

MOD = 10**9 + 7

ans = 0
for i in range(64):
    B = (A >> i) & 1
    x = np.count_nonzero(B)
    y = N - x
    x *= y

    for _ in range(i):
        x *= 2
        x %= MOD

    ans += x
ans %= MOD
print(ans)

Solution (Python):
N=int(input())
A=list(map(int,input().split()))
bin_A=[bin(c) for c in A]
flags=[True]*N

count=0
for keta in range(60):
   count_0=0
   count_1=0
   for i in range(N):
      if flags[i]:
         if bin_A[i][-1*(keta+1)]=="b":
            count_0+=1
            flags[i]=False
         elif bin_A[i][-1*(keta+1)]=="0":
            count_0+=1
         else:
            count_1+=1
      elif flags[i]==False:
         count_0+=1
   count+=count_0*count_1*2**keta

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

Solution (Python):
n = int(input())
X = list(map(int, input().split()))
res = 0
MOD = int(1e9 + 7)
bit = 0
for n in range(60):
    b1, b0 = 0, 0
    for i in range(len(X)):
       if X[i] & (1 << bit):
           b1 += 1
       else:
           b0 += 1
    res += (b1 * b0 * (1 << bit))
    res = res % MOD
    bit += 1
print(res)

Solution (Python):
import sys

stdin = sys.stdin

mod = 1000000007

ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline().rstrip()
nas = lambda: stdin.readline().split()

n = ni()
a = na()

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

print(ans)

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

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

cnt = [[0, 0] for _ in range(60)]
for i in range(60): 
    for j, v in enumerate(a):
        cnt[i][bool(v & (1 << i))] += 1



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





result = 0
for i, c in enumerate(cnt):
    for j, delete in enumerate(a[:-1]):
        target = not (delete & (1 << i))
        result += (c[target] - sub[i][target]) * (1 << i)

        

        sub[i][not target] += 1

    
    
    












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

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

mod = 10**9 + 7

S = [0]*61

for i in range(N):
    tmpA = A[i]
    now = 0
    while tmpA != 0:
        if tmpA%2 == 1:
            S[now] += 1
        tmpA //= 2
        now += 1
ans = 0
for i in range(61):
    ans += pow(2,i,mod)*S[i]*(N-S[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 = list(map(int, input().split()))
a = np.array(a)
mod = 10**9 + 7
ans = 0
for i in range(60):
    
    cnt_zero = np.count_nonzero(a >> i & 1)
    cnt_one = n - cnt_zero
    
    ans += 2**i * cnt_zero * cnt_one
    ans %= mod
print(ans)

Solution (Python):
from math import log, ceil
N = int(input())
A = list(map(int, input().split()))


keta = ceil(log(max(A)+1,2))

X = [0] * keta

for a in A:
  work = a
  i = 0
  while work > 0:
    X[i] += work % 2
    i += 1
    work = work // 2

ans = 0
mod = int(1e9+7)
for i in range(len(X)):
  ans += X[i] * (N-X[i]) * 2**i
  ans = 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
N = int(readline())
A = np.array(readline().split(), np.int64)

mod = 10**9+7
ans = 0
for i in range(64):
	B = (A>>i)&1
	x = np.count_nonzero(B)
	y = N - x
	x *= y

	for _ in range(i):
		x *= 2
		x %= mod
	ans += x
	ans %= mod
print(ans)

Solution (Python):

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

"""
ビット演算は桁ごとに独立しているので、何桁目かというループを外側において
桁ごとに計算して、最後に全部の値を足す。
↓何が良いか？
XORの性質として、0を1個、1を1個選ぶことで1になるので、そうなる選び方の総数を求めることで
高速に計算が可能となる。
"""

ans = 0

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

    now *= 2**i 

    ans += now
    ans %= mod

print(ans)

"""
その桁のXORが１になる回数が
(1の出現回数)*(0の出現回数)であることの証明

その桁の全ループに対して、愚直に1の出現回数を数えてみる
今回は、[0,1,0,1,0,0,1]について考える。X = 3,Y = 4でXOR=12となることを証明する。

[0] 1 0 1 0 0 1 → 3回(0より右に1は3回ある)
0 [1] 0 1 0 0 1 → 3回
0 1 [0] 1 0 0 1 → 2回
0 1 0 [1] 0 0 1 → 2回
0 1 0 1 [0] 0 1 → 1回
0 1 0 1 0 [0] 1 → 1回
---------------------
計：              12回

よって、その桁の全ループにおいて
XORが1になる回数は、(1の出現回数)*(0の出現回数)であることが分かる。
"""

Solution (Python):

import heapq
import collections
import math
import sys
N =  int(input())
input = sys.stdin.readline








nums = list(map(int,input().split(" ")))
keta = [0] * 62


jijou = []
MOD = 10 ** 9 + 7


for num in nums:
    s = format(num,"b")
    l = len(s)

    for i in range(0,l):
        if s[l - i - 1 ] == "1":
            keta[i] += 1

ans = 0
temp = 1
for i in range(62):

    ans += ( keta[i] * (N - keta[i])) * temp
    ans %= MOD
    temp *= 2
    temp %= MOD
print(ans)

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

MOD = 10**9+7

m = 1
ans = 0
for i in range(60):
    bit = sum(a & m for a in A)
    bit //= m
    zero = N - bit
    now = bit * zero % MOD
    for j in range(i):
        now = (now * 2) % MOD
    ans += now
    ans %= MOD
    m <<= 1

print(ans)

Solution (Python):
n = int(input())
a = list(map(int, input().split()))
max = 60
ans = 0
mod = 10**9 + 7
for i in range(max):
    one = 0
    for ai in a:
        if (ai >> i) & 1:
            one += 1
    ans += one*(n - one)*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())))

mod = 10**9 + 7
ans = 0

for j in range(60):
    li = (a >> j) & 1
    i = np.count_nonzero(li)
    o = n - i
    ans += i*o*2**j
    ans %= mod

print(ans % mod)

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

Solution (Python):
import numpy as np

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

mod = 10 ** 9 + 7

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

print(ans%mod)

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

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

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

print(ans)

Solution (Python):

import numpy as np

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

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

print(ans % mod)

Solution (Python):
n = int(input())
a = list(map(int, input().split()))
ans = 0
mod = 1e9 + 7
digit = 1
for i in range(60):
  one = 0
  for aa in a:
    if (aa >> i) & 1:
      one += 1
  ans += (one * (n - one) * digit) % mod
  ans %= mod
  digit *= 2

print(int(ans))

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

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

MOD = 10 ** 9 + 7
cnt = [0] * 61

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

answer = 0
for i in range(61):
  answer = (answer + (2 ** i * cnt[i] * (N - cnt[i]))) % MOD
print(answer)

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

maxA_len = len(bin(maxA)[2:])
num0_each_digit = [0 for _ in range(maxA_len)]
num1_each_digit = [0 for _ in range(maxA_len)]

for i in range(N):
    for i_bit, bit in enumerate(bin(A[i])[2:].zfill(maxA_len)):
        if bit == '0':
            num0_each_digit[i_bit] += 1
            num0_each_digit[i_bit] %= MOD
        else:
            num1_each_digit[i_bit] += 1
            num1_each_digit[i_bit] %= MOD
ans = 0
for i in range(maxA_len):
    factor = (2 ** (maxA_len - i - 1)) % MOD
    ans += (num0_each_digit[i] * num1_each_digit[i] * factor) % MOD

print(ans % MOD)

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

zero_each_dig = [0 for _ in range(60)]
one_each_dig = [0 for _ in range(60)]

for i in range(n):
     for j in range(60):
        if (A[i] >> j) & 1 == 1:
            one_each_dig[j] += 1
        else:
            zero_each_dig[j] += 1

Multi = []
for k in range(60):
    Multi.append(zero_each_dig[k] * one_each_dig[k] * (2**k) % (10**9 +7))

ans = sum(Multi) % (10**9 +7)
print(ans)

Solution (Python):
N = int(input())
A = list(map(int,input().split()))
suma = 0
maxa = max(A)
bin = format(maxa,'b')
for i in range(len(bin)):
    count1 = 0
    for j in range(N):
        if (A[j] >> i) & 1 == 1:
            count1 += 1
    suma = (suma+(N-count1)*count1*((2**i))%(10**9+7))%(10**9+7)
print(suma)

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

Solution (Python):

MOD = 10 ** 9 + 7
n = int(input())
a = list(map(lambda x: format(int(x), '060b')[::-1], input().split()))

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

for i in range(60):
    ans += ((2 ** i) * onecount[i] * zerocount[i] % MOD)
    ans %= MOD
print(ans)

Solution (Python):

import numpy as np
n=int(input())
a=np.array([int(i) for i in input().split()])
mod=int(1e9+7)
ans=0
for k in range(60):
  b = (a>>k)&1
  m = np.count_nonzero(b)
  ans += m*(n-m)*2**k
print(ans%mod)

Solution (Python):
n = int(input())
a = list(map(int, input().split()))
mod = 1000000007
ml = len(bin(max(a)))-2
ans = 0
for i in range(ml):
  x = sum([1 for j in a if ((j>>i) & 1)])
  ans += x*(n-x)*(2**i)
  ans %= mod
print(ans)

Solution (Python):


import sys
sys.setrecursionlimit(300000)

MOD = 1000000007  

def solve(N: int, A: "List[int]"):
    counts = [0] * 62
    for val in A:
        i = 0
        while val > 0:
            counts[i] += val % 2
            val //= 2
            i += 1
    ret = 0
    for i, cnt in enumerate(counts):
        ret += (2 ** i) * (cnt) * (N - cnt)
        ret %= MOD
    print(ret)
    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=[int(i) for i in input().split()]
MOD = int(1e9+7)
ans=0
for k in range(60):
  x=0
  t=1<<k
  for i in range(n):
    if a[i]&t:
      x+=1
  c=x*(n-x)*2**k
  ans+=c
print(ans%MOD)

Solution (Python):

n = int(input())
a = list(map(int,input().split()))
mod = 10**9+7
md = len(bin(max(a)))-2
ans = 0
for d in range(md):
    cnt1 = sum([1 for i in a if ((i>>d)&1)]) 
    ans += cnt1 * (n-cnt1) * (1<<d)          
    ans %= mod                              
    
print(ans%mod)

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

Solution (Python):

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

Solution (Python):

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

Solution (Python):
import sys
import numpy as np
input = sys.stdin.readline
N = int(input())
MOD = 10**9+7
def inputs():return [int(x) for x in input().split()]
A = np.array([inputs()])
ans = 0
for i in range(63):
  B = A&(1<<i)
  x = np.count_nonzero(B)
  y = N-x
  x*=y
  ans+=(2**i*x)%MOD
  ans%=MOD
print(ans)

Solution (Python):


def resolve():
    N = int(input())
    A = tuple(map(int, input().rstrip().split()))

    ma = max(*A)

    i = 1
    asum = 0
    while i < ma:
        cc = 0
        for x in A:
            if x & i: cc += 1
        asum += i * (N - cc) * cc
        i <<= 1

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

if __name__ == "__main__":
    resolve()

Solution (Python):
N=int(input())
A=[format(i,'060b') for i in map(int,input().split())]
ans=0
mod=10**9+7
for k in range(60):
    count=[a[60-1-k] for a in A].count('0')
    ans+=count*(N-count)*(2**k)%mod
print(ans%mod)

Solution (Python):
p = 10**9+7
N = int(input())
C = {i:0 for i in range(60)}
A = input().split()
for i in range(N):
    a = bin(int(A[i]))[2:]
    n = len(a)
    for j in range(n):
        if a[j]=="1":
            C[n-1-j] += 1
cnt = 0
for i in range(60):
    if C[i]>0:
        cnt = (cnt+C[i]*(N-C[i])*2**i)%p
print(cnt)

Solution (Python):
MOD = 1000000007
class ModInt:
    def __init__(self, x):
        self.x = x % MOD

    def __str__(self):
        return str(self.x)

    __repr__ = __str__

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

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

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

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

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

    __radd__ = __add__

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

    __rmul__ = __mul__

    def __rtruediv__(self, other):
        return (
            ModInt(
                other.x * pow(self.x, MOD - 2, MOD)
            ) if isinstance(other, ModInt) else
            ModInt(other * pow(self.x, MOD - 2, MOD))
        )

    def __rpow__(self, other):
        return (
            ModInt(pow(other.x, self.x, MOD)) if isinstance(other, ModInt) else
            ModInt(pow(other, self.x, MOD))
        )
    
    def __iadd__(self,other):
        self.x += other.x if isinstance(other, ModInt) else other
        self.x %= MOD
        return self

    def __isub__(self,other):
        self.x += ModInt(MOD - other.x) if isinstance(other, ModInt) else ModInt(MOD - other)
        return self

    def __imul__(self, other):
        self.x *= other.x if isinstance(other, ModInt) else other
        self.x %= MOD
        return self
    
    def factorical(self,n):
        tmp = ModInt(1)
        for i in range(n):
            tmp *= (i+1)
        return tmp
    
    
    def modinv(self,a,m=MOD):
        b = m
        u = 1
        v = 0
        while(b):
            t = a//b
            a -= t * b
            a,b = b,a
            u -= t * v
            u,v = v,u
        return ModInt(u)

    def comb(self,n,r):
        n = int(n)
        r = int(r)
        if r > n or n < 0 or r < 0:
            return 0
        m = n+1
        nterms = min(r, n-r)
        numerator = ModInt(1)
        denominator = ModInt(1)
        for j in range(1, nterms + 1):
            numerator *= m - j
            denominator *= j
        return numerator * self.modinv(denominator.x)
        

n = int(input())
a = list(map(int,input().split()))
b = [0] * 60
for i in range(len(a)):
  tmp = a[i]
  for j in range(60):
    x = tmp%2
    if x == 1:
      b[j] += 1
    tmp //= 2
tmp = ModInt(1)
ans = ModInt(0)
for i in range(60):
    s = ModInt((n-b[i])*b[i])
    ans += s*tmp
    tmp *= 2
print(ans)

Solution (Python):
import numpy as np 

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

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

ans = 0
mod = int(1e9+7)

for i in range(60+1):
    bottom_bit = (A>>i)&1 
    ones = np.sum(bottom_bit[bottom_bit>0])
    
    tmp = ones*(N-ones)
    for j in range(i):
        tmp = (tmp * 2) % mod
    ans += tmp

print(ans%mod)

Solution (Python):
N=int(input())
A=[format(i,'060b') for i in map(int,input().split())]
ans=0
mod=10**9+7
for k in range(60):
    count=[a[60-1-k] for a in A].count('0')
    ans+=count*(N-count)*(2**k)%mod
print(ans%mod)

Solution (Python):
mod = int(1e9 + 7)
N = int(input())
A = [format(i, '060b') for i in map(int, input().split())]
S = 0
for k in range(60):
  s = [b[59-k] for b in A]
  v = s.count('0')*s.count('1')
  S += (v<<k)
S %= mod
print(S)

Solution (Python):

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

b = [0]*100

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

res = 0
for i in range(100):
    res += b[i]*(n-b[i])*(1<<i)
    res %= MOD

print(res)

Solution (Python):
N = int(input())
A = list(map(int, input().split()))
MOD = 10 ** 9 + 7
mask = 1
ret = 0
for i in range(70):
    on = 0
    off = 0
    for a in A:
        if a & mask:
            on += 1
        else:
            off += 1
    ret += (on * off) * mask
    ret %= MOD
    mask *= 2

print(ret)

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

l.sort(reverse=True)
kmax = len(format(l[0], 'b'))

l0 = [0]*kmax
l1 = [0]*kmax

for i in range(n):
  a = format(l[i], 'b')
  a = ''.join(list(reversed(a)))
  for j in range(kmax):
    if j > len(a)-1:
      l0[j] += 1
    elif a[j] == '0':
      l0[j] += 1
    else:
      l1[j] += 1

ans = 0
for k in range(kmax):
  ans += l0[k]*l1[k]*(2**k)
  ans %= 10**9+7
print(ans)

Solution (Python):
import itertools

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


def main():
    count_1 = [0] * 61
    for i in range(60):
        tmp = 0
        for j, a in enumerate(A):
            tmp += (a >> i) & 1
        count_1[i] += tmp
    ans = 0
    for i, c1 in enumerate(count_1):
        c0 = len(A) - c1
        ans += c0 * c1 * 2**i
    ans %= MOD
    print(ans)


if __name__ == '__main__':
    main()

Solution (Python):
n = int(input())
divide = 10 ** 9 + 7

a = [format(i, '060b') for i in map(int, input().split())]
ans = []

for i in range(60):
    bit_list = [b[59-i] for b in a]
    val = bit_list.count('0') * bit_list.count('1')
    ans.append((val * 2 ** i))

print(sum(ans)%divide)

Solution (Python):
'''input
3 5
1 2 1
2 3 0
'''

from sys import stdin, setrecursionlimit
from bisect import bisect_left
import sys, threading
from collections import defaultdict


def power(a, x, mod):
    if x == 0:
        return 1
    temp = power(a, x//2, mod) % mod
    if x % 2:
        return ((temp * temp) % mod * a) % mod
    else:
        return ((temp * temp)% mod)



n = int(stdin.readline().strip())
arr = list(map(int, stdin.readline().split()))
ans = 0
mod = 10 ** 9 + 7
for i in range(60):
    num = 1 << i
    count = 0
    for k in range(n):
        if num & arr[k] == 0:
            count += 1
    
    ans += (power(2, i, mod) *(count * (n - count)) % mod) % mod
    ans %= mod
print(ans)

Solution (Python):
import sys
import math
import heapq
sys.setrecursionlimit(10**7)
INTMAX = 9223372036854775807
INTMIN = -9223372036854775808
DVSR = 1000000007
def POW(x, y): return pow(x, y, DVSR)
def INV(x, m=DVSR): return pow(x, m - 2, m)
def DIV(x, y, m=DVSR): return (x * INV(y, m)) % m
def LI(): return [int(x) for x in input().split()]
def LF(): return [float(x) for x in input().split()]
def LS(): return input().split()
def II(): return int(input())
def FLIST(n):
    res = [1]
    for i in range(1, n+1): res.append(res[i-1]*i%DVSR)
    return res
def gcd(x, y):
    if x < y: x, y = y, x
    div = x % y
    while div != 0:
        x, y = y, div
        div = x % y
    return y

N=II()
As=LI()

DIG_CUM = [[0]*60 for _ in range(N+1)]

for i in range(N):
    for s in range(60):
        DIG_CUM[i+1][s] = DIG_CUM[i][s] + ((As[i] >> s) & 1)



POW2 = [1]
for i in range(60): POW2.append(POW2[i]*2%DVSR)

res = 0
for i in range(N-1):
    for s in range(60):
        coef = DIG_CUM[N][s] - DIG_CUM[i+1][s]
        if (As[i] >> s) & 1: coef = N - i - 1 - coef
        res += coef * POW2[s]
    res %= DVSR
print(res)