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=[int(i) for i in input().split()]

a_bin=[]

for i in a:
    a_bin.append(format(i, '



def get_keta_num(keta,a_list):
    zero=0
    one=0
    for i in a_list:
        if i[-keta]=="0":
            zero+=1
        else:
            one+=1
    return zero*one

ans=0
for i in range(1,61):
    ans+=(2**(i-1))*get_keta_num(i,a_bin)
    ans=ans%(10**9+7)

print(ans)

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

Solution (Python):
from collections import deque
N = int(input())
A = deque(map(int, input().split()))
mod = 10**9 + 7
M = len(bin(max(A))) - 2
ans = 0
bitlist = [1]
anslist = [0 for _ in range(M)]
for k in range(M):
    bitlist.append(bitlist[-1]*2%mod)
counter = [0 for _ in range(M)]

for k in range(N):
    a = A.pop()
    c = 0
    while a:
        b = a & 1
        if b == 0:
            anslist[c] += counter[-c-1]
        else:
            anslist[c] += k - counter[-c-1]
            counter[-c-1] += 1
        c += 1
        a >>= 1
    while c < M:
        anslist[c] += counter[-c-1]
        c += 1
for k in range(M):
    ans += anslist[k]*bitlist[k]%mod
    ans %= mod
print(ans)

Solution (Python):
from collections import deque
N = int(input())
A = deque(map(int, input().split()))
mod = 10**9 + 7
M = len(bin(max(A))) - 2
ans = 0
bitlist = [1]
anslist = [0 for _ in range(M)]
for k in range(M):
    bitlist.append(bitlist[-1]*2%mod)
counter = [0 for _ in range(M)]

for k in range(N):
    a = A.pop()
    c = 0
    while c < M:
        b = a & 1
        if b == 0:
            anslist[c] += counter[-c-1]
        else:
            anslist[c] += k - counter[-c-1]
            counter[-c-1] += 1
        c += 1
        a >>= 1
for k in range(M):
    ans += anslist[k]*bitlist[k]%mod
    ans %= mod
print(ans)

Solution (Python):
from collections import deque
N = int(input())
A = deque(map(int, input().split()))
mod = 10**9 + 7
M = len(bin(max(A))) - 2
ans = 0
bitlist = [1]
for k in range(M):
    bitlist.append(bitlist[-1]*2%mod)
counter = [0 for _ in range(M)]

for k in range(N):
    a = A.pop()
    c = 0
    while c < M:
        b = a & 1
        if b == 0:
            ans += counter[-c-1]*bitlist[c]%mod
            ans %= mod
        else:
            ans += (k-counter[-c-1])*bitlist[c]%mod
            ans %= mod
            counter[-c-1] += 1
        c += 1
        a >>= 1
print(ans)

Solution (Python):
N = int(input())
A = list(map(int, input().split()))
MOD = 10**9+7
num_one_for_digit = [0]*61
for i in range(N):
    b = bin(A[i])[2:].zfill(61)
    for d in range(61):
        if b[d] == "1":
            num_one_for_digit[d] += 1
ans = 0
t = 1
for d in range(60, -1, -1):
    n_1 = num_one_for_digit[d]
    ans += n_1 * (N - n_1) * t % MOD
    ans %= MOD
    t *= 2
print(ans%MOD)

Solution (Python):
n=int(input())
A=[int(i) for i in input().split()]
mod=10**9+7

ans=0
cnt=[0 for i in range(61)]

for i in range(n):
    now=A[i]
    bek=1
    for q in range(61):
        if now&1==0:
            ans+=cnt[q]*bek
        else:
            ans+=(i-cnt[q])*bek
        bek=bek*2%mod
        cnt[q]+=now&1
        now>>=1
    ans=ans%mod
    
print(ans)

Solution (Python):
n=int(input())

p=10**9+7

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

binA=[]
for i in range(n):
  binA.append(format(A[i],"060b"))

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


ans=0
for i in range(60):
  num0=0
  num1=0
  for j in range(n):
    if binA[j][i]=="0":
      num0+=1
    else:
      num1+=1
  ans=(ans+num0*num1*exp[59-i])%p

print(ans)

Solution (Python):
n=int(input())

p=10**9+7

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

binA=[]
for i in range(n):
  binA.append(format(A[i],"060b"))


lis=[0 for i in range(60)]

for binAi in binA:
  for j in range(60):
    lis[j]+=int(binAi[j])

binary=[0 for i in range(60)]

for i in range(n):
  for j in range(60):
    if binA[i][j]=="0":
      binary[j]+=lis[j]
    else:
      binary[j]+=n-lis[j]


binary[58]+=binary[59]//2
binary[59]=0


explis=[1]

for i in range(60):
  explis.append((explis[i]*2)%p)

ans=0
for i in range(59):
  ans=(ans+binary[i]*explis[58-i])%p

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
for i in range(60):
    s = int((a&1).sum())
    ans += s*(n-s) * 2**i
    ans %= MOD
    a >>= 1
print(ans)

Solution (Python):
import numpy as np

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

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

Solution (Python):
def main():
    N = int(input())
    A = list(map(int, input().split()))
    MOD = 10 ** 9 + 7
    ans = 0
    L = 100
    for l in range(L):
        one = 0
        zero = 0
        for a in A:
            if (a & (1<<(L - l - 1))):
                one += 1
            else:
                zero += 1
        ans += (one * zero) * 2 ** (L - l - 1)
        ans %= MOD

    print(ans)
    


if __name__ == "__main__":
    main()

Solution (Python):
mod = 10**9+7
n = int(input())
A = list(map(int,input().split()))
from collections import defaultdict
zero = defaultdict(int)
one = defaultdict(int)
for a in A:
    for i in range(61):
        if a &(1<<i):
            one[i] += 1
        else:
            zero[i] += 1
ans = 0
for i in range(61):
    ans += pow(2,i,mod)*zero[i]*one[i]
    ans %=mod

print(ans%mod)

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

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

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

mod = 10**9 + 7

pows = [pow(2, i, mod) for i in range(60)]
count = [0]*60
num = [0]*60
ans = 0

for i in range(n):
    bit = a[i]
    for g in range(60):
        if bit % 2 == 1:
            count[g] += 1
            num[g] += i+1 - count[g]
        else:
            num[g] += count[g]
        bit //= 2

for i in range(60):
    ans += num[i]*pows[i]

print(ans % mod)

Solution (Python):
n=int(input())
a=list(map(int,input().split()))
num=[0]*63
for i in range(n):
    num1=a[i]
    for j in range(63):
        if num1==0:
            break
        if num1%2==1:
            num[j]+=1
        num1//=2
ans=0
for i in range(63):
    if num[i]!=0 and num[i]!=n:
        ans+=((2**i)*num[i]*(n-num[i]))%(10**9+7)
ans%=10**9+7
print(ans)

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

mod = 10**9 + 7

pows = [pow(2, i, mod) for i in range(60)]
count = [0]*60

for i in range(n):
    bit = a[i]
    for g in range(60):
        count[g] += bit%2
        bit //= 2
        if bit == 0:
            break

ans = 0
num = [0]*60

for i in range(n):
    bit = a[i]
    for g in range(60):
        if bit % 2 == 1:
            num[g] += n - count[g]
        else:
            num[g] += count[g]
        bit //= 2

for i in range(60):
    ans += num[i]*pows[i]

print(ans//2 % mod)

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

bit_l=[0 for _ in range(60)]

for x in a:
  for i in range(60):
    if ((x>>i)&1):
      bit_l[i]+=1
ans=0
mod=10**9+7
for y in range(len(bit_l)):
  r=2**y
  k=(n-bit_l[y])*bit_l[y]
  ans+=r*k%mod
  
print(ans%mod)

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

ans = 0
M = 10**9 + 7
for i in range(60):
  c0 = 0
  c1 = 0
  m = 1 << i
  for a in A:
    if a & m == 0:
      c0 += 1
    else:
      c1 += 1
  ans += (c0 * c1) * m
  ans %= M
print(ans)

Solution (Python):
n=int(input())
a=[int(x) for x in input().split()]
keta_0=[0]*70
keta_1=[0]*70
for shift in range(70):
    for i in range(n):
        if a[i]>>shift & 1:
            keta_1[shift]+=1
        else:
            keta_0[shift]+=1
ans=0

for i in range(70):
    ans+=2**i*keta_0[i]*keta_1[i]
    ans%=10**9+7

print(ans)

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

c = [0]*100
for i in a:
    b = format(i,'b')[::-1]
    for x in range(len(b)):
        c[x] += int(b[x])

ans = 0
mod = 10**9+7
for i in range(100):
    ans += c[i]*(n-c[i])*2**i
    ans %= mod

print(ans)

Solution (Python):
from copy import copy
n = int(input())
a_ls = list(map(int, input().split()))
c_bin = [[0]*60 for _ in range(n)]
a_bin_ls = [[0]*60 for _ in range(n)]
now_bin = [0] * 60
for i in range(n-1,-1,-1):
    a = a_ls[i]
    j = 0
    while True:
        if a == 1:
            now_bin[j] += 1
            a_bin_ls[i][j] = 1
            break
        elif a == 0:
            break
        a,r = divmod(a,2)
        now_bin[j] += r 
        a_bin_ls[i][j] = r
        j += 1
    c_bin[i] = copy(now_bin)
ans_bin = [0]*60
for i in range(n-1):
    a_bin = a_bin_ls[i]
    for j in range(60):
        if a_bin[j] == 0:
            times = c_bin[i+1][j]
        else:
            times = n - (i+1) - c_bin[i+1][j]
        ans_bin[j] += times
ans = 0
mod = 10**9+7
for i in range(60):
    ans += 2**i * (ans_bin[i]%mod)
    ans %= mod
print(ans)

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

mod = 10 ** 9 + 7
ans = 0

for k in range(60):
    x, y = 0, 0
    for a in A:
        x += 1 & a >> k
    tmp = x * (n - x) % mod
    tmp *= 2**k%mod
    ans += tmp
    ans %= mod
print(ans)

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

    mod = 10**9+7
    ans = 0

    for k in range(60):
        x, y = 0, 0
        for a in A:
            x += 1 & a>>k
        tmp = x*(n-x)%mod
        tmp *= pow(2, k, mod)
        ans += tmp
        ans %= mod
    print(ans)


if __name__ =='__main__':
    main()

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

mod = 10**9 + 7
ans = 0


for i in range(60):
    k = 1 << i  
    cnt_1 = 0
    cnt_0 = 0

    for ai in a:
        if k & ai:
            cnt_1 += 1
        else:
            cnt_0 += 1
    
    
    ans += ((k % mod) * cnt_1 * cnt_0) % mod

print(ans % mod)

Solution (Python):
from sys import stdin
import sys
import math
from functools import reduce
import functools
import itertools
from collections import deque,Counter,defaultdict
from operator import mul
import copy


import heapq
sys.setrecursionlimit(10**6)

INF = 10**18
import bisect
import statistics
mod = 10**9+7


def bit(S, j):
    
    return (S>>j)&1

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

B = [0 for i in range(61)]
for i in range(61):
    for j in range(N):
        B[i] += bit(A[j], i)

for i in range(61):
    B[i] = B[i]*(N-B[i]) % mod

ans = 0
for i in range(61):
    ans = (ans + 2**i*B[i]) % mod

print(ans % mod)

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

Solution (Python):
import sys;      from decimal import Decimal
import math;     from itertools import combinations, product
import bisect;   from collections import Counter, deque, defaultdict


MOD = 10 ** 9 + 7
INF = 10 ** 9
PI = 3.14159265358979323846

def read_str():      return sys.stdin.readline().strip()
def read_int():      return int(sys.stdin.readline().strip())
def read_ints():     return map(int, sys.stdin.readline().strip().split())
def read_str_list(): return list(sys.stdin.readline().strip().split())
def read_int_list(): return list(map(int, sys.stdin.readline().strip().split()))
def lcm(a: int, b: int) -> int: return (a * b) // math.gcd(a, b)

import numpy as np

def Main():
    n = read_int()
    a = np.array(read_int_list(), np.int64)
    ans = 0
    for i in range(60):
        cnt_one = np.count_nonzero(a >> i & 1)
        cnt_zero = n - cnt_one
        ans += (cnt_one * cnt_zero * (1 << i)) % MOD
        ans %= MOD
    print(ans)
    

if __name__ ==  '__main__':
    Main()

Solution (Python):


import sys
import math
from bisect import bisect_right as br
from bisect import bisect_left as bl
sys.setrecursionlimit(2147483647)
from heapq import heappush, heappop,heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
inf = float('inf')
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))

n = I()
a = LI()
cnt = [0] * 61
for i in a:
    for j in range(61):
        if i >> j & 1:
            cnt[j] += 1

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

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

MOD = 10 ** 9 + 7

N = int(input())
A = list(map(int, input().split()))
B = [bin(a) for a in A]

maxA = max(A)
mask = 1

count = 0
i = 0
while maxA >> i:
    zeros = sum([1 for a in A if (mask * 2**i) & a == 0]) % MOD
    ones = (len(A) - zeros) % MOD
    count += zeros * ones * ((2**i) % MOD)
    count %= MOD
    i += 1

print(count)

Solution (Python):
import sys
def input(): return sys.stdin.readline().rstrip()
def ii(): return int(input())
def mi(): return map(int, input().split())
def li(): return list(mi())

def main():
    mod = 10**9+7
    n = ii()
    a = li()
    bi = [0]*60
    for x in a:
        for i in range(60):
            if (x>>i)&1:
                bi[i]+= 1
    ans = 0
    for i in range(60):
        tmp = bi[i]*(n-bi[i])*(1<<i)
        tmp %= mod
        ans += tmp
        ans %= mod

    print(ans)



if __name__ == '__main__':
    main()

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

n = int(input())
alst = list(map(int, input().split()))
bin_s = [2 ** i for i in range(60)]
cnt = [0 for _ in range(60)]

for a in alst:
    for j in range(60):
        if bin_s[j] & a:
            cnt[j] += 1

ans = 0
for i in range(60):
    ans += bin_s[i] * cnt[i] * (n - cnt[i])
    ans %= MOD
print(ans)

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

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





mod=10**9+7
asum=0
for i in range(60):
    zcnt=0
    for ii in range(n):
        asht=a[ii]>>i
        if asht&1==0:
            zcnt+=1
    tmp=(zcnt*(n-zcnt))%mod*((2**i)%mod)
    asum+=(tmp)%mod
               
asum=asum%mod
print(asum)

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


maxl = 0
textlist = []
for i in range(N):
    tmp = str(bin(A[i]))
    tmp = tmp[2:]
    length = len(tmp)
    if maxl < length:
        maxl = length
    textlist.append(tmp)
zeros = {}
ones = {}
for i in range(maxl):
    zeros[i] = 0
    ones[i] = 0

for i in range(N):
    tmp = textlist[i]
    length = len(tmp)
    if maxl < length:
        maxl = length
    for j in range(length):
        if tmp[-j-1]== '1':
            ones[j] += 1
for i in range(maxl):
    zeros[i] = N-ones[i]

result = 0
n2 = 1
for i in range(maxl):
    result = (result + n2 * (zeros[i] * ones[i])) % mod
    n2  = (n2 * 2) % mod
print(result)

Solution (Python):
def main():
    N = int(input())
    l = list(map(int, input().split()))
    ans = 0
    m = 10**9 + 7
    
    for i in range(60):
        x = 0
        for j in l:
            x += 1 & j >> i
        
        tmp = x * (N - x) % m
        tmp *= 2 ** i % m
        ans += tmp
        ans %= m

    print(ans)

if __name__ == '__main__':
    main()

Solution (Python):
def main():
    import sys
    input = sys.stdin.readline
    
    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):
