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())
As = list(map(int, input().split()))
P = 10**9 + 7

rlt = 0
pw = 1
for i in range(61):
  c0 = 0
  c1 = 0
  for j in range(N):
    a = As[j]
    if a % 2 == 0:
      c0 += 1
    else:
      c1 += 1
    As[j] = a//2
  rlt += c0*c1*pw % P
  rlt %= P
  pw *= 2
  
print(rlt)

Solution (Python):
import numpy as np
n=int(input())
arr = np.array([int(i) for i in input().split()])
mod = 10**9+7
sm=0

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

print(sm%mod)

Solution (Python):
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians, log2
from itertools import accumulate, permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

N = INT()
A = LIST()

n = max(A).bit_length()

cnt = [0]*n

for x in A:
	for i, y in enumerate("{:b}".format(x).zfill(n)[::-1]):
		if y == "1":
			cnt[i] += 1

ans = 0

for i, c in enumerate(cnt):
	bit_sum = (c*(N-c)%mod) * pow(2, i, mod) % mod
	ans = (ans+bit_sum)%mod

print(ans)

Solution (Python):
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians, log2
from itertools import accumulate, permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

N = INT()
A = LIST()

n = max(A).bit_length()

cnt = [[0, 0] for _ in range(n)]

for x in A:
	x = "{:b}".format(x).zfill(n)
	for i in range(n):
		cnt[i][int(x[-(i+1)])] += 1

ans = 0

for i in range(n):
	bit_sum = ((cnt[i][0]*cnt[i][1])%mod) * pow(2, i, mod) % mod
	ans = (ans+bit_sum)%mod

print(ans)

Solution (Python):
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians, log2
from itertools import accumulate, permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

N = INT()
A = LIST()

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

for x in A:
	x = "{:b}".format(x).zfill(n)
	for i in range(n):
		cnt[i][int(x[-(i+1)])] += 1

ans = 0

for i in range(n):
	bit_sum = ((cnt[i][0]*cnt[i][1])%mod) * pow(2, i, mod) % mod
	ans = (ans+bit_sum)%mod

print(ans)

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 >>= 1

print(s % mod)

Solution (Python):
MOD = 10**9+7
def resolve():
    N = int(input())
    A = list(map(lambda x: bin(int(x))[2:].zfill(60), input().split()))
    ans = 0
    for i in range(60):
        one_cnt = 0
        zero_cnt = 0
        for a in A:
            if a[i] == "1":
                one_cnt += 1
            else:
                zero_cnt += 1
        ans += (one_cnt*zero_cnt)*(2**(59-i))
        ans %= MOD
    print(ans)

    

if '__main__' == __name__:
    resolve()

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

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

num_per_digit = [0]*60

for i in range(60):
    num = 0
    for j,a in enumerate(A):
        num += a % 2
        A[j] //= 2
    num_per_digit[i] = num

result = 0    
for d,num in enumerate(num_per_digit):
    result = (result + num * (N - num) * pow(2, d, MOD)) % MOD
    
print(result)

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

def main(n,a):
    MOD=10**9+7
    hist=[0]*61
    bs=[]
    for i in range(n):
        
        
        
        
        

        s=bin(a[i])[2:]
        bs.append(s)
        for j in range(len(s)):
            if s[j]=='1':
                hist[len(s)-j-1]+=1
        
        
        
        
        
        
        


    
    
    sum=0
    for i in range(n-1):
        s=bs[i]
        b=1
        for j in range(len(s)):
            if s[len(s)-1-j]=='0':
                sum=(sum+hist[j]*b)%MOD
            else:
                sum=(sum+( n-i-hist[j] )*b)%MOD
                hist[j]-=1
            b*=2
        for j in range(len(s),61):
            sum=(sum+hist[j]*b)%MOD
            b*=2
    
    
    
    

    return sum

if __name__=='__main__':
    n,l=readinput()
    ans=main(n,l)
    print(ans)

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

def main(n,a):
    MOD=10**9+7
    hist=[0]*61
    bs=[]
    for i in range(n):
        
        
        
        
        

        s=bin(a[i])[2:]
        for j in range(len(s)):
            if s[j]=='1':
                hist[len(s)-j-1]+=1
        
        
        
        
        
        
        


    
    
    sum=0
    
    
    
    
    
    
    
    
    
    
    
    
    
    b=1
    for j in range(61):
        sum=(sum+( hist[j]*(n-hist[j])*b )%MOD )%MOD
        b*=2

    return sum

