Problem:
 Score : 400 points    Problem Statement We have N integers. The i -th integer is A_i .  Find \sum_{i=1}^{N-1}\sum_{j=i+1}^{N} (A_i \mbox{ XOR } A_j) , modulo (10^9+7) .   What is \mbox{ XOR } ?  The XOR of integers A and B , A \mbox{ XOR } B , is defined as follows:  When A \mbox{ XOR } B is written in base two, the digit in the 2^k 's place ( k \geq 0 ) is 1 if either A or B , but not both, has 1 in the 2^k 's place, and 0 otherwise.  For example, 3 \mbox{ XOR } 5 = 6 . (In base two: 011 \mbox{ XOR } 101 = 110 .)       Constraints  2 \leq N \leq 3 \times 10^5  0 \leq A_i < 2^{60}  All values in input are integers.         Input Input is given from Standard Input in the following format:  N  A_1  A_2  ...  A_N       Output Print the value \sum_{i=1}^{N-1}\sum_{j=i+1}^{N} (A_i \mbox{ XOR } A_j) , modulo (10^9+7) .        Sample Input 1 3
1 2 3      Sample Output 1 6  We have (1\mbox{ XOR } 2)+(1\mbox{ XOR } 3)+(2\mbox{ XOR } 3)=3+2+1=6 .       Sample Input 2 10
3 1 4 1 5 9 2 6 5 3      Sample Output 2 237       Sample Input 3 10
3 14 159 2653 58979 323846 2643383 27950288 419716939 9375105820      Sample Output 3 103715602  Print the sum modulo (10^9+7) .

Solution (Python):
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
 
import collections
mod = 10 ** 9 + 7
 
N = int(readline())
A = [int(i) for i in readline().split()]
 
answer = 0
for n in range(62):
    B = [(i >> n) & 1 for i in A]
    C = collections.Counter(B)
    x = C[1]
    y = N - x
    x *= y
    for _ in range(n):
        x *= 2
        x %= mod
    answer += x
    answer %= mod
print(answer)

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

def binary(n):
    return bin(n)[2:]

def pow_by_binary(a, x, n): 
    x = [int(b) for b in binary(x)]
    y = a
    for i in range(1, len(x)):
        y = (y**2) % n
        if x[i] == 1:
            y = (y * a) % n
    return y 
  
mod = 10 ** 9 + 7
 
N = int(readline())
A = [int(i) for i in readline().split()]
 
answer = 0
for n in range(62):
    B = [(i >> n) & 1 for i in A]
    C = collections.Counter(B)
    x = C[1]
    y = N - x
    x *= y
    if n >= 1:
      x = x*pow_by_binary(2,n,mod)
    x %= mod
    answer += x
    answer %= mod
print(answer)

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

    N = int(input())
    *a, = map(int, input().split())

    b = [0] * 60
    for x in a:
        for j in range(60):
            b[j] += (x & 1) > 0
            x >>= 1

    t = 1
    ans = 0
    for j in range(60):
        ans = (ans + b[j] * (N - b[j]) * t) % MOD
        t <<= 1
    print(ans)


if __name__ == '__main__':
    main()

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


