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

x = 1
ans = 0
for i in range(60):
    num1s = 0
    for a in As:
        if a & x:
            num1s += 1
    ans += (x % MOD) * num1s * (N - num1s)
    ans %= MOD
    x <<= 1
print(ans)

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

l = 60

ones = [0] * l
for i in range(n):
    b = bin(a[i])[2:].zfill(l)
    for j in range(l):
        if b[j] == '1':
            ones[j] += 1


ans = 0
for i in range(l):
    ans += ones[i] * (n - ones[i]) * 2 ** (l - i - 1)
    ans = ans % (10 ** 9 + 7)
print(ans)

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

bt = [0]*60

ans = 0

for j in range(60):
    for i in range(n):
        s = a[i]
        if((s>>j) & 1):
            ans += (i-bt[j])*(2**j)
            ans %= mod
            bt[j] += 1
        else:
            ans += bt[j]*(2**j)
            ans %= mod

print(ans)

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

bit = [0] * 62

for a in al:
    for i in range(62):
        bit[i] += (a % 2)
        a = a // 2

ans = 0
p = 1
for i in range(62):
    ans += bit[i] * (n - bit[i]) * p
    ans %= 10**9 + 7
    p *= 2

print(ans)

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

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

dp = [0] * 62
for a in A :
    for i in range(62) :
        if a & (1 << i) :
            dp[i] += 1

ret = 0
for i in range(62) :
    ret += (N * (N - 1) - (N - dp[i]) * (N - dp[i] - 1)) // 2 * (1 << i) % mod
    ret -= dp[i] * (dp[i] - 1) // 2 * (1 << i) % mod
    ret %= mod

print(ret)

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

Solution (Python):
n = int(input())
one = [0 for i in range(70)]
zero = [n for i in range(70)]
for c in input().split():
  b = list(bin(int(c)))
  b.reverse()
  j = 0
  for i in b:
    if i == "b":
      break
    else:
      if i == '1':
        one[j] += 1
        zero[j] -= 1
    j += 1
ans = 0
mod = 10 ** 9 + 7

for j in range(70):
  ans += one[j] * zero[j] * 2 ** j
  ans %= mod
print(ans)

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

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


N1 = []
for i in range(0,61):
    m = sum([a % 2 for a in A])
    N1.append(m)
    for j in range(N):
        A[j] = A[j] >> 1

ans = 0
for i,n1 in enumerate(N1):
    n0 = N-n1
    m = n0 * n1
    ans += 2**i * m
    ans = ans % MOD
print(ans % MOD)

Solution (Python):
import sys
sys.setrecursionlimit(2147483647)
INF=float("inf")
MOD=10**9+7
input=lambda:sys.stdin.readline().rstrip()
def resolve():
    n=int(input())
    A=list(map(int,input().split()))
    ans=(n-1)*sum(A)
    ans%=MOD

    for d in range(60,-1,-1):
        cnt=sum((a>>d)&1 for a in A)
        k=cnt*(cnt-1)
        ans-=k<<d
        ans%=MOD
    print(ans)
resolve()

Solution (Python):
def main():
    n=int(input())
    a=list(map(int,input().split()))
    l1=[0]*61
    for i in a:
        j=list(reversed(bin(i)[2:]))
        for k in range(len(j)):
            if j[k]=="1":
                l1[k]+=1
    l0=[n-i for i in l1]
    ans=0
    mod=10**9+7
    for i in range(len(l1)):
        ans=(ans+l0[i]*l1[i]*pow(2,i,mod))%mod
    print(ans)
main()

Solution (Python):
N = int(input())
A = [int(a) for a in input().split()]
P = 10**9+7
ans = 0
for i in range(60):
    s = sum([a>>i & 1 for a in A])
    ans += s * (N-s) << i
    ans %= P

print(ans)

Solution (Python):
def fastio():
    import sys
    from io import StringIO 
    from atexit import register
    global input
    sys.stdin = StringIO(sys.stdin.read())
    input = lambda : sys.stdin.readline().rstrip('\r\n')
    sys.stdout = StringIO()
    register(lambda : sys.__stdout__.write(sys.stdout.getvalue()))
fastio()

MOD = 10**9 + 7
I = lambda:list(map(int,input().split()))

n, = I()
a = I()
ans = 0
for bit in range(64):
    c = [0, 0]
    for i in a:
        c[(i >> bit)&1] += 1
    ans += c[0] * c[1] * 2**bit
    ans %= MOD
    
print(ans)

Solution (Python):

import sys
input = sys.stdin.buffer.readline


from collections import defaultdict

