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 numpy as np
 
MAX_DIGIT = 60
MOD = 10**9 + 7
 
N = int(input())
A = np.array([int(a) for a in input().split()])
 
answer = 0
for d in range(MAX_DIGIT + 1):
    A, r = (A>>1), A % 2
    s = int(r.sum())
    base = (1<<d) % MOD
    answer += (base * s * (N - s)) % MOD
 
answer %= MOD
print(answer)

Solution (Python):
import sys
mod = 10**9+7
N = int(sys.stdin.readline())
A = tuple(map(int, sys.stdin.readline().split()))
B = []
ans = 0
C = [0 for i in range(60)]
for i in A:
    for l in range(60):
        if ((i >> l) & 1) == 1:
            C[l] += 1
for i in range(60):
    t = C[i]
    ans = (ans + t*(N-t)*(2**i)) % mod
print(ans)

Solution (Python):
import numpy as np

MAX_DIGIT = 60
MOD = 10**9 + 7

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

answer = 0
for d in range(MAX_DIGIT + 1):
    A, r = (A>>1), A % 2
    s = int(r.sum())
    base = (1<<d) % MOD 
    answer += (base * s * (N - s)) % MOD

answer %= MOD
print(answer)

Solution (Python):
import sys


def solve():
    readline = sys.stdin.buffer.readline
    mod = 10 ** 9 + 7
    n = int(readline())
    a = list(map(int, readline().split()))
    ls = [0] * 65
    for v in a:
        tt = bin(v)
        for i in range(len(tt)-2):
            ls[i] += int(tt[-i-1])
    t = 0
    for i in range(len(ls)):
        t += pow(2, i, mod) * (n - ls[i]) * ls[i]
        t %= mod
    print(t)


if __name__ == '__main__':
    solve()

Solution (Python):
import numpy as np

MAX_DIGIT = 60
MOD = 10**9 + 7

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

answer = 0
for d in range(MAX_DIGIT + 1):
    A, r = (A>>1), A % 2
    s = int(r.sum())
    base = (1<<d) % MOD 
    answer += (base * s * (N - s)) % MOD

answer %= MOD
print(answer)

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

o = []

MOD = 10**9 + 7

for b in range(60):
    count = 0
    x = 2**b
    for i in range(n):
        if (a[i] & x) == 0:
            count += 1
    o.append(count)

sum = 0
for b in range(60):
    sum += (o[b] * (n - o[b])) * 2**b

print(sum % MOD)

Solution (Python):
import sys


def solve():
    readline = sys.stdin.buffer.readline
    mod = 10 ** 9 + 7
    n = int(readline())
    a = list(map(int, readline().split()))
    ls = [0] * 65
    for v in a:
        tt = bin(v)
        for i in range(len(tt)-2):
            ls[i] += int(tt[-i-1])
    t = 0
    for i in range(len(ls)):
        t += 2 ** i * (n - ls[i]) * ls[i]
        t %= mod
    print(t)


if __name__ == '__main__':
    solve()

Solution (Python):
from collections import Counter
N = int(input())
MAXBIT = 60
MOD = 10 ** 9 + 7
A = list(map(int, input().split()))
B = []
C = [[] for _ in range(MAXBIT)]
for a in A:
    for d in range(MAXBIT):
        C[d].append(a >> d & 1)
ans = 0
for d in range(MAXBIT):
    num0 = C[d].count(0)
    num1 = N - num0
    ans += ((num0 * num1) % MOD) * pow(2, d, MOD)
    ans %= MOD
print(ans)

Solution (Python):
def main():
    mod=1000000007
    n=int(input())
    A=list(map(int,input().split()))
    D=[0]*61
    for i in range(61):
        for a in A:
            if a>>i&1:
                D[i]+=1
    ans=0
    for i,d in enumerate(D):
        ans+=(pow(2,i,mod)*(d*(n-d)))
        ans%=mod
    print(ans)
    
if __name__=='__main__':
    main()

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

Solution (Python):
MOD = 1000000007

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

