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())
mod = 10 ** 9 + 7

A = [int(x) for x in input().split()]
ans = 0
for i in range(60):
    cnt = 0
    for a in A:
        cnt += a >> i & 1
    ans += cnt * (N - cnt) * (1 << i)
print(ans % mod)

Solution (Python):
def run():
  bit = 60
  N = int(input())
  a_li = list(map(int, input().split()))
  ans = 0
  dp = [[0]*bit for i in range(N)]
  for i in range(bit):
    dp[0][i] = (a_li[0] >> i) & 1
  for i in range(1, N):
    for j in range(bit):
      a_j = (a_li[i] >> j) & 1
      dp[i][j] = dp[i-1][j] + a_j
      ans += abs(a_j*i - dp[i-1][j]) << j
  print(ans%(10**9+7))

if __name__ == '__main__':
  run()

Solution (Python):
def run():
  b = 10**9+7
  bit = 60
  N = int(input())
  a_li = list(map(int, input().split()))
  ans = 0
  dp = [[0]*bit for i in range(N)]
  for i in range(bit):
    dp[0][i] = (a_li[0] >> i) & 1
  for i in range(1, N):
    tem = 0
    for j in range(bit):
      a_j = (a_li[i] >> j) & 1
      dp[i][j] = dp[i-1][j] + a_j
      if a_j == 1:
        tem += (i-dp[i-1][j]) << j
      else:
        tem += dp[i-1][j] << j
    
    ans += tem
  
  print(ans%b)

if __name__ == '__main__':
  run()

Solution (Python):
import math
import  numpy as np

N = int(input())
a = np.array(list(map(int, input().split())))

ans = 0
a_max = max(a)

if a_max==0:alog=1
else:alog = int(math.log2(a_max))+1

for i in range(alog):
    p = pow(2, i)
    cnt = np.count_nonzero((a >> i)& 1 == 1)
    
    ans += cnt * (N - cnt)*(2**i)
print(ans%(10**9+7))

Solution (Python):
import numpy as np
N = int(input())
As = np.array(list(map(int, input().split())))
modNum = 10**9 + 7
sum = 0
for d in range(60):
	n1 = np.count_nonzero((As >> d) & 1 == 1)
	sum += (2 ** d) * n1 * (N - n1)
print(sum % modNum)

Solution (Python):
def solve():
    import numpy as np
    from sys import stdin
    f_i = stdin
    
    mod = 10 ** 9 + 7
    
    N = int(f_i.readline())
    A = np.array(f_i.readline().split(), dtype=np.int64)
    
    ans = 0
    for i in range(60):
        cnt = np.count_nonzero((A >> i) & 1)
        ans += (1 << i) * cnt * (N - cnt)
    
    print(ans % mod)

solve()

Solution (Python):
N = int(input())
A = list(map(int, input().split()))
B = [0]*60
for a in A:
    for i in range(len(B)):
        if a & (2**i):
            B[i] += 1
ans = 0
for i, b in enumerate(B):
    ans += 2**i * b * (N-b)
ans %= 10**9+7
print(ans)

Solution (Python):
import sys
def main():
    MOD = 10**9+7
    input = sys.stdin.readline
    N = int(input())
    A = list(map(int, input().split()))

    count = [0] * 61
    ans = 0
    for a in A:
        for i, c in enumerate(format(a, 'b')[::-1]):
            if c == '1':
                count[i] += 1

    for i, c in enumerate(count):
        tmp = (c*(N-c) * pow(2, i, MOD))%MOD
        ans = (ans + tmp)%MOD
    print(ans)


if __name__ == '__main__':
    main()

Solution (Python):
import sys
def main():
    MOD = 10**9+7
    input = sys.stdin.readline
    N = int(input())
    A = list(map(int, input().split()))

    count = [0] * 61
    ans = 0
    for a in A:
        for i, c in enumerate(format(a, 'b')[::-1]):
            if c == '1':
                count[i] += 1

    for i, c in enumerate(count):
        tmp = (c*(N-c) * pow(2, i, MOD))%MOD
        ans = (ans + tmp)%MOD
    print(ans)