def main():
    n = int(input())
    A = [int(x) for x in input().split()]
    ans = 0
    mod = 10 ** 9 + 7
    for d in range(60):
        
        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

B=[[] for i in range(n)]
for i in range(n):
    B[i]= [((A[i]>>(59-j))) & 1 for j in range(60)]
    B[i] = [0]*(60-len(B[i]))+B[i]

TB=[[0]*n for i in range(60)]
for i in range(60):
    TB[i] = [B[j][i] for j in range(n)]
        


ans=0
for i in range(60):
    now=TB[i]
    q=sum(now)
    
    ans+= ((pow(2,59-i,mod)* (q*(n-q)))%mod)%mod
    ans%=mod


print((ans)%mod)

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

c = [n]*61
for i in range(n):
    b = str(bin(a[i]))[2:]
    b = b[::-1]
    for j, x in enumerate(b):
        if x == "1":
            c[j] -= 1

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

Solution (Python):

MOD = 10 ** 9 + 7
MAX = 60

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

cnt = [0 for i in range(MAX)]
for i in range(n):
    bit = bin(a[i])[2:].zfill(MAX)
    for j in range(MAX):
        cnt[j] += int(bit[j])

ans = 0
for i in range(MAX):
    ans += cnt[MAX - i - 1] * (n - cnt[MAX - i - 1]) * 2 ** i
    ans %= MOD