if __name__=='__main__':
    n,l=readinput()
    ans=main(n,l)
    print(ans)

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

def main(n,a):
    MOD=10**9+7
    hist=[0]*61
    bs=[]
    for i in range(n):
        
        
        
        
        
        s=bin(a[i])[2:]
        for j in range(len(s)):
            if s[j]=='1':
                hist[len(s)-j-1]+=1

    
    
    sum=0
    
    
    
    
    
    
    
    
    
    
    
    
    
    b=1
    for j in range(61):
        sum=(sum+( hist[j]*(n-hist[j])*b )%MOD )%MOD
        b*=2

    return sum

if __name__=='__main__':
    n,l=readinput()
    ans=main(n,l)
    print(ans)

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


ans, num = 0,1
for i in range(60):
    cnt = sum((ai & num) == num for ai in a)
    ans += (cnt * (n - cnt) * num) % mod
    num <<= 1
print(ans % mod)

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


ans, num = 0,1
for i in range(60):
    cnt = sum((ai & num) >> i for ai in a)
    ans += (cnt * (n - cnt) * num) % mod
    num <<= 1
print(ans % mod)

Solution (Python):


for i in range(pow(10,6)):
    pass

n = int(input())
a = list(map(int,input().split()))
d = 0
m = 10**9+7
for i in range(60):
    b = 1<<i
    l = len([1for j in a if j&b])
    d += l*(n-l)*b%m
    d %= m
print(d)

Solution (Python):
from collections import defaultdict
N = int(input())
A = list(map(int, input().split()))
INF = 10 ** 9 + 7

D = defaultdict(int)
for a in A:
    for i in range(61):
        
        D[1 << i] += bool(a & (1 << i))

ans = 0
for key, value in D.items():
    ans += key * value * (N - value)
    ans %= INF

print(ans % INF)

Solution (Python):
import sys
import numpy as np
def input(): return sys.stdin.readline().rstrip()
 
def main():
    n=int(input())
    A=np.array(list(map(int, input().split())),dtype='int64')
    ans = 0
    mod = 10**9 + 7
    for i in range(60):
        q = int((A >> i & 0b1).sum())
        ans += q*(n-q)*pow(2, i, mod)
        ans %= mod
    print(ans)
 
if __name__=='__main__':
    main()

Solution (Python):
import bisect, collections, copy, heapq, itertools, math, string, sys
input = lambda: sys.stdin.readline().rstrip() 
sys.setrecursionlimit(10**7)
INF = float('inf')
MOD = 10 ** 9 + 7
def I(): return int(input())
def F(): return float(input())
def SS(): return input()
def LI(): return [int(x) for x in input().split()]
def LI_(): return [int(x)-1 for x in input().split()]
def LF(): return [float(x) for x in input().split()]
def LSS(): return input().split()

def resolve():
    N = I()
    A = LI()

    

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

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

    print(ans)

if __name__ == '__main__':
    resolve()

Solution (Python):
import sys
def input(): return sys.stdin.readline().rstrip()
 
def main():
    n=int(input())
    A=list(map(int, input().split()))
    ans = 0
    mod = 10**9 + 7
    for i in range(60):
        q = sum(map(lambda x:((x >> i) & 0b1),A))
        ans += q*(n-q)*pow(2, i, mod)
        ans = ans % mod
    print(ans)
 
if __name__=='__main__':
    main()

Solution (Python):
import sys,math,collections,itertools
input = sys.stdin.readline

N = int(input())
A = list(map(int,input().split()))
m = 10**9+7
sumA = 0
for i in range(60):
    cnt1 = 0
    for a in A:
        if a>>i & 1:
            cnt1 += 1
    sumA += (cnt1*(N-cnt1)*2**i)%m
print(sumA%m)

Solution (Python):
import numpy as np

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

a = np.array(a, dtype='int64')
MOD = 10**9+7
ans = 0
for i in range(60):
    ca = a >> i & 1
    c1 = int(ca.sum())
    c0 = n - c1
    c0c1 = (c0 * c1) % MOD
    c0c1pow = (c0c1 * 2**i) % MOD
    ans = (ans + c0c1pow) % MOD
print(ans)

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

mod=10**9+7
ans=0

for i in range(61):
    x=0
    for j in range(N):
        if A[j]>>i&0b1:
            x+=1
    now=x*(N-x)%mod
    for j in range(i):
        now=now*2%mod
    ans+=now
    ans%=mod