def sumXOR(arr,n):
    xorsum = 0
    for i in range(64):
        zc = 0
        oc = 0
        idsum = 0
        for j in range(n):
            if arr[j] % 2 == 0:
                zc += 1
            else:
                oc += 1
            arr[j] = arr[j]//2
        idsum = oc*zc*(1 << i)
        xorsum += idsum
        xorsum %= MOD
    return xorsum

XORSUM = 0
XORSUM = sumXOR(A,N);
print(XORSUM%MOD)

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

ans = 0
for i in range(61):
  c0 = 0
  c1 = 0
  for a in A:
    if (a>>i)&1 == 1:
      c1 += 1
    else:
      c0 += 1
  
  ans += ((c0*c1)<<i)
  ans %= MOD
print(ans)

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

a_b = []
for i in A:
    this_b = []
    this_a = i
    for j in range(59,-1,-1):
        j2 = 2**j
        if this_a >= j2:
            this_b.append(1)
            this_a -= j2
        else:
            this_b.append(0)
    a_b.append(this_b)
    


count_a_b = []
for i in range(60):
    count_a_b.append(0)

    
for i in a_b:
    for j in range(len(i)):
        count_a_b[j] += i[j]


count = 0
for i in range(len(count_a_b)):
    count += (count_a_b[i] * (N-count_a_b[i])) *2**(59-i)
    
print(count%(10**9+7))

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

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



def solve(n, arr):
    sum = 0
    bitcount = [0]*100
    for num in arr:
        b = reversed(bin(num)[2:])
        for i, s in enumerate(b):
            if i != "0":
                bitcount[i] += int(s)
    for i, b in enumerate(bitcount):
        sum += b * (n-b) * 2**i
    return sum % (10**9 + 7)


def main():
    N = int(input())
    A_l = [int(i) for i in input().split()]
    print(solve(N, A_l))


if __name__ == "__main__":
    main()

Solution (Python):
MOD = 1000000007

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

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

ans = 0
for i in range(60):
    ans += digits[i] * (N - digits[i]) * (1<<i)
    ans %= MOD

print(ans)

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

mod = 10 ** 9 + 7


def read_valus():
    return map(int, input().split())


def read_list():
    return list(read_valus())


def read_lists(N):
    return [read_list() for n in range(N)]


def p(N, a):
    return (a * (N - a)) % mod


def main():
    pows = [1] * 66
    for i in range(65):
        pows[i + 1] = (pows[i] * 2) % mod

    N = int(input())
    A = read_list()

    num = [0] * 65
    for a in A:
        tmp = a
        for i in range(65):
            if tmp == 0:
                break
            num[i] += tmp % 2
            tmp //= 2

    res = 0
    for i in range(65):
        if num[i] == 0:
            continue

        res = (res + (pows[i] * p(N, num[i])) % mod) % mod

    print(res % mod)


if __name__ == "__main__":
    main()

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

cnt=[0]*60
p=10**9+7
for m in a:
    
    
    
    for i in range(60):
        if((m>>i) & 1):
            cnt[i]+=1
    
    
    
    
    
    
    
    



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

ans=0

for i in range(60):
    ans+=(lis[i]%p)*(cnt[i]%p)*((n-cnt[i])%p)
    ans%=p

print(ans)

Solution (Python):
N = int(input())
A = list(map(int, input().split()))
q = 10 ** 9 + 7
ans = 0
cnt = [0] * 61
for i in range(N):
    b = bin(A[i])[2:].zfill(61)
    for i in range(61):
        if b[i] == '1':
            cnt[i] += 1
for num, c in enumerate(cnt[::-1]):
    zero = N - c
    ichi = c
    ans += zero * ichi * (2 ** num)
    ans = ans % q
print(ans % q)

Solution (Python):
import numpy as np
N = int(input())
A = np.array(input().split(), dtype=np.int64)

X = (1 << np.arange(60, dtype=np.int64)) & A.reshape(-1,1)
B = np.sum(X != 0, axis=0)

total = 0

for i,count in enumerate(B):
  total += int(count) * int(N - count) * int(1 << i)

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