con = 10 ** 9 + 7


def getlist():
	return list(map(int, input().split()))


def main():
	N = int(input())
	A = getlist()
	D0 = defaultdict(int)
	D1 = defaultdict(int)
	for i in range(N):
		a = A[i]
		for j in range(61):
			if a % 2 == 0:
				D0[j] += 1
			else:
				D1[j] += 1
			a = int(a // 2)

	ans = 0
	for i in range(61):
		ans += (D0[i] * D1[i] * (2 ** i)) % con

	ans = ans % con
	print(ans)

if __name__ == '__main__':
	main()

Solution (Python):

import sys
from collections import defaultdict, deque
from operator import itemgetter
from heapq import heappop, heappush
input = sys.stdin.readline
def inpl(): return list(map(int, input().split()))
MOD = 10**9 + 7

N = int(input())
A = sorted(inpl())
DP = [0]*60
B = [pow(2, i, MOD) for i in range(60)]

for i in range(N):
    a = A[i]*1
    
    for j in range(60):
        DP[j] += a&1
        a //= 2

ans = 0
for i in range(N):
    a = A[i] * 1
    for j in range(60):
        DP[j] -= a&1
        if a&1:
            ans = (ans + B[j]*(N-1-i-DP[j]))%MOD
        else:
            ans = (ans + B[j]*(DP[j]))
        a //= 2

print(ans%MOD)

Solution (Python):
n=int(input())
a=list(map(int,input().split()))
s=[0]*60
m=10**9+7
for i in a:
    t=bin(i)[2:][::-1]
    for i in range(len(t)):
        if t[i]=="1":
            s[i]+=1
c=0
for i in range(60):
    c=(c+s[i]*(n-s[i])*pow(2,i,m))%m
print(c)

Solution (Python):
def examD(mod):
    N = I(); A = LI()
    d = defaultdict(int)
    for i in range(N):
        cur = A[i]
        j = 1
        while(cur>0):
            if cur&1==1:
                d[j] +=1
            j +=1
            cur >>=1
    ans = 0
    for i,j in d.items():
        ans += j*(N-j) * 2**(i-1)
        ans %=mod
    print(ans)
    return

def examE():
    return

def examF():
    return

import sys,copy,bisect,itertools,heapq,math
from heapq import heappop,heappush,heapify
from collections import Counter,defaultdict,deque
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))
def LSI(): return list(map(str,sys.stdin.readline().split()))
def LS(): return sys.stdin.readline().split()
def SI(): return sys.stdin.readline().strip()
mod = 10**9 + 7
inf = float('inf')

if __name__ == '__main__':
    examD(mod)

Solution (Python):
def main():
    n = input()
    aa = map(int, raw_input().split())
    mod = 10 ** 9 + 7 
    s = 0
    for i in xrange(60):
        c0 = 0
        c1 = 0
        mask = 1 << i
        for a in aa:
            if a & mask:
                c1 += 1
            else:
                c0 += 1
        s = (s + 2 ** i * c0 * c1) % mod
    print s


main()

Solution (Python):

N = int(input())

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

for i in range(61):

    z = 0
    o = 0
    now = 2 ** i

    for j in A:

        if j & now == 0:
            z += 1
        else:
            o += 1

    ans += now * (z * o)
    ans %= 10 ** 9 + 7

print (ans)

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

ans = 0
A.sort()
M = len(bin(A[-1])) - 2

p = 1
for i in range(M):
  z = 0
  t = 1 << i
  for j in range(N):
    if A[j] & t == 0:
      z += 1
  o = N - z
  ans = (ans + z * o * p) % MOD
  p *= 2

print(ans)

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

Solution (Python):
import math

n=int(input())
alist = [int(i) for i in input().split()]
alist=sorted(alist)

keta=math.floor(math.log(max(alist[-1],1), 2))+1
zeros=[0]*keta
ones=[0]*keta

for al in alist:
    kaz2=bin(al)[2:]
    kaz2=(keta-len(kaz2))*'0'+kaz2
    for i in range(keta):
        if kaz2[i]=='1':
            ones[i]+=1
        else:
            zeros[i]+=1

answer=0
for i in range(keta):
    tas=ones[-i-1]*zeros[-i-1]
    tas*=((2**i)%(10**9+7))
    answer+=tas%(10**9+7)

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

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

m = max(A).bit_length()
cnt = 0
k = 1
for i in range(m):
    s = sum((v >> i) & 1 for v in A)
    cnt += s*(N-s)*k
    cnt %= MOD

    k *= 2
    k %= MOD

print(cnt)

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

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