print(ans)

Solution (Python):
import numpy as np

N = int(input())
A = tuple(map(int, input().split(' ')))
A = np.array(A, dtype=np.int64)
MOD = 10 ** 9 + 7

ans = 0
mask = 1

for i in range(60):
    ones = np.count_nonzero(A & mask)
    ans += (ones * (N - ones) % MOD) * (mask % MOD)
    ans %= MOD
    mask <<= 1

print(ans)

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

zeros = [0] * 60
ones = [0] * 60

for a in A:
    for i, bit in enumerate(reversed(format(a, '060b'))):
        if bit == '0':
            zeros[i] += 1
        else:
            ones[i] += 1

base = 1
ans = 0

for i in range(len(zeros)):
    ans += zeros[i] * ones[i] * base
    ans %= MOD
    base *= 2
    base %= MOD

print(ans)

Solution (Python):
n = int(input())
A = list(map(int,input().split()))
a = [format(i,'b') for i in A]
ans = 0
mod = 10**9+7
for i in range(60):
  cnt = 0
  for v in a:
    if len(v)<i+1:
      continue
    if v[-1-i]=='1':
      cnt += 1
  cnt = cnt*(n-cnt)%mod
  ans += cnt*(2**i)%mod
print(ans%mod)

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

zeros = [0] * 61
ones = [0] * 61

for a in A_list:
    for i, b in enumerate([1 if (a >> j & 1) else 0 for j in range(61)]):
        if b == 1:
            ones[i] += 1
        else:
            zeros[i] += 1

res = 0
for a in A_list:
    twice = 1
    for i, b in enumerate([1 if (a >> j & 1) else 0 for j in range(61)]):
        if b == 1:
            cnt = zeros[i]
            ones[i] -= 1
        else:
            cnt = ones[i]
            zeros[i] -= 1
        res += twice * cnt
        twice *= 2
    res %= MOD
print(res)

Solution (Python):
def main():
    n = int(input())
    a = list(map(int,input().split()))
    mod = 10**9+7
    div = {}
    for i in range(61):
        div[i] = 0
    for i in range(n):
        b = bin(a[i])
        l = len(b)
        for j in range(l-2):
            if b[l-1-j]=='1':
                div[j]+=1
    ans = 0
    for k in div.keys():
        ans += div[k] * (n-div[k]) * 2**k
        ans = ans % mod
    print(ans)

if __name__ == "__main__":
    main()

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


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

  mem0 = [[0]*60 for _ in range(N+1)]
  mem1 = [[0]*60 for _ in range(N+1)]
  for i in range(1, N+1):
    
    for j in range(60):
      if A[i-1] & (1 << j):
        mem1[i][j] = mem1[i-1][j] + 1
        mem0[i][j] = mem0[i-1][j]
      else:
        mem1[i][j] = mem1[i-1][j]
        mem0[i][j] = mem0[i-1][j] + 1

  sum_ = 0
  MAX = len(bin(max(A))) - 2
  for i in range(1, N+1):
    for j in range(MAX):
      if A[i-1] & (1 << j):
        sum_ += ( (1 << j)*(mem0[N][j] - mem0[i][j]) % MOD )
      else:
        sum_ += ( (1 << j)*(mem1[N][j] - mem1[i][j]) % MOD )

  print(sum_ % MOD)


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

Solution (Python):
N=int(input())
A=list(map(int,input().split()))
mod = 10**9+7
base = [(2**i)%mod for i in range(63,-1,-1)]

count = [0 for i in range(64)]
for i in range(N):
  b = list(map(int, list(bin(A[i])[2:])))
  b = [0]*(64-len(b))+b
  for j in range(64):count[j]+=b[j]

print(sum([base[i]*count[i]*(N-count[i]) for i in range(64)])%mod)

Solution (Python):
N = int(input())
aaa = list(map(int, input().split()))
bbb = [format(a, '061b') for a in aaa]

zero = [0] * 61
one = [0] * 61
for i in range(61):
    s = ''.join(list(b[-(i+1)] for b in bbb))
    zero[i] = s.count('0')
    one[i] = s.count('1')
ans = 0
MOD = 1_000_000_007
for i, o, l in zip(range(61), zero, one):
    ans += 2**i * o * l
    ans %= MOD
print(ans)