Solution (Python):
N = int(input())
A = [int(x) for x in input().split()]
B = []
for x in A:
    tmp_lst = []
    for _ in range(60):
        tmp = x // 2
        tmp_lst.append(x - tmp * 2)
        x = tmp
    B.append(tmp_lst)

ans = 0
for i in range(60):
    tr, fl = 0, 0
    for x in B:
        if x[i]:
            tr += 1
        else:
            fl += 1
    ans += (tr * fl) * 2 ** i
    ans = ans % (10 ** 9 + 7)
print(ans)

Solution (Python):
from itertools import accumulate
n = int(input())
a = list(map(int,input().split()))
a.sort(reverse=True)
aa = list(accumulate(a))
aa = aa[::-1]
a.sort()
div = 10**9+7
ans=0

ls = [0]*60
for i in range(60):
    for j in a:
        if j&(1<<i):
            ls[i]+=1
        else:
            ls[i]-=1
    
for i in range(n-1):
    ans+=aa[i+1]
    for j in range(60):
        if a[i]&(1<<j):
            ls[j]-=1
            ans-=ls[j] * 2**j
        else:
            ls[j]+=1
    
    ans %= div

print(ans)

Solution (Python):



import sys
import math
from bisect import bisect_right as br
from bisect import bisect_left as bl
sys.setrecursionlimit(1000000)
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()
b = [0]*60
for i in range(n):
    for j in range(a[i].bit_length()):
        if (a[i] >> j) & 1:
            b[j] += 1
ans = 0
tmp = 0
for i in range(60):
    r = n-b[i]
    ans += b[i]*r*(2**tmp)
    ans %= mod
    tmp += 1
print(ans)

Solution (Python):
from collections import Counter
N = int(input())
A = list(map(int,input().split()))
MOD = 10 ** 9 + 7
ans = 0
bit_matrix = [[0] * N for _ in range(61)]
for i in range(len(A)):
    n = 0
    while 2 ** n <= A[i]:
        if A[i] >> n & 1:
            bit_matrix[n][i] = 1
        n += 1


'''
for j in range(60):
    tmp = []
    for i in range(N):
        tmp.append(bit_matrix[i][j])
    bit_matrix_T.append(tmp)
'''

for i in range(len(bit_matrix)):
    tmp = Counter(bit_matrix[i])
    a = list(tmp.values())
    if len(a) == 2:
        ans += (2 ** i) * a[0] * a[1]
        ans %= MOD
print(ans)

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

def main():
    n=int(input())
    a=list(map(int, input().split()))
    pre2 = (1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096, 8192, 16384, 32768, 65536, 131072, 262144, 524288, 1048576, 2097152, 4194304, 8388608, 16777216, 33554432, 67108864, 134217728, 268435456, 536870912, 73741817, 147483634, 294967268, 589934536, 179869065, 359738130, 719476260, 438952513, 877905026, 755810045, 511620083, 23240159, 46480318, 92960636, 185921272, 371842544, 743685088, 487370169, 974740338, 949480669, 898961331, 797922655, 595845303, 191690599, 383381198, 766762396, 533524785, 67049563, 134099126, 268198252, 536396504)
    pre1 = (1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096, 8192, 16384, 32768, 65536, 131072, 262144, 524288, 1048576, 2097152, 4194304, 8388608, 16777216, 33554432, 67108864, 134217728, 268435456, 536870912, 1073741824, 2147483648, 4294967296, 8589934592, 17179869184, 34359738368, 68719476736, 137438953472, 274877906944, 549755813888, 1099511627776, 2199023255552, 4398046511104, 8796093022208, 17592186044416, 35184372088832, 70368744177664, 140737488355328, 281474976710656, 562949953421312, 1125899906842624, 2251799813685248, 4503599627370496, 9007199254740992, 18014398509481984, 36028797018963968, 72057594037927936, 144115188075855872, 288230376151711744, 576460752303423488, 1152921504606846976)
    x=[0 for _ in range(61)]
    ans=0
    for i in range(n):
        z=[0 for _ in range(61)]
        y = a[i]
        for k in range(60,-1,-1):
            if y>=pre1[k]:
                y-=pre1[k]
                z[k]+=1
        for j in range(61):
            num = i-x[j]
            if i!=0:
                if z[j]==0:
                    ans=(ans+x[j]*pre2[j])%mod
                else:
                    ans=(ans+num*pre2[j])%mod
            x[j]+=z[j]
    print(ans)