if __name__ == '__main__':
    main()

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=0
    for d in range(60,-1,-1):
        k=sum((a>>d)&1 for a in A)
        ans+=(k*(n-k))<<d
        ans%=MOD

    print(ans)
resolve()

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

Solution (Python):
import math
n=int(input())
al=list(map(int,input().split()))
a=['{:060b}'.format(x) for x in al]
a=''.join(a)

m=math.ceil(math.log(max(1,max(al)),2))

ans=0
for i in range(m):
  sum1=a[59-i::60].count('1')
  sum0=n-sum1
  ans+=2**i*sum1*sum0

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

Solution (Python):
import sys


def solve():
    input = sys.stdin.readline
    mod = 10 ** 9 + 7
    n = int(input().rstrip('\n'))
    a = list(map(int, input().rstrip('\n').split()))
    ls = [0] * 60
    t = 0
    for i in range(60):
        for av in a:
            ls[i] += av >> i & 1
        t += 2 ** i * ls[i] * (n - ls[i])
        t %= mod
    print(t)


if __name__ == '__main__':
    solve()

Solution (Python):
import numpy as np


def solve(string):
    n, *a = map(int, string.split())
    a = np.asarray(a)
    m = 10**9 + 7
    ans = 0
    for i in range(60):
        s = int((a & 1).sum())
        a >>= 1
        ans += s * (n - s) * pow(2, i, m) % m
        ans %= m
    return str(ans)


if __name__ == '__main__':
    import sys
    print(solve(sys.stdin.read().strip()))

Solution (Python):
"""
def solve(string):
    n, *a = map(int, string.split())
    a = ("{:060b}".format(_a) for _a in a)
    m, ans = 10**9 + 7, 0
    for s in map(lambda x: x.count("1"), zip(*a)):
        ans <<= 1
        ans += s * (n - s)
        ans %= m
    return str(ans)


if __name__ == '__main__':
    import sys
    print(solve(sys.stdin.read().strip()))
"""
import numpy as np


def solve(string):
    n, *a = map(int, string.split())
    
    a = np.asarray(a, dtype=np.int64)
    m = 10**9 + 7
    ans = 0
    for i in range(60):
        s = int((a & 1).sum())
        a >>= 1
        
        ans += s * (n - s) * pow(2, i, m) % m
        ans %= m
    return str(ans)


if __name__ == '__main__':
    import sys
    print(solve(sys.stdin.read().strip()))

Solution (Python):
"""
def solve(string):
    n, *a = map(int, string.split())
    a = ("{:060b}".format(_a) for _a in a)
    m, ans = 10**9 + 7, 0
    for s in map(lambda x: x.count("1"), zip(*a)):
        ans <<= 1
        ans += s * (n - s)
        ans %= m
    return str(ans)


if __name__ == '__main__':
    import sys
    print(solve(sys.stdin.read().strip()))
"""
import numpy as np


def solve(string):
    n, *a = map(int, string.split())
    
    a = np.asarray(a, dtype=np.int64)
    m = 10**9 + 7
    ans = 0
    for i in range(60):
        s = int((a & 1).sum())
        a >>= 1
        
        ans = (ans + s * (n - s) * (1 << i)) % m
    return str(ans)


if __name__ == '__main__':
    import sys
    print(solve(sys.stdin.read().strip()))

Solution (Python):
def solve(string):
    n, *a = map(int, string.split())
    a = ("{:060b}".format(_a) for _a in a)
    m, ans = 10**9 + 7, 0
    for c in zip(*a):
        s = c.count("1")
        ans <<= 1
        ans += s * (n - s)
        ans %= m
    return str(ans)


if __name__ == '__main__':
    import sys
    print(solve(sys.stdin.read().strip()))

Solution (Python):
def solve(string):
    n, *a = map(int, string.split())
    a = ("{:060b}".format(_a) for _a in a)
    m, ans = 10**9 + 7, 0
    for s in map(lambda x: x.count("1"), zip(*a)):
        ans <<= 1
        ans += s * (n - s)
        ans %= m
    return str(ans)


if __name__ == '__main__':
    import sys
    print(solve(sys.stdin.read().strip()))