print(ans)

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

Solution (Python):
MOD = int(1e9 + 7)
n = int(input())
A = list(map(int, input().split()))
ans = 0
for i in range(62):
    cnt = 0
    for a in A:
        if a & 1<<i:
            cnt += 1
    ans += (1<<i % MOD) * cnt % MOD * (n - cnt) % MOD
print(ans % MOD)

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

for i in range(60):
    cnt = 0
    digit = 1 << i
    for j in a:
        if digit & j:
            cnt += 1
    ans += digit*cnt*(n - cnt)%mod

print(ans%mod)

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

ans = 0
x = 1
for d in range(60):
    odd = 0
    even = 0
    for a in A:
        if a & (1 << d):
            odd += 1
        else:
            even += 1
    ans += odd * even * x
    ans %= MOD
    x <<= 1
print(ans)

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

Solution (Python):
import os
import sys
import numpy as np

def solve(A, N):
    mod = 10**9+7
    C = [0] * 60
    for a in A:
        for i in range(60):
            if a>>i&1:
                C[i] += 1
    ans = 0
    for i, c in enumerate(C):
        ans += (1<<i) % mod * c % mod * (N-c) % mod
    return ans % mod


numba_config = [
    [solve, "i8(i8[:],i8)"],
]
if sys.argv[-1] == "ONLINE_JUDGE":
    from numba import njit
    from numba.pycc import CC
    cc = CC("my_module")
    for func, signature in numba_config:
        vars()[func.__name__] = njit(signature)(func)
        cc.export(func.__name__, signature)(func)
    cc.compile()
    exit()