if __name__ == "__main__":
    main()

Solution (Python):
MOD = 10 ** 9 + 7
def main():
    N = int(input())
    A = [int(i) for i in input().split()]
    B = [0] * 60
    for i in A:
        for j in range(60):
            if i & (1 << j):
                B[j] += 1
    r = 0
    for ii, i in enumerate(A[:-1]):
        for j in range(60):
            if i & (1 << j):
                B[j] -= 1
                r = (r + (1 << j) * (N - ii - 1 - B[j])) % MOD
            else:
                r = (r + (1 << j) * B[j]) % MOD
    print(r)

main()

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

def sumXOR( arr,  n): 
    sum = 0
    for i in range(0, 64): 
  
        
        zc = 0
        oc = 0
           
        
        idsum = 0
        for j in range(0, n): 
            if (arr[j] % 2 == 0): 
                zc = (zc + 1)
                  
            else: 
                oc = (oc + 1)
            arr[j] = (arr[j] >> 1) 
          
           
        
        idsum = (oc * zc * ((1 << i))) % 1000000007
   
        
        sum = (sum + idsum)
      
    return sum
  
  
  
  
print(sumXOR(A, N)  % 1000000007)

Solution (Python):
def sumXOR(arr, n):       
    MOD = 10 ** 9 + 7
    sum = 0
    for i in range(0, 61): 
        zc = 0
        oc = 0
        idsum = 0
        for j in range(0, n): 
            if (arr[j] % 2 == 0): 
                zc = zc + 1                  
            else: 
                oc = oc + 1
            arr[j] = arr[j] // 2 
          
        idsum = oc * zc * (1 << i)    
        sum = (sum + idsum) % MOD;        
    return sum

n = int(input())
A = list(map(int, input().split()))
sum = 0
sum = sumXOR(A, n); 
print(sum)

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

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


blist=[0]*64
for a in alist:
  bblist=[]
  acopy=a
  while(acopy>0):
    bblist.append(acopy%2)
    acopy//=2
    
  
  for b in range(len(bblist)):
    blist[-1-b]+=bblist[b]
      
blist.reverse()

answer=0
pow=1
for i in range(64):
  answer+=blist[i]*(N-blist[i])*pow
  answer%=MOD
  pow*=2
  
print(answer)

Solution (Python):
import copy
import random
import bisect 
import fractions 
import math
import sys
import bisect

mod = 10**9+7
sys.setrecursionlimit(mod) 

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

N = int(input())
A = LI()

count_list = [0 for i in range(61)]
def counts(count_list, a):
    for i in range(61):
        if a <= 0:
            break
        count_list[i] += a % 2
        a = a // 2
    return count_list

A.reverse()
ans = 0
ans_list = [0 for i in range(61)]
for i in range(N-1):
    count_list = counts(count_list, A[i])
    hikaku = counts([0 for i in range(61)], A[i + 1])
    for j in range(61):
        if hikaku[j] == 1:
            ans_list[j] += i+1 - count_list[j]
        else:
            ans_list[j] += count_list[j]

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

Solution (Python):
n = int(input())
a = list(map(int, input().split()))
L = len(format(max(a), 'b'))
x = [0 for i in range(L)]
ans = 0
MOD = 10 ** 9 + 7
for i in a:
    i_str = list(format(i, '0' + str(L) + 'b'))[::-1]
    for j, s in enumerate(i_str):
        if s == '1':
            x[j] += 1
b = 1
for i, xi in enumerate(x):
    ans += xi * (n - xi) * b % MOD
    ans %= MOD
    b *= 2
    b %= MOD
