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()))
def f(x):
    b = '0' * 64 + bin(x)[2:]
    b = b[::-1]
    b = b[:64]
    return list(map(int, list(b)))

bit_count = [0] * 64
for i in a:
    b = f(i)
    for j in range(64):
        bit_count[j] += b[j]

ans = 0
for i in range(64):
    bc = bit_count[i]
    ans += (2**i) * bc * (n - bc)
    ans %= 10**9 + 7

print(ans)

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

mod = 10**9+7

cnt = [0]*60
bt = [0]*60

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

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

print(ans)

Solution (Python):
from sys import stdin, stdout 

MOD = int(1e9+7)

def pow_mod(a , p , m):
    if p < 2:
        ans = 1
        for _ in range(p):
            ans *= a
            if ans >= m:
                ans = ans % m
        return ans
    ans = pow_mod(a , p //2 , m)
    ans = ans * ans

    if ans >= m :
        ans = ans % m
    if p % 2 :
        ans = ans * a 
        if ans >= m :
            ans = ans % m 
    return ans

    

def solve():
    n = int(input())
    A = [int(inp) for inp in input().split()]
    count_1 = [0] * 61 
    pow_2 = [pow_mod(2, i, MOD) for i in range(61)]
    for a in A :
        x = a
        while x :
           for i in range(61):
               if x & 1 :
                   count_1[i] += 1
               x = x >> 1
    
    
    sum = 0
    
    
    
    
    
    
    
    
    
    
    

    
    
    
    for i in range(61):
        sum += pow_2[i] * count_1[i] * ( n - count_1[i])
        if sum >= MOD:
            sum = sum % MOD
    
    
    print(sum)


def main():
    solve()


if __name__ == "__main__":
    main()

Solution (Python):
N = int(input())
A = list(map(int, input().split()))
B = [[0 for i in range(N)]for j in range(60)]
M = 1000000007
ans = [0 for i in range(60)]
sumB = [[0 for i in range(N)]for j in range(60)]
for j in range(N):
  for i in range(60):
    B[i][j] = A[j]>>i & 1
    sumB[i][j] = A[j]>>i & 1
    if j > 0:
      sumB[i][j] += sumB[i][j-1]
for i in range(1, N):
  for j in range(60):
    if B[j][-i]==0:
      ans[j] += sumB[j][-(i+1)]
    else:
      ans[j] += N-i-sumB[j][-(i+1)]
a = 0
for i in range(60):
  a += (ans[i]*pow(2, i, M))%M
  a %= M
print(a)

Solution (Python):
import sys

sys.setrecursionlimit(10 ** 7)
f_inf = float('inf')
mod = 10 ** 9 + 7


def resolve():
    n = int(input())
    A = list(map(int, input().split()))

    res = 0
    for mask in range(60):
        cnt1 = sum([1 if a & (1 << mask) else 0 for a in A])
        cnt0 = n - cnt1
        res += (pow(2, mask, mod) * cnt1 * cnt0) % mod
        res %= mod
    print(res)


if __name__ == '__main__':
    resolve()

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

cumsum = [[0 for j in range(2)] for i in range(60)]
ans = [0] * 60


for i in range(len(A) - 1, -1, -1):
    plus_num = A[i]
    bit_num = format(plus_num, "060b")
    
    for i, bit in enumerate(bit_num):
        bit = int(bit)
        if bit == 0:
            ans[i] += cumsum[i][1]
        else:
            ans[i] += cumsum[i][0]
        cumsum[i][bit] += 1
    
    

ans_num = 0
mod = 10**9 + 7
for i, cnt in enumerate(ans):
    ans_num += 2**(59-i) * cnt
    ans_num %= mod
print(ans_num)

Solution (Python):




import sys
from io import StringIO
import unittest

def resolve():
    readline=sys.stdin.readline
    mod=10**9+7
    n=int(readline())
    arr=list(map(int, readline().rstrip().split()))
    ans = 0
    x = 1
    for i in range(60):
        c = 0
        for j in range(n):
            if arr[j]&x != 0:
                c += 1
        ans += (c * (n-c)) * x
        ans %= mod
        x = x*2
    print(ans)
    return

if 'doTest' not in globals():
    resolve()
    sys.exit()

Solution (Python):




import sys
from io import StringIO
import unittest

def resolve():
    readline=sys.stdin.readline
    mod=10**9+7
    n=int(readline())
    arr=list(map(int, readline().rstrip().split()))
    binArr = [[0 for i in range(60)] for j in range(n)]
    cnt=[0]*60
    for i in range(n):
        b = bin(arr[i])[2:]
        lenb = len(b)
        for j in range(lenb):
            binArr[i][j] = int(b[lenb-1-j])
            cnt[j]+=binArr[i][j]
    ans=[0]*60
    answer = 0
    for i in range(n):
        for j in range(60):
            
            
            cnt[j]-=binArr[i][j]
            if binArr[i][j] == 0:
                ans[j] += cnt[j]
            else:
                ans[j] += (n-cnt[j]-i-1)
    x=1
    for i in range(60):
        answer += ans[i]*x
        answer %= mod
        x*=2
        x%=mod
    print(answer)
    return

if 'doTest' not in globals():
    resolve()
    sys.exit()

Solution (Python):
N, *A = map(int, open(0).read().split())
MOD = 1_000_000_007
ans = 0
for i in range(64):
    p, q, = 0, 0
    for a in A:
        if a >> i & 1:
            p += 1
        else:
            q += 1
    ans += pow(2, i, MOD) * p * q
    ans %= MOD
print(ans)

Solution (Python):
N,*A=map(int,open(0).read().split())
print(sum((b:=1<<i)*(N-(z:=sum(1 for a in A if a&b)))*z%(m:=10**9+7) for i in range(60))%m)

Solution (Python):
N,*A=map(int,open(0).read().split())
print(sum((b:=1<<i)*(z:=sum(1 for a in A if a&b==0))*(N-z)%(mod:=10**9+7) for i in range(60))%mod)

Solution (Python):

import math

n = int(input())
A = list(map(int,input().split()))
ans = 0
MOD=10**9+7
L0 = [0] * 60
L1 = [0] * 60
for i in range(n):
    b = A[i]
    
    b = format(b, '060b')
    
    for j in range(60):
        if b[60 - j  -1] == "1":
            L1[j] += 1
        else:
            L0[j] += 1



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

Solution (Python):
n = int(input())
A = sorted(map(int, input().split()), reverse=True)
ans = 0
mod = 10 ** 9 + 7
m=A[0]
for i in range(61):
    cnt0 = cnt1 = 0
    if m < 2 ** i:
        break
    for j, a in enumerate(A):
        if a < 2 ** i:
            cnt0 += n - j
            break
        if (a >> i) & 1:
            cnt1 += 1
        else:
            cnt0 += 1
    ans += (((2 ** i) % mod) * ((cnt1 * cnt0) % mod)) % mod
    ans %= mod

print(ans)

Solution (Python):
def main():
    n = int(input())
    A = sorted(map(int, input().split()), reverse=True)
    ans = 0
    mod = 10 ** 9 + 7
    m=A[0]
    for i in range(61):
        cnt0 = cnt1 = 0
        if m < 2 ** i:
            break
        for j, a in enumerate(A):
            if a < 2 ** i:
                cnt0 += n - j
                break
            if (a >> i) & 1:
                cnt1 += 1
            else:
                cnt0 += 1
        ans += (((2 ** i) % mod) * ((cnt1 * cnt0) % mod)) % mod
        ans %= mod

    print(ans)

if __name__ == "__main__":
    main()

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

Solution (Python):

import sys
def main(N, A):
    b1 = [0] * 60
    for a in A:
        for i in range(60):
            if a & (1 << i): b1[i] += 1
    ans = Mint()
    for i in range(60):
        ans += Mint(1 << i) * b1[i] * (N - b1[i])
    print(ans)

MOD = 10**9 + 7
class Mint:
    __slots__ = ('value')

    def __init__(self, value=0):
        self.value = value % MOD
        if self.value < 0: self.value += MOD

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

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

    def __repr__(self): return str(self.value)
    def __eq__(self, other): return self.value == other.value
    def __neg__(self): return Mint(-self.value)
    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)) % MOD
        return self

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

    def __isub__(self, other):
        self.value = (self.value - Mint.get_value(other)) % MOD
        if self.value < 0: self.value += MOD
        return self

    def __sub__(self, other):
        new_obj = Mint(self.value)
        new_obj -= other
        return new_obj

    def __rsub__(self, other):
        new_obj = Mint(Mint.get_value(other))
        new_obj -= self
        return new_obj

    def __imul__(self, other):
        self.value = self.value * Mint.get_value(other) % MOD
        return self

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

    def __ifloordiv__(self, other):
        other = other if isinstance(other, Mint) else Mint(other)
        self *= other.inverse()
        return self

    def __floordiv__(self, other):
        new_obj = Mint(self.value)
        new_obj //= other
        return new_obj

    def __rfloordiv__(self, other):
        new_obj = Mint(Mint.get_value(other))
        new_obj //= self
        return new_obj