elif os.name == "posix":
    exec(f"from my_module import {','.join(func.__name__ for func, _ in numba_config)}")
else:
    from numba import njit
    for func, signature in numba_config:
        vars()[func.__name__] = njit(signature, cache=True)(func)
    print("compiled!", file=sys.stderr)


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

Solution (Python):
import numpy as np 
n = int(input())
tmp = list(map(int,input().split()))

mod = 10**9 + 7
a = np.array(tmp,np.int64)

ans = 0
for i in range(60 + 1):
    b = (a >> i) & 1 
    iti = np.count_nonzero(b) 
    zero = n - iti 
    ans += (iti * zero) * pow(2,i,mod) % mod
ans %= mod
print(ans)

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

for i in range(60):
    cou  = 0
    bit = 1 << i
    for j in a:
        if j & bit:
            cou += 1
    num1 = cou
    num0 = n - num1
    ans += ((num1*num0) * bit )%mod
print(ans%mod)

Solution (Python):
import sys
input = sys.stdin.readline
MOD = pow(10, 9) + 7


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

m = max(a)

num = [0] * 61

for x in a:
    for j in range(61):
        if (x >> j) & 1:
            num[j] += 1

s = 0



for i in range(61):
    s += (n - num[i]) * num[i] * pow(2, i, MOD) % MOD