print(ans)

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

counts = [sum((a >> i) & 1 for a in A) for i in range(60)]

power2 = [1]
for _ in range(59):
    power2.append((power2[-1] * 2) % MOD)

ans = sum(c * (N - c) * power2[i] for i, c in enumerate(counts))

print(ans % MOD)

Solution (Python):
n = int(input())
A = list(map(int, input().split()))
one = [0 for _ in range(60)]

for a in A:
    for i in range(60):
        if a & 1 << i:
            one[i] += 1
ans = 0
for a in A:
    n -= 1
    if n == 0:
        break
    for i in range(60):
        if a & 1 << i:
            one[i] -= 1

    for i in range(60):
        if a & 1 << i:
            ans += (1 << i) * (n - one[i])
        else:
            ans += (1 << i) * one[i]

print(ans % 1000000007)

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

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


blist=[0]*64
for a in alist:
  bblist=[]
  acopy=a
  while(acopy>0):
    bblist.append(acopy%2)
    acopy//=2
    
  
  for b in range(len(bblist)):
    blist[-1-b]+=bblist[b]
      
blist.reverse()

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

Solution (Python):
import sys,collections as cl,bisect as bs
sys.setrecursionlimit(100000)
mod = 10**9+7
Max = sys.maxsize
input = sys.stdin.readline
def l(): 
    return list(map(int,input().split()))
def m(): 
    return map(int,input().split())
def onem(): 
    return int(input())
def s(x): 
    a = []
    aa = x[0]
    su = 1
    for i in range(len(x)-1):
        if aa != x[i+1]:
            a.append([aa,su])
            aa = x[i+1]
            su = 1
        else:
            su += 1
    a.append([aa,su])
    return a
def jo(x): 
    return " ".join(map(str,x))
def max2(x): 
    return max(map(max,x))
def In(x,a): 
    k = bs.bisect_left(a,x)
    if k != len(a) and a[k] ==  x:
        return True
    else:
        return False


def ans():
    n = onem()

    a = l()

    dp = [[0]*60 for j in range(n+1)]

    co = 0

    for i in range(1,n+1):
        kkk = a[i-1]
        for j in range(60):
            if j != 0:
                kkk = kkk // 2
            if kkk & 1:
                dp[i][j] = dp[i-1][j] + 1
            else:
                dp[i][j] = dp[i-1][j]

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

    for i in range(1,n):
        for j in range(60):
            if dp[i][j] == dp[i-1][j]:
                ans = two[j]*(dp[-1][j]-dp[i][j])
                ans %= mod
                co += ans
                co %= mod
            else:
                ans = two[j]*(n-(i-1) - (dp[-1][j] - dp[i-1][j]))
                ans %= mod
                co += ans
                co %= mod

    print(co)

if __name__ == '__main__':
    ans()

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

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

B = [0]*60

for a in A:
    for i in range(60):
        B[i] += (a >> i) % 2

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

Solution (Python):
mod = 10 ** 9 + 7
n = int(input())
a = list(map(int, input().split()))
l = [0 for i in range(len(str(bin(max(a)))) - 2)]
a = [bin(i)[2:] for i in a]

for i in a:
    for j, k in enumerate(i[::-1]):
        if k == "1":
            l[j] += 1
ans = 0
for i, j in enumerate(l):
    ans = (ans + (j * (n - j)) * (2 ** i)) % mod
print(ans)

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

for i in range(N):
  for j in range(61):
    if ((A[i]>>j) & 1):
      
      T[j]+=1


ans=0
for i in range(61):
  ans+=2**i*(N-T[i])*T[i]
  ans%=mod
print(ans)

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

ans = 0
for j in range(60):
    c0 = 0
    c1 = 0
    for i in range(n):
        if a[i] % 2**(j+1) == 0:
            c0 += 1
        else:
            a[i] -= 2**j
            c1 += 1
    ans += 2 ** j * c0 * c1
    ans %= 10**9 + 7

print(ans)