Solution (Python):
from collections import defaultdict
n = int(input())
A = list(map(int, input().split()))
mod = pow(10,9) + 7
D = defaultdict(lambda:0)
for a in A:
    for i in range(61):
        D[1 << i] += bool(a & (1 << i))
ans = 0
for k, v in D.items():
    ans += k * (v * (n - v))
    ans %= mod
print(ans)

Solution (Python):
import sys
input = lambda : sys.stdin.readline().rstrip()
sys.setrecursionlimit(max(1000, 10**9))
write = lambda x: sys.stdout.write(x+"\n")


n = int(input())
a = list(map(int, input().split()))
l = max(a).bit_length()
ans = 0
M = 10**9+7
for j in range(l):
    v0 = 0
    v1 = 0    
    for i in range(n):
        if (a[i]>>j)&1:
            v1 += 1
        else:
            v0 += 1
    ans += v0*v1*pow(2,j,M)
    ans %= M
print(ans%M)

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

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

ans = 0
for i in range(60):
    one = 0
    for a in A:
        if (a & (1 << i) != 0):
            one += 1
    zero = N - one
    now = one * zero % mod
    ans += now * pow(2, i) % mod
    ans %= mod
print(ans)

Solution (Python):
import sys
import heapq
import math
import fractions
import bisect
import itertools
from collections import Counter
from collections import deque
from operator import itemgetter
def input(): return sys.stdin.readline().strip()
def mp(): return map(int,input().split())
def lmp(): return list(map(int,input().split()))

mod=10**9+7
n=int(input())
a=lmp()
l=[[0,0] for i in range(60)]
for i in range(n):
    b=format(a[i],"060b")
    for j in range(60):
        if b[j]=="0":
            l[j][0]+=1
        else:
            l[j][1]+=1
ans=0
for i in range(60):
    ans+=(l[i][0]*l[i][1]*(2**(59-i)))%mod
print(ans%mod)

Solution (Python):

import sys

MOD = 1000000007  

def solve(N: int, A: "List[int]"):
    BN = 64
    B = [[0] * BN for _ in range(N+1)]
    for i, a in enumerate(A):
        for j in range(BN):
            B[i+1][j] = B[i][j] + ((a >> j) & 1)
    ans = 0
    for i in range(BN):
        b = 1 << i
        for j, a in enumerate(A):
            n = B[N][i] - B[j+1][i]
            if a & b:
                n = N - j  - n - 1
            ans = (ans + b * n % MOD) % MOD
    return ans



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)]  
    print(solve(N, A))

def test():
    import doctest
    doctest.testmod()

if __name__ == '__main__':
    
    main()

Solution (Python):
def cmb(n, r, p):
  if (r < 0) or (n < r):
    return 0
  r = min(r, n - r)
  return fac[n]*finv[r]*finv[n-r]%p

def perm(n,r,p):
  if (r < 0) or (n < r):
    return 0
  return fac[n]*finv[n-r]%p

N = 310000
MOD = pow(10,9)+7