print(s % MOD)

Solution (Python):
import numpy as np
INT = lambda: int(input())
INTM = lambda: map(int,input().split())
STRM = lambda: map(str,input().split())
STR = lambda: str(input())
LIST = lambda: list(map(int,input().split()))
LISTS = lambda: list(map(str,input().split()))

def do():
    n=INT()
    a=np.array(LIST())
    ans=0
    mod=10**9+7
    for i in range(70):
        digit=np.sum((a>>i)&1)
        ans+=pow(2,i,mod)*(((n-digit)*digit)%mod)%mod
        ans=ans%mod
    
    print(ans)



if __name__=='__main__':
    do()

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

for i in range(60):
    cnt = 0
    digit = 1 << i
    for j in a:
        if digit & j:
            cnt += 1
    ans += digit*cnt*(n - cnt)%mod

print(ans%mod)

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

for i in range(60):
    cnt = 0
    digit = 1 << i
    for j in a:
        if digit & j:
            cnt += 1
    ans += digit*cnt*(n - cnt)%mod

print(ans%mod)

Solution (Python):
def cin():
    in_ = list(map(int,input().split()))
    if len(in_) == 1:  return in_[0]
    else:  return in_

N = cin()
A = cin()
INF = 10 ** 9 + 7

res = [0 for _ in range(65)]
for i in range(65):
    c0, c1 = 0, 0
    for j in range(N):
        if bool(A[j] & (1 << i)):  c1 += 1
        else:  c0 += 1
    res[i] = c0 * c1