Solution (Python):
n = int(input())
alist = list(map(int,input().split()))
binlist = [0]*60
mod_number = 10**9+7

def dec2bin(target):
    amari = []
    while target != 0:
        amari.append(target%2)
        target = target//2
    amari.reverse()
    return amari

for a in alist:
    a_bin = dec2bin(int(a))
    for i in range(len(a_bin)):
        if int(a_bin[-(i+1)])==1:
            binlist[-(i+1)] += 1
            
ans = 0
for i in range(60):
    ans = (ans + binlist[-(i+1)]*(n-binlist[-(i+1)])*pow(2,i))%mod_number
    
print(ans)

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

def naive_main(nums):
    n = len(nums)
    ans = 0
    for i in range(n - 1):
        for j in range(i + 1, n):
            ans += nums[i] ^ nums[j]
    return ans

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



"""
0 0 0 1
0 0 1 0
0 0 1 0
0 1 0 0
1 0 0 0

4, 4, 6, 4

32 16 12 4
"""

max_len = len(bin(max(nums))) - 2

counter = [0 for _ in range(max_len)]
for i in range(n):
    ss = bin(nums[i])[2:]
    ss = "0" * (max_len - len(ss)) + ss
    for j in range(len(ss)):
        if ss[j] == "1":
            counter[j] += 1



ans = 0
for i in range(max_len):
    c = counter[max_len - 1 - i]
    ans += (c * (n - c) * (2 ** i)) % mod

print(int(ans) % mod)

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


def main():
    MOD = 10 ** 9 + 7
    N = int(input())
    A = [int(x) for x in input().split()]

    x = [0] * 61
    for i in range(N):
        for j in range(61):
            if A[i] >> j & 1:
                x[j] += 1
    ans = sum(A) * (N - 1)
    for i, v in enumerate(x):
        if v == 0 or v == 1:
            continue
        else:
            z = (2 ** i) * (v * (v - 1))
            ans = ans - z

    print(ans % MOD)







if __name__ == '__main__':
    main()

Solution (Python):
import sys

inf = float("inf")

def get_array(): return list(map(int, sys.stdin.readline().strip().split()))
def get_ints(): return map(int, sys.stdin.readline().strip().split())
def input(): return sys.stdin.readline().strip()

mod = 10**9+7

def sumXOR(arr, n):
    sum = 0
    for i in range(0, 64):

        
        zc = 0
        oc = 0

        
        idsum = 0
        for j in range(0, n):
            if (arr[j] % 2 == 0):
                zc = zc + 1

            else:
                oc = oc + 1
            arr[j] = arr[j]//2

            
        idsum = oc * zc * (1 << i)

        
        sum = sum + idsum
        sum%=mod

    return sum

n = int(input())
Arr = get_array()
ans = sumXOR(Arr,n)
ans %= mod
print(ans)

Solution (Python):
N=int(input())
MOD=10**9+7
L=60
ls=[int(s) for s in input().split()]
bi_ls=[0 for _ in range(L)]
for i in range(N):
  for j in range(L):
    if (2**j)&ls[i]>0:
      bi_ls[j]+=1    
ans=0
base=1
for j in range(L):
  ans=(ans+bi_ls[j]*(N-bi_ls[j])*base)%MOD
  base*=2%MOD
print(ans)

Solution (Python):
import sys

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

def main():
    md = 10 ** 9 + 7
    n = int(input())
    aa = LI()
    cnt = [[0] * 2 for _ in range(61)]
    for a in aa:
        for i in range(61):
            cnt[i][a & 1] += 1
            a >>= 1
    
    base = 1
    ans = 0
    for c0, c1 in cnt:
        ans += base * c0 * c1
        ans %= md
        base = base * 2 % md
    print(ans)

main()

Solution (Python):
def bi(x):
    x = int(x)
    i = 0
    o = [0]*61
    while x > 0:
        o[i] = x % 2
        x //= 2
        i += 1
    return o

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