Solution (Python):
def solve(string):
    n, *a = map(int, string.split())
    m = 10**9 + 7
    ans = 0
    for s in map(lambda x: x.count("1"), zip(*("{:060b}".format(_a) for _a in a))):
        ans <<= 1
        ans += s * (n - s)
        ans %= m
    return str(ans)


if __name__ == '__main__':
    import sys
    print(solve(sys.stdin.read().strip()))

Solution (Python):
def solve(string):
    n, *a = map(int, string.split())
    a = ("{:060b}".format(_a) for _a in a)
    m = 10**9 + 7
    ans = 0
    for s in map(lambda x: x.count("1"), zip(*a)):
        ans <<= 1
        ans += s * (n - s)
        ans %= m
    return str(ans)


if __name__ == '__main__':
    import sys
    print(solve(sys.stdin.read().strip()))

Solution (Python):
from itertools import starmap


def solve(string):
    n, *a = map(int, string.split())
    a = ["{:060b}".format(_a) for _a in a]
    m = 10**9 + 7
    ans = 0
    for s in starmap(lambda *x: x.count("1"), zip(*a)):
        ans <<= 1
        ans += s * (n - s)
        ans %= m
    return str(ans)


if __name__ == '__main__':
    import sys
    print(solve(sys.stdin.read().strip()))

Solution (Python):
def solve(string):
    n, *a = map(int, string.split())
    a = ["{:060b}".format(_a) for _a in a]
    m = 10**9 + 7
    ans = 0
    for s in map(lambda x: x.count("1"), zip(*a)):
        ans <<= 1
        ans += s * (n - s)
        ans %= m
    return str(ans)


if __name__ == '__main__':
    import sys
    print(solve(sys.stdin.read().strip()))

Solution (Python):
def solve(string):
    n, *a = map(int, string.split())
    a = ["{:060b}".format(_a) for _a in a]
    m = 10**9 + 7
    ans = 0
    *s, = map(lambda x: x.count("1"), zip(*a))
    for _s in s:
        ans <<= 1
        ans += _s * (n - _s)
        ans %= m
    return str(ans)


if __name__ == '__main__':
    import sys
    print(solve(sys.stdin.read().strip()))

Solution (Python):
def solve(string):
    n, *a = map(int, string.split())
    a = ["{:060b}".format(_a) for _a in a]
    m = 10**9 + 7
    ans = 0
    *s, = map(lambda x: x.count("1"), zip(*a))
    for i, _s in enumerate(s):
        ans += _s * (n - _s) * pow(2, 59 - i, m)
        ans %= m
    return str(ans)


if __name__ == '__main__':
    import sys
    print(solve(sys.stdin.read().strip()))

Solution (Python):
def solve(string):
    n, *a = map(int, string.split())
    a = ["{:060b}".format(_a) for _a in a]
    m = 10**9 + 7
    ans = 0
    for i, d in enumerate(zip(*a)):
        
        s = d.count("1")
        ans += s * (n - s) * pow(2, 59 - i, m)
        ans %= m
    return str(ans)


if __name__ == '__main__':
    import sys
    print(solve(sys.stdin.read().strip()))

Solution (Python):
def solve(string):
    n, *a = map(int, string.split())
    a = ["{:060b}".format(_a) for _a in a]
    m = 10**9 + 7
    ans = 0
    for d in zip(*a):
        ans <<= 1
        s = "".join(d).count("1")
        ans += s * (n - s)
        ans %= m
    return str(ans)


if __name__ == '__main__':
    import sys
    print(solve(sys.stdin.read().strip()))

Solution (Python):
def solve(string):
    n, *a = map(int, string.split())
    a = ["{:060b}".format(_a) for _a in a]
    m = 10**9 + 7
    ans = 0
    for i, d in enumerate(zip(*a)):
        s = "".join(d).count("1")
        ans += s * (n - s) * pow(2, 59 - i, m)
        ans %= m
    return str(ans)


if __name__ == '__main__':
    import sys
    print(solve(sys.stdin.read().strip()))

Solution (Python):
N = int(input())
A = [str(bin(a)).lstrip('0b').zfill(60) for a in map(int,input().split())]
A_rev = list(zip(*A))

ans = 0
for i, a in enumerate(A_rev):
	k = a.count('1')
	ans+=(k*(N-k)*2**(59-i))