if __name__ == '__main__':
    input = sys.stdin.readline
    N = int(input())
    *A, = map(int, input().split())
    main(N, A)

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

mod = 10**9+7
X = [0]*62
for i in range(n):
    a = A[i]
    b = format(a, 'b')
    b = list(b)
    b.reverse()
    for j in range(len(b)):
        if b[j] == '1':
            X[j] += 1
ans = 0
for i in range(62):
    x = X[i]
    y = n-X[i]
    
    ans += x*y*pow(2, i, mod)
ans %= mod
print(ans)

Solution (Python):
N = int(input())
A = list(map(int, input().split()))
mod = 10**9+7
D = {}
for a in A:
    bit = bin(a)[2:][::-1]
    for i in range(len(bit)):
        if bit[i] == '1':
            if i not in D:
                D[i] = 1
            else:
                D[i] += 1

ans = 0
for k, v in D.items():
    ans += (N-v)*v*2**k % mod
    ans = ans % mod

print(ans)

Solution (Python):
N = int(input())
MOD = 10**9+7
nums = list(map(int, input().split()))
B = [0 for _ in range(60)]
for num in nums:
  for i in range(60):
    if num>>i&1:
      B[i] += 1
answer = 0
for i, b in enumerate(B):
  if b > 0:
    answer = (answer+b*(N-b)*2**i)%MOD