def main():    
    MOD = 10 ** 9 + 7
    n = int(readline())
    a = list(map(int, readline().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
        ans %= MOD
    print(ans)


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(60):
    x = 0
    for j in range(n):
        if a[j] >> i & 1:
            x += 1
    ans += x * (n - x) * 2 ** i
    ans %= MOD
print(ans)

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

Solution (Python):
n = int(input())
*A, = map(int, input().split())
p = 10**9+7
A = [format(a, '060b') for a in A]
s = 0
for i in range(60):
    Ai = [a[i] for a in A]
    c0 = Ai.count('0')
    c1 = n-c0
    c = c0*c1
    s = (s+c*(2**(59-i))) % p
print(s)

Solution (Python):
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
input = sys.stdin.readline

N = int(input())
A = list(map(int, input().split()))
x = [0] * 60
y = [0] * 60
for a in A:
    for i in range(60):
        if a >> i & 1:
            x[i] += 1
        else:
            y[i] += 1
ans = 0
mod = 10**9 + 7
for i in range(60):
    ans += x[i] * y[i] * (1 << i) % mod
    ans %= mod
print(ans)

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

    M = max(A)
    L = M.bit_length()
    ans = 0
    mod = 10**9 + 7
    k = [0]*max(1, L)
    k[0] = 1
    for i in range(1, L):
        k[i] = k[i-1]*2
    for j in range(L):
        count = 0
        for x in A:
            if (x >> j) % 2 == 1:
                count += 1
        ans += count*(N - count)*k[j]
    ans %= mod
    print(ans)


main()

Solution (Python):
import sys
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def LIST(): return list(map(int, input().split()))
mod = 10 ** 9 + 7

n = INT()
a = LIST()
arr = [0 for _ in range(61)]
for i in range(n):
    ai = a[i]
    for j in reversed(range(61)):
        arr[j] += ai % 2
        ai //= 2
ans = 0
for i in range(61):
    ans *= 2
    arri = arr[i]
    ans += arri * (n - arri if arri != 0 else 0)
    ans %= mod
print(ans)

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

Solution (Python):
from collections import Counter,defaultdict,deque
from heapq import heappop,heappush,heapify
import sys,bisect,math,itertools,fractions
from decimal import Decimal
sys.setrecursionlimit(10**8)
mod = 10**9+7
INF = float('inf')
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))

n = inp()
a = inpl()
a.sort()
lmx = len(bin(a[-1])) - 2
cnt = [[0,0] for _ in range(lmx)]
for i in a:
    for j in range(lmx):
        tt = 1 if (i>>j)&1 else 0
        cnt[j][tt] += 1

res = 0
for i,bit in enumerate(cnt):
    x,y = bit
    res += x*y*pow(2,i)
    res %= mod
print(res)

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

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

ans = 0
for d in range(62):
    mask = (1 << d)
    zero = len([0 for a in A if (a & mask) == 0])
    ans += zero * (N - zero) * mask % MOD
print(ans % MOD)

Solution (Python):
from collections import *
from heapq import *
import sys