print(ans%(10**9+7))

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

ans=0
MOD=10**9+7

for k in range(60):
    x0=0
    x1=0
    for i in range(n):
        cnt=(a[i]>>k)&1
        if cnt==0:
            x0+=1
        else:
            x1+=1

    tmp=1
    for j in range(k):
        tmp*=2
        tmp%=MOD

    su=(x0*x1)*tmp%MOD
    ans+=su
    ans%=MOD

print(ans)

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

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

    mod = 10 ** 9 + 7

    a_bin = [format(i, 'b') for i in a]

    m = len(max(a_bin, key = len))

    ans = 0

    for i in range(n):
        a_bin[i] = '0' * (m - len(a_bin[i])) + a_bin[i]

    for i in range(1, m+1):
        count = [0, 0]
        for j in a_bin:
            count[int(j[-i])] += 1
        ans += count[0] * count[1] * 2 ** (i-1)

    print(ans % mod)

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

    a = np.array(a)
    ans = 0
    mod = 10**9 + 7

    for i in range(60):
        count = np.count_nonzero(a & 1)
        ans += count * (n - count) * 2 ** i
        a >>= 1

    print(ans % mod)

if __name__ == '__main__':
    main2()

Solution (Python):
MOD = 10**9 + 7
def solve(n, a, p=60):
    res, m = 0, 1
    for i in range(p):
        y = sum(x & m for x in a) // m
        res += y * (n-y) * m
        m *= 2
    return res % MOD

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

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

Solution (Python):
import numpy as np

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

mod = 10 ** 9 + 7
s = 0

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

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

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


def main():
    N = int(input())
    A = list(map(int, input().split()))
    zeros = [0] * 60
    ones = [0] * 60
    for a in A:
        for i, c in enumerate(bin(a)[2:].zfill(60)):
            if c == '0':
                zeros[59 - i] += 1
            else:
                ones[59 - i] += 1
    ans = 0
    for i in range(60):
        ans += zeros[i] * ones[i] * (2 ** i)
        ans %= MOD
    print(ans)


if __name__ == '__main__':
    main()

Solution (Python):
n = int(raw_input())
l = [int(x) for x in raw_input().split()]
ret = 0
for bit in xrange(62):
  num = sum([(l[i] & (1 << bit)) > 0 for i in xrange(n)])
  ret += num * (n - num) * (1<<bit)
print ret % 1000000007

Solution (Python):
import numpy as np

MOD = 10 ** 9 + 7

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

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

ans %= 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):
    t = arr & 1
    c1 = np.count_nonzero((arr & 1))
    s += 2 ** i * c1 * (n - c1)
    arr >>= 1

print(s % mod)

Solution (Python):
n=int(input())
mod=10**9+7;ans=0
a=list(map(int,input().split()))
for i in range(61):
  checkbit=1 << i
  cnt=sum([1 for j in a if j & checkbit])
  ans+=checkbit*cnt*(n-cnt)
  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
ans = 0

for i in range(61):
    cnt = np.count_nonzero(A & 1)
    ans += (2 ** i) * cnt * (N - cnt)
    A >>= 1

print(ans % MOD)

Solution (Python):
n = int(input())
a = list(map(int,input().split()))
for i in range(n):
    a[i] = str(bin(a[i]))

ans = [0] * 65
for i in a:
    for j in reversed(range(len(i))):
        if i[j] == '1':
            ans[-len(i)+j] += 1
        elif i[j] == '0':
            continue
        elif i[j] == 'b':
            break

tmp = 0
for i in range(len(ans)):
    tmp += 2 ** abs(i - 64) * (n - ans[i]) * ans[i]
    
    tmp %= 10**9+7

print(tmp)

Solution (Python):
n = int(input())
a = [int(i) for i in input().split()]

mod = 10 ** 9 + 7

j_max = 0
cnt = [0] * 60
for i in range(n):
    for j in range(60):
        cnt[j] += a[i] % 2
        a[i] = a[i] // 2
        if a[i] == 0:
            j_max = max(j_max, j)
            break

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

print(ans)

Solution (Python):