a = 0
ruijoo = 1
bbb = 0
B = [0]*N
h = 0
while h < 61:
    i = 0
    isOne = 0
    while i < N:
        aaaa = A[i][h]
        isOne += aaaa
        B[i] = aaaa
        i += 1
    isZero = N - isOne
    C = [isOne,isZero]
    bbbb = 0
    i = 0
    while i < N:
        bbbb += C[B[i]]
        i += 1
    bbbb *= ruijoo
    bbb += bbbb
    bbb %= 1000000007
    ruijoo *= 2
    ruijoo %= 1000000007
    h += 1

bbb *= 500000004
bbb %= 1000000007
print(bbb)

Solution (Python):
N=int(input()) 
import math
A=list(map(int, input().split())) 
k =  len(bin(max(A))[2:])
mod = 10**9+7

c = [0]*k

for i in A:
  bit = bin(i)[2:].zfill(k)
  for j in range(k):
    if bit[j] == '1':
      c[-1-j] +=1
      
ans = 0
for i in range(k):
  ans = (ans +(2**i)*(c[i]*(N-(c[i]))))%mod
  
print(ans)

Solution (Python):
MOD = 10 ** 9 + 7
n = int(input())
m = 65
a = list(map(int, input().split()))
b = [[0] * n for i in range(m)]

for i in range(n):
    for j in range(m):
        b[j][i] = (a[i] >> j) & 1

ans = 0
d = 1
for i in range(m):
    s = sum(b[i])
    ans += s * (n-s) * d
    ans %= MOD
    d *= 2

print(ans % MOD)

Solution (Python):
n = int(input())
arr = list(map(int,input().split()))
buf = [0 for i in range(61)]

count = [[0,0] for i in range(61)]

for a in arr:
    txt = str(bin(a))[2:].zfill(61)

    for i in range(len(txt)):
        if txt[i] == "0":
            buf[i] += count[i][1]
            count[i][0] += 1
        else:
            buf[i] += count[i][0]
            count[i][1] += 1

m = 10**9 +7

buf.reverse()
ans = 0

for i in range(len(buf)):
    num = buf[i]
    if i == 0:
        base = 1
    else:
        base = base*2
    b = base%m
    b = (b*num)%m

    ans += b
    ans = ans%m


print(ans)

Solution (Python):
n = int(input())
A = list(map(int,input().split()))
MOD = 10**9 + 7
for i in range(n):
  b = format(A[i],'b').zfill(61)
  A[i] = b


bit = [0]*61
for i in range(n):
  for j in range(61):
    if A[i][j] =='1':
      bit[j] += 1

ans = 0
for k in range(61):
  multi = (bit[k]*(n-bit[k]))%MOD
  if k > 30:
    ans += (((2**(60-k))%MOD) * multi)%MOD
  else:
    ooo = ((2**(30-k))%MOD * (2**20)%MOD * (2**10)%MOD) %MOD
    ans += (ooo * multi)%MOD
  ans %= MOD
print(ans)

Solution (Python):
import sys
def input():
    return sys.stdin.readline()[:-1]
mod=10**9+7
n=int(input())
a=list(map(int,input().split()))
keta=[0]*60
lis=[]
for i in range(n):
    tmp=[]
    for j in range(60):
        if (a[i]>>j)&1==1:
            keta[j]+=1
            tmp.append(j)
    lis.append(tmp)

s=sum(a)
ans=0
for i in range(n):
    s-=a[i]
    j=0

    for j in range(len(lis[i])):
        tmp2=lis[i][j]
        keta[tmp2]-=1
        ans+=(2**tmp2)*((n-(i+1)-keta[tmp2]*2))
    ans+=s
    ans%=mod
print(ans%mod)

Solution (Python):
n=int(input())
a=list(map(int,input().split()))
keta=[0 for i in range(61)]
ans=0
for i in range(n):
  b=a[i]
  cnt=0
  while(b>=1):
    if b%2==1:
      keta[cnt]+=1
    b=b//2
    cnt+=1

for i in range(61):
  
  
  ans+=(keta[i]*(n-keta[i])*(2**i))%(1000000007)
while(ans>1000000007):
  ans%=1000000007