print(answer)

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

mod = 10**9+7

ans = 0
p = 1
for i in range(60):
    s = sum(1 for b in a if b&p)
    ans += s*(n-s)*p
    ans %= mod
    p <<= 1
print(ans)

Solution (Python):
N = int(input())
A = list(map(int, input().split()))
mod = 10**9+7
ma = max(A)
n = len(bin(ma))-2
D = [0]*n
ans = 0
for i in range(n):
    zero = 0
    one = 0
    for a in A:
        if a>>i&1:
            one+=1
        else:
            zero+=1
            
    ans+=((one*zero)*2**i)%mod
    ans%=mod
print(ans)

Solution (Python):

import sys
from itertools import chain, count

MOD = 1000000007  


def solve(N: int, A: "List[int]"):
    a_max = max(A)
    ans = 0
    for i in count(0):
        mask = 2**i
        if mask > a_max:
            return ans
        c0 = 0
        c1 = 0
        for a in A:
            if a & mask:
                c1 += 1
            else:
                c0 += 1
        mask = mask % MOD
        ans = (ans + mask*(c0 * c1)) % MOD 

def main():
    tokens = chain(*(line.split() for line in sys.stdin))
    N = int(next(tokens))  
    A = [int(next(tokens)) for _ in range(N)]  
    answer = solve(N, A)
    print(answer)

if __name__ == '__main__':
    main()

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

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

mod = 10 ** 9 + 7
ans = 0
for i in range(60):
    ones = 0
    for a in A:
        
        if a & (1 << i):
            ones += 1
    
    
    
    ans = (ans + ones * (N - ones) * (1 << i)) % mod

print(ans)

Solution (Python):

import sys

sysread = sys.stdin.buffer.readline
read = sys.stdin.buffer.read


sys.setrecursionlimit(10**7)









INF = 1 << 50
EPS = 1e-8
mod = 10 ** 9 + 7

def mapline(t = int):
    return map(t, sysread().split())
def mapread(t = int):
    return map(t, read().split())