MOD = 10 ** 9 + 7
n = int(input())
A = list(map(int, input().split()))
ans = 0
b = 1
for _ in range(60):
    sm = sum(a&b for a in A)
    sm //= b
    ans = (ans + sm * (n-sm) * b) % MOD
    b<<=1
print (ans)

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

for k in range(60):
    zero = 0
    one = 0
    for i in range(N):
        
        x = (A[i] >> k) & 1
        if x == 0: zero += 1
        else: one += 1
    ans += (2**k * (zero * one)) % mod

print(ans % mod)

Solution (Python):
n=int(input())
a=list(map(int,input().split()))
l=[0]*60
r=[0]*60
for i in range(n):
	x=format(a[i],'b').zfill(60)
	for j in range(60):
		if x[j]=='0':
			l[j]+=1
		else:
			r[j]+=1

ans=0
for i in range(60):
	ans+=l[i]*r[i]*(2**(59-i))
print(ans%(10**9+7))

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

s=0
for c in range(60):
  m=1<<c
  bc=len([1 for x in A if x&m])
  s+=bc*(N-bc)*m
  s%=10**9+7
  
print(s)

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

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

    b[i]=count
    count=0

for i in range(60):
    ans+=2**i*(b[i]*(n-b[i]))
    ans%=mod


print(ans)

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



N = int(input())
A = list(map(int, input().split()))
for i, a in enumerate(A):
    a = bin(a)[2:]
    l = len(a)
    A[i] = '0' * (60 - l) + a
mod = 10**9 + 7

ans = 0
for i in range(60):
    num_0 = 0
    num_1 = 0
    for a in A:
        if a[-i-1] == '1':
            num_1 += 1
        else:
            num_0 += 1
    ans += (num_0 * num_1) * (2 ** i)
    ans %= mod

print(ans)

Solution (Python):
n=int(input())
A=[int(i) for i in input().split()]
B=[0]*60
C=[0]*60
ans=0
mod=10**9+7
for i,a in enumerate(A):
  for j in range(60):
    if a%2==0:
      C[j]+=B[j]
    else:
      C[j]+=i-B[j]
      B[j]+=1
    a//=2
for i in range(60):
  ans=(ans+C[i]*(2**i))%mod
print(ans)

Solution (Python):
import numpy as np

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

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

print(ans%MOD)

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

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

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

    b[i]=count
    count=0

for i in range(60):
    ans+=2**i*( b[i]*(n-b[i]) )


print(ans%mod)

Solution (Python):
import numpy as np

N = int(input())
A = np.array([int(x) for x in input().split()])
mod = 10**9+7
ans = 0

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

print(ans%mod)

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

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

n = inp()
a = inpl()
a.sort()
ln = len(bin(a[-1])) - 2
bit = [[0,0] for i in range(ln)]
res = 0
for i in a:
    for j in range(ln):
        tmp = 0
        if (i>>j) % 2:
            tmp += 1
        bit[j][tmp] += 1
for i,j in enumerate(bit):
    c = pow(2,i)
    res += j[0] * j[1] * c
    res %= mod
print(res)

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

n = inp()
a = inpl()
a.sort()
ln = len(bin(a[-1])) - 2
bit = [defaultdict(int) for i in range(ln)]
res = 0
for i in a:
    tmp = bin(i)
    for _,j in enumerate(tmp[:1:-1]):
        
        bit[_][j] += 1

for i,j in enumerate(bit):
    x = j['0']
    y = j['1']
    if x+y < n:
        x = n - y
    
    c = pow(2,i)
    res += x * y * c
    res %= mod
print(res)

Solution (Python):
n=int(input())
arr=[int(i) for i in input().split()]
def sumXOR(arr, n):
    MOD=int((1e+9)+7)
    sum = 0
    for i in range(0, 62): 
        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

ans = sumXOR(arr, n); 
print (ans)

Solution (Python):
N = int(input())
from collections import defaultdict
d = defaultdict(int)
for i in map(int,input().split()):
  for idx,j in enumerate(reversed('{:b}'.format(i))):
    if j == "1":
      d[idx]+=1

m = max( set(d.keys())|set([0]))
print(int(sum([((2**i)* (N-d[i])*d[i])%(1e9+7) for i in range(m+1)])%(1e9+7)))