ans = 0
for i in range(65):  ans = (ans + (1 << i) * res[i]) % INF
print(ans)

Solution (Python):


M = 10**9+7
n = int(input())
l = list(map(int,input().split()))
o = [0]*61
z = [0]*61
for i in l:
    a = bin(i)[2:]
    j = 0
    while(j < len(a)):
        if a[j] == "1":
            o[len(a)-j-1] += 1

        j += 1

cnt = 0
b = 1
for j in range(len(o)):
    cnt = (cnt+(o[j]*(n-o[j])*b)%M)%M
    b *= 2

print(cnt)

Solution (Python):


M = 10**9+7
n = int(input())
l = list(map(int,input().split()))
o = [0]*61
z = [0]*61
for i in l:
    a = bin(i)[2:]
    j = 0
    while(j < len(a)):
        if a[j] == "1":
            o[len(a)-j-1] += 1

        j += 1

cnt = 0
b = 1
for j in range(len(o)):
    cnt = (cnt+(o[j]*(n-o[j])*b)%M)%M
    b *= 2

print(cnt)

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):
from math import ceil,floor,factorial,gcd,sqrt,log2,cos,sin,tan,acos,asin,atan,degrees,radians,pi,inf
from itertools import accumulate,groupby,permutations,combinations,product,combinations_with_replacement
from collections import deque,defaultdict,Counter
from bisect import bisect_left,bisect_right
from operator import itemgetter
from heapq import heapify,heappop,heappush
from queue import Queue,LifoQueue,PriorityQueue
from copy import deepcopy
from time import time
from functools import reduce
import string
import sys
sys.setrecursionlimit(10 ** 7)
def input() : return sys.stdin.readline().strip()
def INT()   : return int(input())
def MAP()   : return map(int,input().split())
def LIST()  : return list(MAP())

n = INT()
a = LIST()

ans = 0
k = 1
for i in range(60):
    s = 0
    t = 0
    for j in range(n):
        if a[j] % 2 == 0:
            s += 1
        else:
            t += 1
        a[j] //= 2
    ans = ( ans + s * t * k ) % ( 10**9 + 7 )
    k *= 2
print(ans)

Solution (Python):
import numpy as np

n = int(input())
a = np.array([int(x) for x in input().split()])

ans = 0
mod = pow(10, 9)+7
for i in range(100):
  c = np.sum((a>>i)&1)
  ans += (c*(n-c)%mod)*pow(2, i, mod)%mod
  ans %= mod

print(ans)

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

mod = 10**9 + 7

ans = 0