print(ans)

Solution (Python):
mod=10**9+7
n=int(input())
a=list(map(int,input().split()))
l=[0 for i in range(60)]
for x in a:
    x=bin(x)[2:]
    col=0
    for b in x[::-1]:
        if b=='1':
            l[col] = l[col]+1
        col+=1
l2=[0 for i in range(60)]
for x in a:
    x=bin(x)[2:]
    x=x.zfill(60)
    col=0
    for b in x[::-1]:
        if b=='0':
            l2[col] = l2[col] + l[col]
        else:
            l2[col] = l2[col] + n - l[col]
        col+=1
cnt=0
c=1
for i in range(60):
    cnt+=l2[i]*c
    c*=2
    c%=mod
print(cnt//2%mod)

Solution (Python):

def main():
    n = int(input())
    xs = list(map(int, input().split()))
    mod = 10 ** 9 + 7

    ps = [
        sum((x & (1<<i)) >> i for x in xs)
        for i in range(60)
    ]
    ms = [n - p for p in ps]

    ans = 0

    for i in range(60):
        s = 0
        for x in xs:
            b = (x & (1<<i)) >> i
            if b == 1:
                ps[i] -= 1
                s += ms[i]
            else:
                ms[i] -= 1
                s += ps[i]
        ans += s * (2**i % mod)
        ans = ans % mod

    print(ans)

main()

Solution (Python):


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

ans = 0
mod = 10**9 + 7


b = bin(max(A))

l = len(b) - 2


for j in range(l):
    tmp = 0
    for i in range(N):
        if (A[i] >> j) % 2 == 1:
            tmp += 1

    ans += (2**j) * tmp * (N-tmp)
    ans %= mod
print(ans)

Solution (Python):
def tentwo(N):
    ret = [0] * 60
    NN = N
    for i in range(60):
        ret[i] = NN % 2
        NN //= 2
    return ret

N = int(input())

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

B = [0] * N

for i in range(N):
    B[i] = tentwo(A[i])

ans = 0
for j in range(60):
    count = 0
    for i in range(N):
        if B[i][j] == 1:
            count += 1
    ans = (ans + (count * (N-count)) * (2 ** j)) % (10**9 + 7)

print(ans)

Solution (Python):
import numpy as np

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


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):
bits = [0]*60

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

mod = pow(10, 9) + 7
res = 0
eles = 0
mx = 0
for i in range(n-1, -1, -1):
	ele = arr[i]
	mx = max(mx, ele.bit_length())
	add = 0
	for j in range(mx):
		if ele&(1<<j):
			add += (eles - bits[j])*pow(2, j)
			bits[j] += 1
		else:
			add += (bits[j])*pow(2, j)
	res += add
	res %= mod
	eles += 1
print(res)

Solution (Python):
def main():
    import sys

    input = sys.stdin.readline

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

    b = [0] * 60

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

    ret = 0
    for j in range(60):
        ret = (ret + b[j] * (n - b[j]) * (1 << j)) % mod

    print(ret)


if __name__ == '__main__':
    main()

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

pow2 = [1]
mod = 1000000007

for i in range(1,61):
    pow2.append(pow2[-1]*2 % mod)

seq = list(map(lambda x: bin(int(x))[2:], input().split()))

onec = [0 for i in range(61)]

for i in range(n):
    ln = len(seq[i])
    for j in range(ln):
        if seq[i][ln-1-j] == '1':
            onec[j] += 1

sm = 0

for i in range(61):
    sm += onec[i]*(n-onec[i]) * pow2[i] % mod
    
print(sm % mod)

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

b = 1
b2 = 1
ans = (base * N) % MOD
for i in range(60):
	s = 0
	k = 0
	for a in A:
		if (a // b) % 2 == 1:
			k -= 1
			s += 1
		else:
			k += 1
	ans = (ans + ((b2 * s * k) % MOD)) % MOD
	b2 = b2 * 2 % MOD
	b = b * 2

ans = (ans * ((MOD + 1) // 2)) % MOD
print(ans)