Solution (Python):

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





for i in range(61):
    yes=sum([1 for a in A if (a>>i)&1])
    no=N-yes
    ans+=(1<<i)*yes*no

ans%=mod
print(ans)

Solution (Python):
n=int(input())
a=[int(x) for x in input().split()]
ans=0
mod=10**9+7
for i in range(64):
    num_1=0
    num_0=0
    for ai in a:
        if (ai >> i) & 1:
            num_1+=1
        else:
            num_0+=1
    ans+=num_0*num_1*(1 << i)
print(ans%mod)

Solution (Python):



import numpy as np


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

mod = 10 ** 9 + 7
s = 0

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

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
















import numpy as np

A = np.array(A)
sum_ = 0
for i in range(len(bin(np.max(A))) - 2):
    count = np.count_nonzero(A & 1)
    sum_ += 2**i * count * (N - count)
    A >>= 1
print(sum_ % (10**9 + 7))

Solution (Python):
import math
import collections
import itertools
import sys
import bisect
from heapq import heappop,heappush,heapify
sys.setrecursionlimit(10**6)
def MAP(): return list(map(int,input().split()))
def INT(): return int(input())
def FLOAT(): return float(input())
MOD = 10**9+7

n = INT()
a = MAP()

m = 1
ans=0
for _ in range(60):
    bit = sum(i & m for i in a)
    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()))
mod=10**9+7
import numpy as np
a=np.array(a)
md = len(bin(max(a)))
ans = 0
for d in range(md):
    cnt1 = np.count_nonzero((a>>d)&1)
    ans += cnt1 * (n-cnt1) * (1<<d)
    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(60):
  cnt=sum([1 for a in A if a>>i&1]) 
  cnt=cnt*(n-cnt)%mod
  cnt=2**i*cnt%mod
  ans+=cnt
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):
    zeroCnt = 0
    oneCnt = 0

    for j in range(n):
        if (a[j] >> i) & 1 == 1:
            oneCnt += 1
        else:
            zeroCnt += 1
    ans += zeroCnt * oneCnt * pow(2, i, mod)
    ans %= mod

print(ans)

Solution (Python):
import numpy as np


def solve():
    MOD = 10**9+7
    N = int(input())
    a = np.array(input().split(), int)

    ans = 0
    for i in range(60):
        ones = np.count_nonzero((a >> i) & 1)
        zeros = N - ones
        ans += zeros * ones * 2 ** i
        ans %= MOD
    print(ans)


if __name__ == '__main__':
    solve()

Solution (Python):



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


result = 0
for bit in range(60):
    m = 1 << bit
    c = sum(a & m for a in alist) >> bit
    result += (c * (n - c)) << bit
    result %= 10**9+7


print(result)

Solution (Python):
n=int(input())
a=list(map(int,input().split()))
ans=0
mod=10**9+7
for j in range(60):
    cnt1=sum([1 for i in a if i>>j&1])
    cnt0=n-cnt1
    ans+=(cnt1*cnt0*2**j)
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(60):
    a = 0
    b = 0
    for j in range(N):
        if A[j] % 2:
            a += 1
        else:
            b += 1
        A[j] //= 2
    ans += a*b*pow(2, i, mod)
    ans %= mod
print(ans)

Solution (Python):
MOD = int(1e9+7)


def div(a, b):
    return a * pow(b, MOD-2, MOD) % MOD


def main():
    N = int(input())
    A = list(map(int, input().split()))
    M = 60
    bitcnt = [0] * M
    for a in A:
        for i in range(M):
            if a & (1 << i):
                bitcnt[i] += 1
    ans = 0
    for a in A:
        for i in range(M):
            x = 1 << i
            if a & x:
                ans = (ans + x * (N - bitcnt[i])) % MOD
            else:
                ans = (ans + x * bitcnt[i]) % MOD
    ans = div(ans, 2)
    print(ans)


if __name__ == "__main__":
    main()

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


if __name__=='__main__':
    main()

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

Solution (Python):



import numpy as np

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


for i  in range(60):
    c1=np.count_nonzero(arr&1)
    c0=N-c1
    ans+=2**i*c1*c0
    arr>>=1