def generate_inv(n,mod):
    """
    逆元行列
    n >= 2
    Note: mod must bwe a prime number
    """
    ret = [0, 1]
    for i in range(2,n+1):
        next = -ret[mod%i] * (mod // i)
        next %= mod
        ret.append(next)
    return ret

def run():
    N, *A = mapread()
    maxA = max(A)
    L = maxA.bit_length()
    subs = [0] * L
    for k in range(L):
        sum = 0
        for a in A:
            if (a >> k) & 1:
                sum += 1 << k
            sum %= mod
        subs[k] = sum

    sumA = 0
    for a in A:
        sumA += a
        sumA %= mod
    ret = 0
    ret += (sumA * N) % mod
    ret += (sumA * N) % mod

    sub_sum = 0
    for a in A:
        sums = 0
        for k in range(L):
            if (a >> k) & 1:
                sums += subs[k] * 2
                sums %= mod
        sub_sum += sums
        sub_sum %= mod

    ret -= sub_sum
    ret %= mod

    inv = generate_inv(2, mod)
    ret *= inv[2]
    ret %= mod
    print(ret)


if __name__ == "__main__":
    run()

Solution (Python):
n=int(input())
A=list(map(int,input().split()))
ans=0
for d in range(61):
    n_1 = 0
    for a in A:
        if (a>>d)&1 == 1:
            n_1 += 1
    n_0 = n - n_1
        
    ans += n_0*n_1 * 2**d
    ans %= 10**9+7
print(ans)

Solution (Python):

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
import numpy as np
 
mod = 10 ** 9 + 7
 
N = int(input())
A = np.array(list(map(int, input().split())))
 
 
ans = 0
for n in range(len(bin(max(A)))):   
    num_1 = np.count_nonzero((A >> n)&1)   
    num_0 = N - num_1                      
    mul = num_1 * num_0   
    ans += ((2 ** n)*mul) % mod
ans %= mod
print(ans)

Solution (Python):
import sys
import numpy as np
mod=10**9+7
n=int(sys.stdin.buffer.readline())
a=np.fromstring(sys.stdin.buffer.readline(),dtype=np.int64,sep=' ')
ans=0
b=1
for i in range(60):
    s=int((a&1).sum())
    ans=(ans+s*(n-s)*b)%mod
    a>>=1
    b=b*2%mod
print(ans)

Solution (Python):
n=int(input())
table=[[0]*n for i in range(60)]
for i,v  in enumerate(map(int,input().split())):
    for j in range(60):
        table[j][n-1-i]=v%2
        v//=2
        if v==0:break

ans=0
mod1,mod2=10**9+7,998244353
mod=mod1
a=1
for t in table:
    o,z=0,0
    
    for v in t:
        if v:
            o+=1
            ans=(ans+z*a)%mod
        else:
            z+=1
            ans=(ans+o*a)%mod

    a=a*2%mod
print(ans)

Solution (Python):
import sys
from sys import exit
from collections import deque
from copy import deepcopy
from bisect import bisect_left, bisect_right, insort_left, insort_right
from heapq import heapify, heappop, heappush
from itertools import product, permutations, combinations, combinations_with_replacement
from functools import reduce
from math import gcd, sin, cos, tan, asin, acos, atan, degrees, radians

sys.setrecursionlimit(10**6)
INF = 10**20
eps = 1.0e-20
MOD = 10**9+7

def lcm(x,y):
    return x*y//gcd(x,y)
def lgcd(l):
    return reduce(gcd,l)
def llcm(l):
    return reduce(lcm,l)
def powmod(n,i,mod=MOD):
    return pow(n,mod-1+i,mod) if i<0 else pow(n,i,mod)
def div2(x):
    return x.bit_length()
def div10(x):
    return len(str(x))-(x==0)
def intput():
    return int(input())
def mint():
    return map(int,input().split())
def lint():
    return list(map(int,input().split()))
def ilint():
    return int(input()), list(map(int,input().split()))
def judge(x, l=['Yes', 'No']):
    print(l[0] if x else l[1])
def lprint(l, sep='\n'):
    for x in l:
        print(x, end=sep)
def ston(c, c0='a'):
    return ord(c)-ord(c0)
def ntos(x, c0='a'):
    return chr(x+ord(c0))
class counter(dict):
    def __init__(self, *args):
        super().__init__(args)
    def add(self,x,d=1):
        self.setdefault(x,0)
        self[x] += d
    def list(self):
        l = []
        for k in self:
            l.extend([k]*self[k])
        return l
class comb():
    def __init__(self, n, mod=None):
        self.l = [1]
        self.n = n
        self.mod = mod
    def get(self,k):
        l,n,mod = self.l, self.n, self.mod
        if k<0 or n<k:
            return 0
        k = n-k if k>n//2 else k
        while len(l)<=k:
            i = len(l)
            l.append(l[i-1]*(n+1-i)//i if mod==None else (l[i-1]*(n+1-i)*powmod(i,-1,mod))%mod)
        return l[k]
def pf(x,mode='counter'):
    C = counter()
    p = 2
    while x>1:
        k = 0
        while x%p==0:
            x //= p
            k += 1
        if k>0:
            C.add(p,k)
        p = p+2-(p==2) if p*p<x else x
    if mode=='counter':
        return C
    S = set([1])
    for k in C:
        T = deepcopy(S)
        for x in T:
            for i in range(1,C[k]+1):
                S.add(x*(k**i))
    if mode=='set':
        return S
    if mode=='list':
        return sorted(list(S))



N,A=ilint()
ans=0
beki2=[2**(59-i) for i in range(60)]
S=[0]*60
B=list(map(lambda x:bin(x)[2:].zfill(60),A))

def f(x):
    global S
    for i in range(60):
        S[i]+=int(x[i])

f(B[N-1])
for i in range(N-2,-1,-1):
    for j in range(60):
        ans += beki2[j]*S[j] if B[i][j]=='0' else beki2[j]*(N-1-i-S[j])
        ans %= MOD
    f(B[i])
    
print(ans)

Solution (Python):
import sys

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007


def main():
    N, *A = map(int, read().split())

    ans = 0
    for i in range(60):
        one = 0
        for a in A:
            if a & (1 << i):
                one += 1
        ans = (ans + one * (N - one) * (1 << i)) % MOD

    print(ans)
    return


if __name__ == '__main__':
    main()

Solution (Python):
import sys

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007


def main():
    N, *A = map(int, read().split())

    ans = 0
    for i in range(60):
        one = 0
        for a in A:
            if a & (1 << i):
                one += 1
        ans = (ans + one * (N - one) * (1 << i)) % MOD

    print(ans)
    return


if __name__ == '__main__':
    main()

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

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

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

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

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

print(ans)

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

x=[0]*61

for i in range(61):
  for j in a:
    if (j>>i)%2==1:
      x[i]+=1


for i in a:
  for j in range(61):
    if (i>>j)%2==1:
      ans+=(n-x[j])*(2**j)


print(ans%mod)

Solution (Python):


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

bits=[0]*71
for a in A:
    j=0
    while a>>j:
        if (a>>j)&1:
            bits[j]+=1
        j+=1

t=0
n=70
while n>=0:
    if bits[n]!=0:
        break
    n-=1

for a in A:
    j=0
    while j<=n:
        if (a>>j)&1:
            res+=((2**j)*(N-bits[j]))%p
        else:
            res+=((2**j)*bits[j])%p
        j+=1
    t=res
print((res*500000004)%p)

Solution (Python):
import sys

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007


def main():
    N, *A = map(int, read().split())

    ans = 0
    p = 1
    for _ in range(60):
        n = 0
        for i in range(N):
            A[i], d = A[i] // 2, A[i] % 2
            n += d
        ans = (ans + n * (N - n) * p) % MOD
        p = p * 2 % MOD

    print(ans)
    return


if __name__ == '__main__':
    main()

Solution (Python):
import sys

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007


def main():
    N, *A = map(int, read().split())

    ans = 0
    p = 1
    for _ in range(60):
        n = 0
        for i in range(N):
            if A[i] % 2:
                n += 1
            A[i] //= 2
        ans = (ans + n * (N - n) * p) % MOD
        p = p * 2 % MOD

    print(ans)
    return


if __name__ == '__main__':
    main()

Solution (Python):
import sys

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007


def main():
    N, *A = map(int, read().split())

    ans = 0
    for i in range(60):
        s = 0
        for a in A:
            if a & (1 << i):
                s += 1
        tmp = 0
        for j in range(N):
            if A[j] & (1 << i):
                s -= 1
                tmp += (N - j - 1) - s
            else:
                tmp += s
        ans = (ans + tmp * pow(2, i, MOD)) % MOD

    print(ans)
    return


if __name__ == '__main__':
    main()

Solution (Python):
n = int(input())
a = list(map(int,input().split()))
tmp = [0]*61
MOD = 1_000_000_007
for i in range(n):
    for j in range(61):
        mask = 1<<j
        if a[i]&mask>0:
            tmp[j]+=1
ans = 0
for i in range(61):
    mask = 1<<i
    ans = (ans + mask*tmp[i]*(n-tmp[i])) % MOD
print(ans)

Solution (Python):
import numpy as np
n,*a = map(int,open(0).read().split())
a = np.array(a)
mod = 10**9+7
ans = 0
for i in range(61):
  b = np.count_nonzero(a>>i&1)
  ans += b*(n-b)*1<<i
print(ans%mod)

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

Solution (Python):
import queue
import numpy as np
import math

n = int(input())
A = list(map(int, input().split()))
A = np.array(A,np.int64)
ans = 0

for i in range(60 + 1):
    a = (A >> i) & 1
    count1 = np.count_nonzero(a)
    count0 = len(A) - count1
    ans += count1*count0 * pow(2, i)
    ans%=1000000007

print(ans)

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

count = 0

max = A[-1]
if max == 0:
	print(0)
	exit()

import math
V = [0]*(math.floor(math.log(max, 2))+1)

for i in range (0, N):
	B = A[i]
	vount = 0
	while B > 0:
		if B%2 == 0:
			B = B//2
			vount+=1			
		else:
			B = (B-1)//2
			V[vount]+=1
			vount+=1

for i in range (0, len(V)):
	count+=((V[i]*(N-V[i]))*(2**i))

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

Solution (Python):
import math
N = int(input())
A = list(map(int, input().split()))
bit = [0] * 60
MOD = 10 ** 9 + 7
for a in A:
    i = 0
    waru = 1
    while a > 0:
        if a % (waru * 2) != 0:
            a -= waru
            bit[i] += 1
        waru *= 2
        i += 1
answer = 0
for i, b in enumerate(bit):
    answer += (2 ** i) * (b * (N-b))
print(answer % MOD)

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


print(ans%mod)

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

ones = [0]*60
ans = 0
for i in range(n):
    x = l[i]
    for j in range(60):
        ones[j] += (x>>j)&1
    ans = (ans + (n-1)*x)%mod


for i in range(60):
    ans = (ans - ones[i]*(ones[i]-1)*2**i)%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
two = 1
for i in range(61):
    one = np.count_nonzero(a & 1)
    a = a >> 1
    ans = (ans + (one*(n-one))*two) % mod
    two = (two * 2) % mod
print(ans)

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

mod = 10**9 + 7
ans = 0
two = 1
for i in range(61):
    one = 0
    for j in range(n):
        if (a[j] >> i) & 1:
            one += 1
    ans = (ans + (one*(n-one))*two) % mod
    two = (two * 2) % mod
print(ans)

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

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




'''
a=[]
b=[]
for i in range():
    A, B = map(int, input().split())
    a.append(A)   
    b.append(B)'''
import numpy as np
n=int(input())
a = np.array([int(i) for i in input().split()])

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

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

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

def main():
    mod=10**9+7
    N=I()
    M=65
    A=LI()
    cnt=[0]*M
    
    for i in range(N):
        a=A[i]
        for j in range(M):
            if a>>j & 1:
                cnt[j]+=1
                
    ans=0
    for i in range(M):
        a=cnt[i]
        b=N-a
        ans=(ans + a*b*pow(2,i,mod))%mod
        
    print(ans)
                

main()

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

l=[0]*60
for i in A:
  for j in range(60):
    if i&(1<<j):l[j]+=1
ans=0
for i in range(60):
  ans+=l[i]*(N-l[i])*(1<<i)
  ans%=10**9+7
print(ans)

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

Solution (Python):
import numpy as np

N=int(input())
A=np.array([int(x) for x in input().split()])

ans=0
M=pow(10,9)+7
for i in range(100):
  one=int(np.sum((A>>i)&1))
  zero=N-one
  ans+=(one*zero)*pow(2,i)
  ans%=M
  
print(ans)

Solution (Python):
import numpy as np

N=int(input())
A=np.array([int(x) for x in input().split()])

ans=0
M=pow(10,9)+7
for i in range(100):
  one=int(np.sum((A>>i)&1))
  zero=N-one
  ans+=(one*zero)*pow(2,i,M)
  ans%=M
  
print(ans)

Solution (Python):
import numpy as np

N=int(input())
A=np.array([int(x) for x in input().split()])

ans=0
M=pow(10,9)+7
for i in range(100):
  one=np.sum((A>>i)&1)
  zero=N-one
  ans+=(one*zero)%M*pow(2,i,M)%M
  ans%=M
  
print(ans)

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

ans=0
for i in range(60):
  one=sum([a>>i&1 for a in A])
  zero=N-one
  ans+=(one*zero)*pow(2,i,M)%M
  ans%=M
  
print(ans)

Solution (Python):
N=int(input())
M=10**9+7

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

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

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

ans=p=0
for i in range(60):
  one=sum([a>>p&1 for a in A])
  zero=N-one
  p+=1
  ans+=(one*zero)*2**i
  ans%=M
  
print(ans)

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

b = [0] * 65

for i in range(N):
    bb = format(A[i], "060b")
    for j in range(60):
        if bb[j] == "1":
            b[j] += 1

ans = 0

for j in range(60):
    ans = (ans + b[j] * (N - b[j]) * pow(2, 59 - j, mod)) % mod

print(ans)

Solution (Python):
N = int(input())
A = list(map(int, input().split()))
res = 0
n = 0
quot = (10 ** 9) + 7
while 1:
  p = 0
  q = 0
  temp = 0
  for i, var in enumerate(A):
    if var % 2 == 1:
      p += 1
    else:
      q += 1
    A[i] = A[i] >> 1
    temp += var
  
  if temp == 0:
    break
  res += p*q*(2**n)
  res %= quot
  n += 1
print(res)

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

ans = 0

for i in range(61):
    cnt0 = 0
    cnt1 = 0
    for a in A:
        if (a>>i) & 1 == 0:
            cnt0 += 1
        else:
            cnt1 += 1
    ans += cnt0 * cnt1 * (2 ** i)
    ans %= mod

print(ans)

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

xor_num = [0]*m
for i in range(n):
    for j in range(m):
        if ((a[i] >> j) & 1):
            xor_num[j] += 1

b = 1
ans = 0
for i in range(m):
    ans += b*xor_num[i]*(n-xor_num[i])
    b *= 2
    b %= mod
print(ans%mod)

Solution (Python):
N = int(input())
A = list(map(int, input().split()))
P = int(1e9+7)
max_log_2 = 60
k_zyo=[0] * max_log_2
k_2=[1]*max_log_2
for i in range(1, max_log_2):
    k_2[i] = k_2[i-1]*2
for a in A:
    for i in range(max_log_2):
        k_zyo[i] += (a // (k_2[i])) % 2

ans = 0
for a in A:
    for i in range(max_log_2):
        if (a // (k_2[i])) % 2 == 0:
            ans = (ans + k_zyo[i] * k_2[i]) % P
print(ans)

Solution (Python):
n=int(input())
p=10**9+7
a=list(map(int,input().split()))
bit=[0]*61
for i in range(n):
    b=bin(a[i])[2:].zfill(61)
    for j in range(61):
        if b[j]=="1":
            bit[j]+=1
ans=0
for i in range(61):
    x=bit.pop()
    ans+=x*(n-x)*(2**i)%p
print(ans%p)

Solution (Python):

import collections as cl
import sys


def II():
    return int(sys.stdin.readline())


def MI():
    return map(int, sys.stdin.readline().split())


def LI():
    return list(map(int, sys.stdin.readline().split()))


MOD = 10 ** 9 + 7


def main():
    N = II()
    targets = LI()

    ttl_bins = [0]*60
    for i in range(N):
        target = targets[i]
        target_str = format(target, f"0{60}b")
        for keta in range(60):
            ttl_bins[keta] += int(target_str[keta])

    ans = 0
    for i in range(60):
        ttl = ttl_bins[i] * (N - ttl_bins[i])
        ans += pow(2, 59-i, MOD) * ttl
        ans %= MOD

    print(ans)


main()

Solution (Python):
def nishin(n):
  return str(bin(n)[2:])[::-1]
N=int(input())
L=list(map(int,input().split()))
mod=1000000007
ans=sum(L)*(N-1)
c=[0]*61
for i in L:
  i=nishin(i)
  for j in range(len(i)):
    if i[j]=="1":
      c[j]+=1
for i in range(61):
  ans-=(pow(2,i,mod)*c[i]*(c[i]-1))%mod
print(ans%mod)

Solution (Python):

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

    ans = 0
    for i in range(60):
        p = 1 << i
        one = sum([1 for a in A if a & p])
        zero = N - one
        ans += p * one * zero
        ans %= MOD
    print(ans)


if __name__ == "__main__":
    resolve()