for i in range(60):
    k = 1 << i  
    cnt_1 = 0
    cnt_0 = 0

    for ai in a:
        if k & ai:
            cnt_1 += 1
        else:
            cnt_0 += 1
    
    ans += (k % mod * cnt_1 * cnt_0) % mod

print(ans % mod)

Solution (Python):


def read_int():
    return int(input().strip())


def read_ints():
    return list(map(int, input().strip().split(' ')))


def solve():
    N = read_int()
    size = 60
    digits = [[0, 0] for _ in range(size)]
    for a in read_ints():
        for i in range(size-1, -1, -1):
            digits[i][a&1] += 1
            a >>= 1
    p = 1
    answer = 0
    modulo = 10**9+7
    for i in range(size-1, -1, -1):
        answer = (answer+p*digits[i][0]*digits[i][1])%modulo
        p *= 2
    return answer


if __name__ == '__main__':
    print(solve())

Solution (Python):

mod = 10**9+7
n = int(input())
arr = list(map(int , input().split()))
dp = [ [0 for i in range(67)] for j in range(0, n+6)]
for i in range(n-1,0 , -1):
	for j in range( 0 , 61):
		dp[i+1][j]=dp[i+2][j]
	for j in range(0 , 61):
		if (arr[i] &(1<<j)):
			dp[i+1][j]+=1
ans = 0
for i in range(1 , n+1):
	for j in range(0 , 61):
		if (arr[i-1]&(1<<j)):
			ust = n-i-dp[i+1][j]
			ans = ans + (ust*(1<<j))
			ans = ans%mod
		else:
			st = dp[i+1][j]
			ans = ans+(st*(1<<j))
			ans = ans%mod
print(ans)

Solution (Python):
N = int(input())
A = list(map(int,input().split()))
zero_count = [0]*70
one_count  = [0]*70

for a in A:
    count_ = [0]*70
    bin_a = list(bin(a)[2:])
    bin_a.reverse()
    
    for b_idx,b in enumerate(bin_a):
        count_[b_idx] = int(b)
        

    
    for c_idx,c in enumerate(count_):
        if c == 0: 
            zero_count[c_idx] += 1
            
        elif c == 1: 
            one_count[c_idx] += 1
            

ans = 0     

for l in range(70):
    ans += zero_count[l]*one_count[l]*(2**l)
    
print(ans%((10**9)+7))

Solution (Python):

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

MOD = 10 ** 9 + 7
ans = 0
for b in range(61):
    ctr = [0, 0]
    for i in range(N):
        ctr[X[i] >> b & 1] += 1

    ans += (1 << b) * ctr[0] * ctr[1]
    ans %= MOD

print(ans)

Solution (Python):
X=[0]*60
M=10**9+7
N=int(input())
T=500000004

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

for a in A:
    for k in range(60):
        X[k]+=a%2
        a>>=1


Y=0
y=1
for b in X:
    Y+=b*(N-b)*y
    Y%=M
    y<<=1
print(Y)

Solution (Python):
import numpy as np

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

for i in range(60):
  keta = a>>i & 1
  num1 = int(keta.sum())
  num0 = n - num1
  ans+= ((2**i)%mod)*(num1*num0)
  ans%=mod
print(ans)

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


print(ans%mod)

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):
n, *a = map(int, open(0).read().split())
b = [0] * 60
ans = 0
for i in range(n):
    for j in range(60):
        ans += 2**j * (i - b[j] if a[i] >> j & 1 else b[j])
        ans %= 10**9 + 7
    for j in range(len(bin(a[i])) - 2):
        b[j] += a[i] >> j & 1
print(ans)

Solution (Python):

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

Solution (Python):

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

Solution (Python):

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

Solution (Python):
N = int(input())
A = list(map(int, input().split()))
L = 60
MOD = 10**9 + 7
data = [0]*L
for a in A:
    S = reversed(bin(a)[2:])
    for i, s in enumerate(S):
        data[i] += s=="1"
p = 1
res = 0
for i in range(L):
    res += data[i]*(N-data[i])*p
    p *= 2
    p %= MOD
print(res%MOD)