sys.setrecursionlimit(10 ** 5)
int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep="\n")
def II(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def MI1(): return map(int1, sys.stdin.readline().split())
def LI(): return list(map(int, sys.stdin.readline().split()))
def LI1(): return list(map(int1, sys.stdin.readline().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def SI(): return sys.stdin.readline()[:-1]
dij = [(1, 0), (-1, 0), (0, 1), (0, -1)]

class mint:
    def __init__(self, x):
        self.__x = x % md

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

    def __neg__(self):
        return mint(-self.__x)

    def __add__(self, other):
        if isinstance(other, mint): other = other.__x
        return mint(self.__x + other)

    def __sub__(self, other):
        if isinstance(other, mint): other = other.__x
        return mint(self.__x - other)

    def __rsub__(self, other):
        return mint(other - self.__x)

    def __mul__(self, other):
        if isinstance(other, mint): other = other.__x
        return mint(self.__x * other)

    __radd__ = __add__
    __rmul__ = __mul__

    def __truediv__(self, other):
        if isinstance(other, mint): other = other.__x
        return mint(self.__x * pow(other, md - 2, md))

    def __rtruediv__(self, other):
        return mint(other * pow(self.__x, md - 2, md))

    def __pow__(self, power, modulo=None):
        return mint(pow(self.__x, power, md))

md = 10**9+7

def main():
    ans=mint(0)
    n=II()
    aa=LI()
    for i in range(61):
        cnt1=0
        for a in aa:cnt1+=a>>i&1
        ans+=(1<<i)*cnt1*(n-cnt1)
    print(ans)

main()

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

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

for i in range(0,N):
    for j in range(0,60):
        data[j]+=(A[i]>>j &1)

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

print(ans)

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

def main():
    N = int(input())
    A = list(map(int, input().split()))
    
    max_bin_digits = len(bin(max(A))[2:])
    ans = 0
    for i in range(max_bin_digits):
        cnt = 0
        m = 1 << i
        for a in A:
            if m & a:
                cnt += 1
        
        ans += cnt * (N - cnt) * m
        ans %= MOD

    print(ans)


if __name__ == "__main__":
    main()

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

def main():
    N = int(input())
    A = list(map(int, input().split()))
    
    max_bin_digits = len(bin(max(A))[2:])
    ans = 0
    for i in range(max_bin_digits):
        cnt = 0
        for a in A:
            if 1 << i & a:
                cnt += 1
        ans += cnt * (N - cnt) * 2 ** i
        ans %= MOD

    print(ans)

if __name__ == "__main__":
    main()

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

def main():
    N = int(input())
    A = list(map(int, input().split()))
    
    max_bin_digits = len(bin(max(A))[2:])
    cnts = [0] * max_bin_digits

    for a in A:
        for i in range(max_bin_digits):
            if 1 << i & a:
                cnts[i] += 1

    ans = 0
    for i in range(max_bin_digits):
        ans += cnts[i] * (N - cnts[i]) * 2 ** i
        ans %= MOD

    print(ans)


if __name__ == "__main__":
    main()

Solution (Python):


int1 = lambda x: int(x) - 1
def II(): return int(input())

def MI(): return map(int, input().split())
def MI1(): return map(int1, input().split())

def LI(): return list(map(int, input().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]

import numpy as np

def solve():
    n = II()
    A = np.array(LI())
    
    mod = 1000000007
    ans = 0
    for i in range(0, 61):
        
        x = np.count_nonzero(A & 1)
        y = n - x       
        
        
        ans = ans + pow(2, i) * x * y % mod
        A = A >> 1
    print(ans % mod)



if __name__ == '__main__':
    solve()

Solution (Python):


int1 = lambda x: int(x) - 1
def II(): return int(input())

def MI(): return map(int, input().split())
def MI1(): return map(int1, input().split())

def LI(): return list(map(int, input().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]

import numpy as np

def solve():
    n = II()
    A = np.array(LI())
    
    mod = 1000000007
    ans = 0
    for i in range(0, 61):
        
        x = np.count_nonzero((A >> i) & 1)
        y = n - x       
        
        
        ans = ans + pow(2, i) * x * y % mod
        
    print(ans % mod)



if __name__ == '__main__':
    solve()

Solution (Python):


int1 = lambda x: int(x) - 1
def II(): return int(input())

def MI(): return map(int, input().split())
def MI1(): return map(int1, input().split())

def LI(): return list(map(int, input().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]


def solve():
    n = II()
    A = LI()
    
    mod = 1000000007
    ans = 0
    for i in range(0, 61):
        
        x = 0
        for a in A:
            if (a >> i) & 1:
                x += 1
        y = n - x       
        
        
        ans = ans + pow(2, i) * x * y % mod
    print(ans % mod)



if __name__ == '__main__':
    solve()

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

ans=0
for i in range(60):
    if bittable[i]!=0:
        ans=(ans+((N-bittable[i])*bittable[i]*pow(2,i,p))%p)%p
print(ans)

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

M = max(A)
m = M
a = 1
while m // 2 != 0:
  m = m//2
  a += 1


b = 0
for i in range(a):
  c = 0
  for j in range(N):
    c += (A[j] & 2**i)//(2**i)  
  b = (b + c*(N-c)*pow(2,i,10**9+7)) % (10**9+7)
  
print(b)

Solution (Python):
n = int(input())
l = [int(x) for x in input().split()]
MOD = 1000000007
ans = 0
for d in range(60):
    ones = 0
    for a in l:
        if a >> d & 1:
            ones += 1
    zeroes = n - ones
    ans += pow(2, d, MOD) * ones % MOD * zeroes % MOD
    ans %= MOD
print(ans)

Solution (Python):
def main():
    import sys
    input = sys.stdin.readline
    _ = int(input())
    A = [int(x) for x in input().strip().split()]
    MOD = 10 ** 9 + 7
    ans = 0

    for i in range(60+1):
        zero = 0
        one = 0
        m = 1 << i
        for a in A:
            if a & m:
                one += 1
            else:
                zero += 1
        ans += (one * zero) * m
        ans = ans % MOD
    print(ans % MOD)

if __name__ == '__main__':
    main()

Solution (Python):
n = int(input())
a = list(map(int, input().split()))
mod = 10**9+7
result = [0 for _ in range(120)]
for i in a:
    x = format(i, "060b")[::-1]
    for j in range(60):
        result[j] = result[j]+(x[j]=="1")
result = [(n-i)*i for i in result]
for i in range(119):
    result[i+1] += result[i]//2
    result[i] = result[i]%2    
print(int("".join(map(str, result[::-1])), 2)%mod)

Solution (Python):
import numpy as np

n = int(input())
arr = np.array([int(i) for i in input().split()])
mod = 10 ** 9 + 7
s = 0

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

print(s % mod)

Solution (Python):
import numpy as np
import sys
n = int(input())
a = np.array(sys.stdin.read().split(), dtype=np.int64)
mod = 10 ** 9 + 7
ans = 0
for i in range(63):
    b = (a >> i) & 1
    x = np.count_nonzero(b)
    x = x * (n - x)
    ans += x * pow(2, i, mod) % mod
print(ans % mod)

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

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

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

ans = 0
for i in bit_num[::-1]:
    ans *= 2
    ans += i
    ans %= mod

print(ans)

Solution (Python):
N = int(input())
A = list(map(int, input().split()))
mod = int(1e9+7)
A.sort(reverse=True)
for i in range(N):
    A[i] = format(A[i], 'b')
    A[i] = A[i].zfill(len(A[0]))
ans = 0
for i in range(len(A[0])):
    count_1 = 0
    count_0 = 0
    for a in A:
        if a[i] == '0':
            count_0 += 1
        else:
            count_1 += 1
    ans += count_0 * count_1 * pow(2, len(A[0])-i-1, mod) 
    ans %= mod
print(ans)

Solution (Python):
import numpy as np
import sys

def main():
  input = sys.stdin.readline
  n = int(input())
  a = np.array([int(x) for x in input().split()])
  inf = pow(10, 9)+7
  max_a = np.max(a)
  bit = 1
  ans = 0
  num = 0
  while max_a:
    num += 1
    max_a //= 2
  for _ in range(num):
    bit_count = np.sum(a%2)
    ans += ((((bit_count%inf)*((n-bit_count)%inf))%inf)*(bit%inf))%inf
    ans %= inf
    a //= 2
    bit *= 2
  print(ans)
  
if __name__ == "__main__":
  main()

Solution (Python):
n = int(input())
l = list(map(int, input().split()))
num_one = [0 for i in range(61)]
num_zero = [0 for i in range(61)]
for num in l:
    for i in range(61):
        if (num>>i)&1 == 1:
            num_one[i] +=1
        else:
            num_zero[i] +=1
ans  = 0
for i in range(61):
    ans += (num_one[i] *num_zero[i])%(10**9+7) * (2**i%(10**9+7))
    ans = ans%(10**9+7)
print(ans)

Solution (Python):
from scipy.sparse.csgraph import shortest_path, floyd_warshall, dijkstra, bellman_ford, johnson, minimum_spanning_tree
from scipy.sparse import csr_matrix, coo_matrix, lil_matrix
import numpy as np
from collections import deque, Counter, defaultdict
from itertools import product, permutations,combinations
from operator import itemgetter
from heapq import heappop, heappush
from bisect import bisect_left, bisect_right, bisect
from fractions import gcd
from math import ceil,floor, sqrt, cos, sin, pi, factorial
from functools import reduce
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10**8)
INF = float('inf')
MOD = 10**9+7
def lcm_base(a, b):
    return (a * b) // gcd(a, b)

def lcm_list(numbers):
    return reduce(lcm_base, numbers, 1)


def main():
  N = int(readline())
  A = np.array(read().split(), np.int64)
  ans = 0
  for i in range(63):
    B = (A>>i)&1
    x = np.count_nonzero(B)
    y = N - x
    x = x*y
    for _ in range(i):
      x *= 2
      x %= MOD
    ans += x
  ans %= MOD
  print(ans)
  
  
  
  
if __name__ == '__main__':
  main()

Solution (Python):
MOD = 10**9 + 7
class ModInt:
    def __init__(self, x):
        if isinstance(x, str):
            x = int(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 calc(N, A, max_k):
    ret = ModInt(0)
    for k in range(max_k):
        count = 0
        for i in A:
            if i & (1 << k):
                count += 1
        ret += 2 ** k * count * (N - count)
    return ret

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

print(calc(N, A, max_k))

Solution (Python):
MOD, res = int(1E9 + 7), 0
n = int(input())
a = list(map(int, input().split()))
for i in range(60):
    cnt = 0
    for j in a:
        if j & (1 << i):
            cnt += 1
    res = (res + cnt * (n - cnt) * pow(2, i, MOD)) % MOD
print(res)

Solution (Python):
n = int(input())
a = [int(x) for x in input().split()]
MOD = 1000000007
ans = 0
for digit in range(60):
    ones = 0
    for num in a:
        if num >> digit & 1:
            ones += 1
    zeroes = n - ones  
    ans = (ans + ones * zeroes * pow(2, digit, MOD)) % MOD

print(ans)

Solution (Python):
ii = lambda : int(input())
mi = lambda : map(int,input().split())
li = lambda : list(map(int,input().split()))

n = ii()
alis = li()
import numpy as np
A = np.array(alis,dtype=np.int64)
b = [0] * 61
count = 0
ans = 0
MOD = 10**9 + 7
while A.any():
    one = np.count_nonzero(A & 1)
    k = (1<<count) % MOD
    
    ans += (one * (n - one)) * k % MOD
    ans %= MOD
    A >>= 1
    count += 1
 
print(ans)

Solution (Python):
import numpy as np
mod=10**9+7
N=int(input())
A=np.array(list(map(int, input().split())))
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 sys

import numpy as np

input = sys.stdin.readline
P = 10 ** 9 + 7


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

    ans = 0
    for b in range(60 + 1):
        cnt_1 = int(np.sum((A >> b) & 1))
        ans += 2 ** b * cnt_1 * (N - cnt_1)
        ans %= P
    print(ans)


if __name__ == "__main__":
    main()

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

Solution (Python):
n=int(input())
a=list(map(int,input().split()))
b=[0]*64
for i in range(n):
    for j in range(a[i].bit_length()):
        if a[i]>>j & 1: b[j]+=1
c=0
for i in range(64):
    c+=(b[i]*(n-b[i])*2**i) % 1000000007
print(c%1000000007)

Solution (Python):
import math,itertools,fractions,heapq,collections,bisect,sys,queue,copy

sys.setrecursionlimit(10**7)
inf=10**20
mod=10**9+7
dd=[(-1,0),(0,1),(1,0),(0,-1)]
ddn=[(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def LS(): return sys.stdin.readline().split()
def S(): return input()

def main():
  k=[0]*60
  n=I()
  l=LI()

  for x in l:
    _a=bin(x)[2:]
    a=_a.zfill(60)

    for i,y in enumerate(a):
      if y=='1':
        k[59-i]+=1

  ans=0
  for i,x in enumerate(k):
    ans+=(n-x)*x*(2**i)
    ans%=mod

  return ans%mod


print(main())

Solution (Python):


import sys
import math













def main():
    mod = 1000000007                  
    inf = float('inf')
    sys.setrecursionlimit(10**6)    
    def input(): return sys.stdin.readline().rstrip()
    def ii():  return int(input())
    def mi():  return map(int, input().split())
    def mi_0(): return map(lambda x: int(x)-1, input().split())
    def lmi(): return list(map(int, input().split()))
    def lmi_0(): return list(map(lambda x: int(x)-1, input().split()))
    def li():  return list(input())
    
    
    n = ii()
    a = lmi()
    m = max(a)
    
    if m == 0:
        print(0)
        exit(0)

    ans = 0
    for shift in range(int(math.log(m, 2)+1)):    
        mask = 0b1 << shift
        
        count_one = tuple(map(lambda x: (x&mask)>>shift, a)).count(1)
        ans = (ans + int(pow(2, shift, mod)) * count_one * (n - count_one)) % mod
        
    print(ans)
    


if __name__ == "__main__":
    main()

Solution (Python):
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)

import numpy as np

n = int(readline())
a = np.array(read().split(), np.int64)
ans = 0
mod = 10 ** 9 + 7
for i in range(63):
    b = (a >> i) & 1
    x = np.count_nonzero(b)
    y = n - x
    x *= y
    for j in range(i):
        x *= 2
        x %= mod
    ans += x
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):
    one = np.count_nonzero(a >> i & 1)
    zero = n - one
    ans += one * zero * 2 ** i
    ans %= MOD

print(ans)

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

ans = 0
m = 1

for i in range(60):
    
    
    
    one = sum(a_e & m for a_e in a)
    one //= m
    zero = n - one
    ans += one * zero * m
    ans %= MOD
    
    m <<= 1

print(ans)

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

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

Solution (Python):
n = int(input())
a = [int(i) for i in input().split()]
mod = 10**9+7
ans = 0
m = max(a)
x = 0
while m > 0:
    m >>= 1
    x += 1 

for i in range(x):
    cnt = 0
    for j in range(n):
        if a[j]>>i & 1 == 0: cnt += 1
    ans = (ans+pow(2,i,mod)*cnt%mod*(n-cnt)%mod)%mod
    
print(ans)

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

Solution (Python):
import numpy as np
mod=10**9+7
N=int(input())
A=np.array(list(map(int, input().split())))
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):
n = int(input())
a = list(map(int, input().split()))

bits = [0] * 60
for d in a:
    for i in range(60):
        if d % 2 == 1:
            bits[i] += 1
        d >>= 1
        if d == 0:
            break

total = 0
mod = 10 ** 9 + 7
for i in range(60):
    total += (2 ** i) * (bits[i] * (n - bits[i]))
    total %= mod
print(total)

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

ans = 0
for i in range(60):
    c = sum([1 for ai in a if (ai >> i) & 1])
    ans += (1 << i) * c * (n-c)
    ans %= mod
print(ans)

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

for i in A:
    b = i
    tmp = 0
    while(b):
        digit[tmp] += b & 1
        tmp += 1
        b >>= 1

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

print(ans)

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

mx=0
for num in nums:
    if num>mx:
        mx=num

j=0
ans=0
while 2**j<=mx:
    sm=0
    for num in nums:
        sm+= num>>j &1
    ans+=(sm)*(n-sm)*2**j
    j=j+1

print(ans%1000000007)

Solution (Python):
n = int(input())
a = list(map(int,input().split()))
x = [0 for i in range(62)]
for i in range(n):
    b = bin(a[i])
    for i in range(len(b)-2):
        if b[-1-i] == '1':
            x[-i-1] += 1
mod = 10**9+7
ans = 0
two = 1
for i in range(1,62):
    ans = (ans + x[-i]*(n-x[-i])*two)%mod
    two = two*2%mod
print(ans)

Solution (Python):
def main():
    import sys
    input = sys.stdin.readline
    sys.setrecursionlimit(10**7)
    from collections import Counter, deque
    
    from itertools import combinations, permutations, accumulate, groupby
    
    from bisect import bisect_left,bisect_right
    from heapq import heapify, heappop, heappush
    from math import floor, ceil
    

    
    mod = 10**9 + 7

    n = int(input())
    a = list(map(int, input().split()))
    res = 0
    for i in range(60):
        cnt = 0
        for j in a:
            if (j>>i) & 1:
                cnt += 1
        res += ((cnt*(n-cnt))*2**i) % mod
    print(res%mod)

if __name__ == '__main__':
    main()

Solution (Python):
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**7)
from collections import Counter, deque

from itertools import combinations, permutations, accumulate, groupby

from bisect import bisect_left,bisect_right
from heapq import heapify, heappop, heappush
from math import floor, ceil



mod = 10**9 + 7

n = int(input())
a = list(map(int, input().split()))
res = 0
for i in range(60):
    cnt = 0
    for j in a:
        if (j>>i) & 1:
            cnt += 1
    res += ((cnt*(n-cnt))*2**i) % mod
print(res%mod)

Solution (Python):
import numpy as np

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

while A.any():
    one = np.count_nonzero(A & 1)
    ans += (one * (N - one) * pow(2, digit, MOD))
    ans %= MOD
    A >>= 1
    digit += 1

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
digit = 0

while A.any():
    one = np.count_nonzero(A & 1)
    ans += (one * (N - one) * pow(2, digit, MOD)) % MOD
    ans %= MOD
    A >>= 1
    digit += 1

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 digit in range(60):
    one = np.count_nonzero(A & 1)
    ans += (one * (N - one) * pow(2, digit, MOD)) % MOD
    ans %= MOD
    A >>= 1

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

max_digit = len(bin(max(A))) - 2

for digit in range(max_digit):
    one = np.count_nonzero((A >> digit) & 1)
    ans += (one * (N - one) * pow(2, digit, MOD)) % MOD
    ans %= 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 digit in range(60):
    one = np.count_nonzero((A >> digit) & 1)
    ans += (one * (N - one) * pow(2, digit, MOD)) % MOD
    ans %= MOD

print(ans)

Solution (Python):
mod=10**9+7
N=int(input())
A = list(map(int,input().split()))
B=[0]*N
for i in range(N):
 B[i]=str(bin(A[i]))
f=0
for i in range(2,62):
 d=0
 e=0
 for j in range(N):
  g=62-len(B[j])
  if i<g:
   e+=1
  elif B[j][i-g]=="1":
   d+=1
  else:
   e+=1
 f+=(d*e*pow(2,61-i,mod))%mod
 f%=mod
print(f)

Solution (Python):
mod=10**9+7
N=int(input())
A = list(map(int,input().split()))
B=[0]*N
for i in range(N):
 B[i]=str(bin(A[i])).rjust(62,"0")
f=0
for i in range(2,62):
 d=0
 e=0
 for j in range(N):
  if B[j][i]=="1":
   d+=1
  else:
   e+=1
 f+=(d*e*pow(2,61-i,mod))%mod
 f%=mod
print(f)

Solution (Python):
mod=10**9+7
N=int(input())
A = list(map(int,input().split()))
B=[0]*N
for i in range(N):
 B[i]=str(bin(A[i])).rjust(62,"0")
f=0
for i in range(2,62):
 d=0
 e=0
 for j in range(N):
  c=B[j]
  if c[i]=="1":
   d+=1
  else:
   e+=1
 f+=(d*e*pow(2,61-i,mod))%mod
 f%=mod
print(f)

Solution (Python):
mod=10**9+7
N=int(input())
A = list(map(int,input().split()))
B=[0]*N
for i in range(N):
 B[i]=str(bin(A[i])).rjust(62,"0")
f=0
for i in range(2,62):
 d=0
 e=0
 for j in range(N):
  c=B[j]
  if c[i]=="1":
   d+=1
  else:
   e+=1
 f+=d*e*pow(2,61-i,mod)
 f%=mod
print(f)

Solution (Python):
import sys
input=sys.stdin.readline
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)