print(ans%mod)

Solution (Python):
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
import math
import bisect
import random
from itertools import permutations, accumulate, combinations, product
import sys
import string
from bisect import bisect_left, bisect_right
from math import factorial, ceil, floor
from operator import mul
from functools import reduce


sys.setrecursionlimit(2147483647)
INF = 10 ** 13
def LI(): return list(map(int, sys.stdin.buffer.readline().split()))
def I(): return int(sys.stdin.buffer.readline())
def LS(): return sys.stdin.buffer.readline().rstrip().decode('utf-8').split()
def S(): return sys.stdin.buffer.readline().rstrip().decode('utf-8')
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)]
def SRL(n): return [list(S()) for i in range(n)]
def MSRL(n): return [[int(j) for j in list(S())] for i in range(n)]
mod = 1000000007


n = I()
A = LI()
ans = 0
for i in range(61):
    one_cnt = [a >> i & 1 for a in A].count(1)
    zero_cnt = n - one_cnt
    ans = (ans + pow(2, i, mod) * one_cnt * zero_cnt) % mod


print(ans)

Solution (Python):

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

ans = 0
mod = 10**9 + 7
for i in range(61):
    
    bit = 1 << i
    count = 0
    for a in A:
        if bit & a > 0:
            count += 1
    ans += 2**i * (count) * (N-count) % mod
print(ans % mod)

Solution (Python):
N = int(input())
A= list(map(int, input().split()))
mod = 10 ** 9 + 7
sum = 0
for i in range(60):
    count0 = 0
    count1 = 0
    count2 = 0

    for j in range(N):
        if A[j] & 1:
            count1 += 1
        else:
            count0 += 1
        A[j] = A[j] >> 1
    count2 = count0 * count1
    sum += count2 * (2 ** i)

print(sum % mod)

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

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

ans = 0
for i in range(60):
    k = 1 << i
    i_1 = sum([k & a for a in ass]) >> i
    ans += i_1 * (n - i_1) << i
    ans = ans % ((10**9) + 7)

print(ans)

Solution (Python):
import numpy as np
 
MOD = 10 ** 9 + 7
 
N = int(input())
A = np.array(list(map(int, input().split())),np.int64)
 
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 *= 2
        x %= MOD
    answer += x
answer %= MOD
print(answer)

Solution (Python):
N = int(input())
A = list(map(int, input().split()))
 
result = 0
for i in range(60):
    on = sum([(1 << i) & a for a in A]) >> i
    result += (on * (N - on)) << i
    result %= ((10**9) + 7)
 
print(result)

Solution (Python):
N = int(input())
A = list(map(int, input().split()))
 
each_bit_sum = [{"0": 0, "1": 0} for _ in range(62)]
result = 0
for a in A:
    for i, b in enumerate(format(a, "b").zfill(62)[::-1]):
        each_bit_sum[i][b] += 1
 
for i, b in enumerate(each_bit_sum):
    result += ((b["0"] * b["1"]) * (2**i)) % ((10**9) + 7)
 
print(result % ((10**9) + 7))

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

ans = 0
MOD = 10**9+7
for i in range(60):
    b = 1 << i
    cnt_1 = sum([a & b for a in A]) >> i
    cnt_0 = N - cnt_1
    b_sum = cnt_1 * cnt_0
    ans += (b_sum << i) % MOD
print(ans%MOD)

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

ans = 0
MOD = 10**9+7
for i in range(60):
    b = 1 << i
    cnt_1 = sum([a & b for a in A]) >> i
    cnt_0 = N - cnt_1
    b_sum = cnt_1 * cnt_0
    ans += (b_sum << i) % MOD
print(ans%MOD)

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

ans = 0
MOD = 10**9+7
for i in range(60):
    b = 1 << i
    cnt_1 = sum([a & b > 0 for a in A])
    cnt_0 = N - cnt_1
    b_sum = cnt_1 * cnt_0
    ans += (b_sum << i) % MOD
print(ans%MOD)

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

result = 0
for i in range(60):
    target = 1 << i
    on = sum([target & a for a in A]) >> i
    result += (on * (N - on)) << i
    result %= ((10**9) + 7)

print(result)