fac = [-1]*(N+1); fac[0] = 1; fac[1] = 1 
finv = [-1]*(N+1); finv[0] = 1; finv[1] = 1 
inv = [-1]*(N+1); inv[0] = 0; inv[1] = 1 
for i in range(2,N+1):
  fac[i] = fac[i-1]*i%MOD
  inv[i] = MOD - inv[MOD%i]*(MOD//i)%MOD
  finv[i] = finv[i-1]*inv[i]%MOD

M = int(input())
A = list(map(int,input().split()))
MAX = 63
L = [0]*MAX

for i in range(M):
  for j in range(MAX):
    if A[i]>>j&1:
      L[j] += 1

ans = 0
for i in range(MAX):
  base = pow(2,i)
  kosu = cmb(M,2,MOD)-cmb(L[i],2,MOD)-cmb(M-L[i],2,MOD)
  ans += base*kosu%MOD
print(ans%MOD)

Solution (Python):
from sys import stdin
nii=lambda:map(int,stdin.readline().split())
lnii=lambda:list(map(int,stdin.readline().split()))

n=int(input())
a=lnii()

mod=10**9+7

ans=0
for i in range(60):
  on=0
  off=0
  for j in a:
    if (j>>i)&1:
      on+=1
    else:
      off+=1
  ans+=(on*off)*(2**i)
  ans%=mod

print(ans)

Solution (Python):
from sys import stdin
nii=lambda:map(int,stdin.readline().split())
lnii=lambda:list(map(int,stdin.readline().split()))

n=int(input())
a=lnii()

mod=10**9+7

ans=0
for i in range(60):
  on=0
  off=0
  for j in a:
    if (j>>i)&1:
      on+=1
    else:
      off+=1
  ans+=(on*off)*(2**i)
  ans%=mod

print(ans)

Solution (Python):
import sys
def input(): return sys.stdin.readline().strip()
def mapint(): return map(int, input().split())
sys.setrecursionlimit(10**9)

N = int(input())
As = list(mapint())
mod = 10**9+7

bits = [0]*70
for a in As:
    for l in range(a.bit_length()):
        if (a>>l)&1:
            bits[l] += 1

ans = 0
for i in range(70):
    one = bits[i]
    zero = N-one
    mul = pow(2, i, mod)
    ans += one*zero*mul
    ans %= mod

print(ans)

Solution (Python):
p0 = 10**9+7
def pow(x,m):
    if m==0:
        return 1
    if m==1:
        return x
    if m%2==0:
        return (pow(x,m//2)**2)%p0
    else:
        return (x*(pow(x,(m-1)//2)**2)%p0)%p0

N = int(input())
A = list(map(int,input().split()))
A = [bin(A[i])[2:] for i in range(N)]
A = ["0"*(60-len(A[i]))+A[i] for i in range(N)]
C = {k:0 for k in range(60)}
for i in range(N):
    for m in range(60):
        if A[i][m]=="1":
            C[59-m] += 1
B = [0 for _ in range(60)]
for k in range(60):
    p = C[k]
    m = N-C[k]
    B[k] = p*m
cnt = 0
for k in range(60):
    cnt = (cnt+B[k]*pow(2,k))%p0
print(cnt)

Solution (Python):
from collections import Counter,defaultdict,deque
from heapq import heappop,heappush
from bisect import bisect_left,bisect_right 
import sys,math,itertools,fractions,pprint
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()
ln = len(bin(max(a))) -2
cnt = [0] * ln
for x in a:
    for shift in range(ln):
        cnt[shift] += (x>>shift)%2

res = 0
for i in range(ln):
    now = cnt[i] * (n-cnt[i])
    res += now*pow(2,i)
    res %= mod
print(res)

Solution (Python):
import sys
from collections import defaultdict, deque, Counter
import math


from bisect import bisect_left, bisect_right
import heapq




input = sys.stdin.readline

getS = lambda: input().strip()
getN = lambda: int(input())
getList = lambda: list(map(int, input().split()))
getZList = lambda: [int(x) - 1 for x in input().split()]

INF = 10 ** 20
MOD = 10**9 + 7
divide = lambda x: pow(x, MOD-2, MOD)


def nck(n, k, kaijyo):
    return (npk(n, k, kaijyo) * divide(kaijyo[k])) % MOD


def npk(n, k, kaijyo):
    if k == 0 or k == n:
        return n % MOD
    return (kaijyo[n] * divide(kaijyo[n-k])) % MOD


def kaijyo(n):
    ret = [1]
    for i in range(1, n + 1):
        ret.append((ret[-1] * i)% MOD)
    return ret

def solve():

    n = getN()
    nums = getList()
    keta = [[0, 0] for i in range(62)]

    for num in nums:
        tmp = num
        for i in range(62):
            if tmp % 2 == 1:
                keta[i][1] += 1
            else:
                keta[i][0] += 1

            tmp //= 2

    ans = 0
    dig = 0
    for k1, k2 in keta:
        ans += ((k1 * k2) * (2**dig)) % MOD
        dig += 1

    print(ans % MOD)


def main():
    n = getN()
    for _ in range(n):
        solve()


if __name__ == "__main__":
    
    solve()

Solution (Python):
MOD = 1000000007
n = int(input())
aas = list(map(int, input().split()))
KET = 60
arr_0 = [0]*KET
arr_1 = [0]*KET
for i in aas:
    bits = format(i,'060b')
    for j in reversed(range(KET)):
        if bits[j] == '0':
            arr_0[KET-j-1] += 1
        else:
            arr_1[KET-j-1] += 1
res = 0
for i in range(KET):
    res += (arr_0[i]%MOD * arr_1[i]%MOD)%MOD * pow(2,i,MOD)
    res %= MOD
print(res)

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

mod=10**9+7

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

s=0
for i in range(60):
    bit = np.count_nonzero(a & 1)
    s += bit*(n-bit)*(2**i)
    a >>= 1
print(s % mod)

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

mod=10**9+7

ans=0
for i in range(60):
  on=0
  off=0
  for j in a:
    if (j>>i)&1:
      on+=1
    else:
      off+=1
  ans+=(on*off)*(2**i)
  ans%=mod

print(ans)

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

N=int(input().rstrip('\n'))
A=[int(x) for x in input().rstrip('\n').split()]
res = 0
t=1
for _ in range(60):
  n = sum(x%2 for x in A)
  A = [x//2 for x in A]
  res += n*(N-n)*t
  t = t*2
  res = res%(7+10**9)
  if all(x==0 for x in A):
    break
print(res)

Solution (Python):
import math

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

    A_max = sorted(A)[-1]
    if A_max == 0:
        print(0)
        exit()
    bit_max = int(math.ceil(math.log2(A_max)))

    i = 0
    bit = 1
    res = 0
    while i <= bit_max:
        c_zero = 0
        c_one = 0
        for j in range(N):
            if A[j] & bit == 0:
                c_zero += 1
            else:
                c_one += 1
        m_bit = bit % mod
        res += m_bit*c_zero*c_one
        res %= mod
        i += 1
        bit<<=1
    print(res)

if __name__ == "__main__":
    main()

Solution (Python):
import numpy as np
N, *A = map(int, open(0).read().split())
A = np.array(A, dtype=np.int64)
mod = 10**9 + 7
 
ans = 0
for i in range(60):
    mask = 1 << i
    cnt = np.count_nonzero(A&mask)
    x = cnt * (N-cnt)
    x *= mask % mod
    ans += x
    ans %= mod
 
print(ans)

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

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

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

n, s, res, MOD = int(input()), list(map(int, input().split())), 0, int(1e9) + 7
for i in range(61):
    x, c = int(pow(2, i, MOD)), [0, 0]
    for j in range(n): c[1 if s[j] & 1 << i else 0] += 1
    x = (x * c[0]) % MOD; x = (x * c[1]) % MOD; res = (res + x) % MOD
print(res)

Solution (Python):
N = int(input())
A = list(map(int,input().split()))
MAX = max(A)
BIG = 10**9+7
L = len(bin(MAX)[2:])
ans = 0
for j in range(L):
    zero = 0
    one = 0
    for i in range(N):
        if (A[i] >> j) & 1:
            one+=1
        else:
            zero+=1
    ans += ((zero*one)%BIG)*pow(2,j,BIG)
    ans = ans%BIG
print(ans)

Solution (Python):
import math

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

Sum = 0
mod = (10 ** 9) + 7

for i in range(len(bin(max(A)))-2):
    Sum_1 = 0
    for j in range(N):
        
        if ((A[j] >> i) & 1):
            Sum_1 += 1

    Sum_0 = N - Sum_1

    Sum = (Sum + ((Sum_0 * Sum_1) % mod * (2 ** i)) % mod) % mod
    

print(Sum)

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

  ans = 0
  for j in range(digit):
    o = 0
    for i in a:
      if (i >> j) & 1:
        o += 1
    ans += o*(n-o)*2**j
    ans %= MOD
  print(ans)
if __name__ == '__main__':
    main()

Solution (Python):
def main():
    n = int(input())
    A = [int(x) for x in input().split()]
    ans = 0
    mod = 10 ** 9 + 7
    for d in range(61):
        
        x = 0
        for a in A:
            if (a >> d) & 1:
                x += 1
        ans += x * (n-x) * 2**d
        ans %= mod
    print(ans)

if __name__ == '__main__':
    main()

Solution (Python):
n = int(input())
a = list(map(int,input().split()))
MOD = 10 ** 9 + 7
digit = 60
o=[0]*digit
z=[0]*digit

for i in a:
  for j in range(digit):
    if (i >> j) & 1:
      o[j] += 1
    else:
      z[j] += 1
ans = 0    
for j in range(digit):
  ans += (o[j]*z[j]*pow(2,j,MOD))
print(ans % MOD)

Solution (Python):
import sys

input_methods=['clipboard','file','key']
using_method=0
input_method=input_methods[using_method]

tin=lambda : map(int, input().split())
lin=lambda : list(tin())
mod=1000000007



def main():
	n = int(input())
	
	
	al = lin()
	lzero = [0]*62
	lone = [0]*62
	for v in al:
		for i in range(62):
			if v & (2**i) > 0:
				lone[i] += 1
			else:
				lzero[i] += 1
	ret = 0
	for i, (n_one, n_zero) in enumerate(zip(lone, lzero)):
		t = pow(2, i, mod) * n_one * n_zero
		ret += t
		ret %= mod
		
	print(ret)
		
			
	
	

isTest=False

def pa(v):
	if isTest:
		print(v)
		
def input_clipboard():
	import clipboard
	input_text=clipboard.get()
	input_l=input_text.splitlines()
	for l in input_l:
		yield l

if __name__ == "__main__":
	if sys.platform =='ios':
		if input_method==input_methods[0]:
			ic=input_clipboard()
			input = lambda : ic.__next__()
		elif input_method==input_methods[1]:
			sys.stdin=open('inputFile.txt')
		else:
			pass
		isTest=True
	else:
		pass
		
			
	ret = main()
	if ret is not None:
		print(ret)

Solution (Python):
def main():
    n = int(input())
    A = [int(x) for x in input().split()]
    ans = 0
    mod = 10 ** 9 + 7
    for d in range(61):
        
        x = 0
        for a in A:
            if (a >> d) & 1:
                x += 1
        ans += x * (n-x) * 2**d
        ans %= mod
    print(ans)

if __name__ == '__main__':
    main()

Solution (Python):
import sys
import numpy as np

input = sys.stdin.buffer.readline
N = int(input())
A = np.array(list(map(int, input().split())))

MOD = 10**9 + 7

answer = 0
for n in range(63):
    B = (A >> n) & 1
    x = np.count_nonzero(B)
    y = N - x
    x *= y
    for _ in range(n):
        x = x * 2 % MOD
    answer += x
answer %= MOD
print(answer)

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 i in range(60):
        cnt_one = 0
        for a in A:
            if (a >> i) & 1:
                cnt_one += 1
        res += (n - cnt_one) * cnt_one * pow(2, i)
        res %= mod
    print(res)


if __name__ == '__main__':
    resolve()

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

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
















def get_bit_array(num):
    res = []
    while num > 0:
        res.append(num%2)
        num //= 2
    return res

bits = {}  
for i in range(n):
    t = aaa[i]
    bit_array = get_bit_array(t)
    r = 1
    for i in range(len(bit_array)):  
        bits[r] = bits.get(r, 0) + bit_array[i]
        r *= 2


ans = 0
for k, v in bits.items():
    ans = (ans + k * (v * (n-v))) % mmm

print(ans)

Solution (Python):
import sys
import math
from collections import deque

sys.setrecursionlimit(1000000)
MOD = 10 ** 9 + 7
input = lambda: sys.stdin.readline().strip()
NI = lambda: int(input())
NMI = lambda: map(int, input().split())
NLI = lambda: list(NMI())
SI = lambda: input()


def make_grid(h, w, num): return [[int(num)] * w for _ in range(h)]


def main():
    N = NI()
    A = NLI()
    B = [[0]*2 for _ in range(62)]
    for a in A:
        for i in range(62):
            B[i][(a >> i) & 1] += 1
    ans = 0
    for i, b in enumerate(B):
        ans += b[0] * b[1] * pow(2, i, MOD)
    print(ans % MOD)


if __name__ == "__main__":
    main()

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

for x in A:
  temp = bin(x)[2:]
  for i in range(len(temp)):
    if temp[-1-i] == "1":
      B[i] += 1

ans = 0

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

print(ans)

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

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

ans = 0
p = 1

for i in range(60):
  if i >= 1:
    p *= 2
    p %= mod
  ans += (N-B[i])*B[i]*p
  ans %= mod

print(ans)

Solution (Python):
import numpy as np


def solve():
    ans = 0
    mask = 1
    for i in range(60):
        one_cnt = np.sum(A >> i & 1)
        tmp = one_cnt * (N - one_cnt)
        tmp %= MOD
        ans += tmp * mask
        ans %= MOD
        mask <<= 1
        mask %= MOD
    return ans


N, *A = map(int, open(0).read().split())
A = np.array(A, dtype=np.int64)
MOD = 1_000_000_007
print(solve())

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(len(bin(max(a)))):
  num_1 = np.count_nonzero((a>>i)&1)
  num_0 = n - num_1
  ans += (2**i)*(num_1*num_0) % mod
ans %= mod
print(ans)