cnt = [0] * 60
for num in a:
    for j in range(60):
        cnt[j] += (num >> j) % 2

ans = 0
for b in range(60):
    ans += cnt[b] * (n - cnt[b]) << b
    ans %= MOD

print(ans)

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

mod = 10**9+7

m = 62
d = [0]*m

ans = 0
for i in range(n):
    ai = a[i]
    for j in range(m):
        
        if ai&(1<<j):
            ans += (1<<j)*(i-d[j])
            d[j] += 1
        
        else:
            ans += (1<<j)*d[j]
    ans %= mod

print(ans)

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

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

mod = 10**9+7

ans = 0
for i in range(60):
    p = 0
    q = 0
    for a in A:
        if a & (1<<i):
            p += 1
        else:
            q += 1
    ans = (ans + ((1<<i) %mod * p * q) % mod) % mod
print(ans)

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

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

ans = 0

C = [0]*61
for a in A:
    for idx in range(61):
        if (1<<idx) & a:
            C[idx] += 1

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

Solution (Python):
import bisect
import heapq
import itertools
import math
import operator
import os
import re
import string
import sys
from collections import Counter, deque, defaultdict
from copy import deepcopy
from decimal import Decimal
from fractions import gcd
from functools import lru_cache, reduce
from operator import itemgetter, mul, add, xor

import numpy as np

if os.getenv("LOCAL"):
    sys.stdin = open("_in.txt", "r")

sys.setrecursionlimit(10 ** 9)
INF = float("inf")
IINF = 10 ** 18
MOD = 10 ** 9 + 7


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

A = np.array(A, dtype=int)
ans = 0

d = 1
while d < (1 << 60):
    cnt = np.count_nonzero(A & d)
    ans += (N - cnt) * cnt * d
    ans %= MOD
    d <<= 1
print(ans)

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

ans = 0
for d in range(60):
    zero = 0
    one = 0
    for a in A:
        if ((1 << d) & a) != 0:
            one += 1
        else:
            zero += 1

    ans += one * zero * (1 << d)
    ans %= MOD

print(ans)

Solution (Python):
def p_d():
    n = int(input())
    *A, = map(int, input().split())
    mod = 10 ** 9 + 7
    max_bit = len(bin(max(A))) - 2
    ans = 0
    for i in range(max_bit):
        count = [0] * 2
        for a in A:
            count[a >> i & 1] += 1
        ans += (1 << i) * count[0] * count[1]
        ans %= mod
    print(ans)
    
p_d()

Solution (Python):


M = 64
P = 10 ** 9 + 7


def solve(n, xs):
    su = 0
    for i in range(M):
        zc = 0
        oc = 0
        idsu = 0
        for j in range(n):
            if xs[j] % 2 == 0:
                zc += 1
            else:
                oc += 1
            xs[j] //= 2
        idsu = oc * zc * (1 << i)
        su += idsu
        su %= P
    return su


def main():
    n = int(input())
    xs = [int(x) for x in input().split()]
    res = solve(n, xs)
    print(res)


if __name__ == "__main__":
    main()

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

sys.setrecursionlimit(10**7)
def input():
    return sys.stdin.readline()[:-1]

mod = 10**9 + 7

def I(): return int(input())
def II(): return map(int, input().split())
def III(): return list(map(int, input().split()))
def Line(N,num):
    if N<=0:
        return [[]]*num
    elif num==1:
        return [I() for _ in range(N)]
    else:
        read_all = [tuple(II()) for _ in range(N)]
        return map(list, zip(*read_all))



N = I()
A = III()

for i in range(N):
    A[i] = str(format(A[i],'b')).zfill(60)

ans = 0
for i in range(60):
    zc = 0
    oc = 0
    for j in range(N):
        if A[j][59-i]=='0':
            zc += 1
        else:
            oc += 1
    ans += 2**i*zc*oc
    ans %= mod
print(ans)

Solution (Python):
MOD = 10**9+7
n = int(input())
a = list(map(int, input().split()))
ans = 0
for b in range(61):
	zero, one = 0, 0
	for x in a:
		if (x>>b)&1:
			one += 1
		else:
			zero += 1
	ans += zero*one*(1<<b)
	ans %= MOD
print(ans)

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

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

ANS=0

for keta in range(61):
    ZERO=0
    ONE=0

    for a in A:
        if a & (1<<keta)!=0:
            ONE+=1
        else:
            ZERO+=1

    ANS=(ANS+ONE*ZERO*(1<<keta))%mod

print(ANS)

Solution (Python):
import sys
input = sys.stdin.readline
n = int(input())
A = list(map(int,input().split()))
B = [0] * 61

for i in range(n):
    b = list(format(A[i], "b").zfill(61))
    for j in range(61):
        if b[j] == "1":
            B[j] += 1

mod=10**9+7
M2 = [1]
for i in range(70):
    M2.append((M2[-1] * 2) % mod)


ans = 0
for i in range(61):
    p = (B[i] * (n-B[i]) * M2[61-i-1]) % mod
    ans = (ans+p) % mod
print(ans)

Solution (Python):
N = int(input())
A = list(map(int, input().split()))
M = 61
ans = 0
mod = 10**9+7
for i in range(M):
    b = 1<<i
    cnt = 0
    for a in A:
        if (a>>i)&1:
            cnt+=1
    ans+=b*(N-cnt)*cnt
    ans%=mod
print(ans)

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

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

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

Solution (Python):
import sys

def get(x,n):
    return ((1<<x)&(n))!=0


def main():
    mod=1000000000+7
    n=int(sys.stdin.readline())
    a=list(map(int,sys.stdin.readline().split()))
    ans=0
    cur=1
    for x in range(60):
        res=get(x,a[-1])
        now=res
        nnow=not res
        total=0
        for i in range(n-2,-1,-1):
            res=get(x,a[i])
            now+=res
            nnow+=not res
            if res:
                total+=nnow
            else:
                total+=now
        ans+=cur*total
        ans%=mod
        cur*=2
    print(ans%mod)
main()

Solution (Python):
def main():
    N = int(input())
    A = map(int, input().split())
    l0 = [0] * 61
    l1 = [0] * 61
    for i in A:
        t = format(i, 'b').zfill(61)
        for j, v in enumerate(t):
            if v == '1':
                l1[j] += 1
            else:
                l0[j] += 1
    a = 0
    for i in range(61):
        a += ((2 ** i) * (l0[60-i] * l1[60-i])) % (10 ** 9 + 7)
    return a % (10**9 + 7)

print(main())

Solution (Python):

from collections import defaultdict,deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS():return [list(x) for x in sys.stdin.readline().split()]
def S():
    res = list(sys.stdin.readline())
    if res[-1] == "\n":
        return res[:-1]
    return res
def IR(n):
    return [I() for i in range(n)]
def LIR(n):
    return [LI() for i in range(n)]
def SR(n):
    return [S() for i in range(n)]
def LSR(n):
    return [LS() for i in range(n)]

sys.setrecursionlimit(1000000)
mod = 1000000007

def solve():
    n = I()
    a = LI()
    m = 61
    d = [0]*m
    ans = 0
    p = [pow(2,j,mod) for j in range(m)]
    for i in range(n):
        ai = a[i]
        for j in range(m):
            if ai&(1<<j):
                ans += (i-d[j])*p[j]%mod
                ans %= mod
                d[j] += 1
            else:
                ans += d[j]*p[j]%mod
                ans %= mod
    print(ans)
    return


if __name__ == "__main__":
    solve()

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

ans = 0
for keta in range(61):
    now = 0
    for x in a:
        if x&(1<<keta):
            now += 1
    ans += (now*(n-now))*2**keta
    ans %= mod

print(ans)

Solution (Python):
MOD=10**9+7 
def sumXOR( arr, n): 
	sum = 0
	for i in range(0, 75): 
		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] >>=1 
		idsum = (oc * zc * pow(2,i,MOD))%MOD
		sum = sum%MOD + idsum; 
		sum%=MOD 
	return sum%MOD 
n=int(input())
arr=[int(i) for i in input().split()]
MOD=10**9+7 
print(sumXOR(arr,n)%MOD)

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

MOD = 10 ** 9 + 7
ans = 0
m = 1
for _ in range(60):
    bit = sum(a & m for a in aaa)
    bit //= m
    non_bit = n - bit
    ans = (ans + bit * non_bit * m) % MOD
    m <<= 1
print(ans)

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

ans = 0

for k in range(60):
  cnt = [0] * 2
  for i in range(N):
    ans += cnt[(A[i] >> k & 1) ^ 1] << k
    cnt[A[i] >> k & 1] += 1

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

Solution (Python):



import sys
read = sys.stdin.read
readline = sys.stdin.readline 
readlines = sys.stdin.readlines

n = int(input())
a = [int(i) for i in readline().split()]

ans = 0

MOD = (10**9+7)
for i in range(62):
    c = 0
    for ai in a:
        if ai&(1<<i): c += 1
    
    r = c*(n-c)
    ans += (1<<i)*r
    ans %= MOD


print(ans)