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-----
3
1 2 3

-----Sample Output-----
6

We have (1\mbox{ XOR } 2)+(1\mbox{ XOR } 3)+(2\mbox{ XOR } 3)=3+2+1=6.

Difficulty: MEDIUM

Solutions:
(n, *a) = map(int, open(0).read().split())
c = 0
for i in range(61):
	i = 2 ** i
	t = sum((i & b and 1 for b in a))
	c = (c + t * (n - t) * i) % (10 ** 9 + 7)
print(c)


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


MOD = 10 ** 9 + 7
n = int(input())
a = list(map(int, input().split()))
s = 0
m = 1
for i in range(60):
	c = sum((ai & m for ai in a))
	c //= m
	s = (s + m * c * (n - c)) % MOD
	m <<= 1
print(s)


n = int(input())
a = list(map(int, input().split()))
p = 10 ** 9 + 7
ans = 0
for i in range(60):
	x = 1 << i
	one = sum((1 for j in a if j & x))
	ans += pow(2, i, p) * one * (n - one)
print(ans % p)


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)


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


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)


N = int(input())
A = list(map(int, input().split()))
mod = 10 ** 9 + 7
ans = 0
for i in range(60):
	X = 1 << i
	n = len([1 for a in A if a & X])
	ans += X * n * (N - n) % mod
	ans %= mod
print(ans)


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


def main():
	n = int(input())
	a = list(map(int, input().split()))
	MOD = 10 ** 9 + 7
	digit = 60
	ans = 0
	for j in range(digit):
		o = 0
		for i in a:
			if i >> j & 1:
				o += 1
		ans += o * (n - o) * 2 ** j
		ans %= MOD
	print(ans)

def __starting_point():
	main()
__starting_point()


N = int(input())
A = list(map(int, input().split()))
ans = 0
for i in range(60):
	p = 1 << i
	num_one = len([1 for x in A if x & p])
	ans = ans + p * num_one * (N - num_one)
print(ans % 1000000007)


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))


N = int(input())
A = list(map(int, input().split()))
m = 1000000007
result = 0
for i in range(60):
	j = 1 << i
	c = sum((a & j for a in A)) >> i
	result += c * (N - c) << i
	result %= m
print(result)


N = int(input())
A = [int(i) for i in input().split()]
mod = 10 ** 9 + 7
ans = 0
for b in range(60):
	c = 0
	for a in A:
		if a >> b & 1:
			c += 1
	ans += 2 ** b * c * (N - c)
	ans %= mod
print(ans)


n = int(input())
a = [int(s) for s in input().split()]
d = 0
ans = 0
mod = 10 ** 9 + 7
for d in range(60):
	c0 = 0
	c1 = 0
	for v in a:
		if v >> d & 1:
			c1 += 1
		else:
			c0 += 1
	ans = (ans + (c0 * c1 << d)) % mod
print(ans)


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)


N = int(input())
A = list(map(int, input().split()))
MOD = 10 ** 9 + 7
sum_num = 0
for i in range(60):
	o = 0
	for a in A:
		o += (a >> i) % 2
	z = N - o
	sum_num = (sum_num + o * z * (1 << i)) % MOD
print(sum_num)


N = int(input())
A = [int(n) for n in input().split(' ')]
ans = 0
for i in range(60):
	x = 0
	for A_i in A:
		if A_i >> i & 1:
			x += 1
	ans += x * (N - x) * 2 ** i
ans = ans % (10 ** 9 + 7)
print(ans)


mod = 10 ** 9 + 7
N = int(input())
str_a = ''.join(['{:060b}'.format(a) for a in map(int, input().split())])
ans = 0
for i in range(60):
	ones = str_a[59 - i::60].count('1')
	ans += pow(2, i, mod) * ones * (N - ones)
print(ans % mod)


import math
import numpy as np
N = int(input())
ARR = list(map(int, input().split()))

def calculate(n, arr):
	maxValue = max(arr)
	if maxValue == 0:
		maxNum = 1
	else:
		maxNum = math.ceil(math.log(maxValue, 2))
	arr = np.array(arr)
	oneArray = [0] * (maxNum + 1)
	zeroArray = [0] * (maxNum + 1)
	for i in range(maxNum + 1):
		s = arr >> i & 1
		a = np.count_nonzero(s)
		oneArray[i] = a
		zeroArray[i] = n - a
	finalResult = 0
	for i in range(maxNum + 1):
		finalResult += 2 ** i * oneArray[i] * zeroArray[i]
	print(finalResult % (10 ** 9 + 7))
calculate(N, ARR)


n = int(input())
a = list(map(int, input().split()))
mod = 1000000007
res = 0
for i in range(62):
	cnt = 0
	for x in a:
		if x & 1 << i > 0:
			cnt += 1
	res = (res + cnt * (n - cnt) * (1 << i)) % mod
print(res)


(N, *A) = map(int, open(0).read().split())
mod = 10 ** 9 + 7
ans = 0
for i in range(60):
	mask = 1 << i
	cnt = 0
	for a in A:
		if a & mask:
			cnt += 1
	x = cnt * (N - cnt)
	x *= mask % mod
	ans += x
	ans %= mod
print(ans)


N = int(input())
aaa = list(map(int, input().split()))
bbb = [format(a, '061b') for a in aaa]
zero = [0] * 61
one = [0] * 61
for i in range(61):
	s = ''.join(list((b[-(i + 1)] for b in bbb)))
	zero[i] = s.count('0')
	one[i] = s.count('1')
ans = 0
MOD = 1000000007
for (i, o, l) in zip(list(range(61)), zero, one):
	ans += 2 ** i * o * l
	ans %= MOD
print(ans)


MOD = 10 ** 9 + 7

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


import numpy as np
mod = 10 ** 9 + 7
n = int(input())
A = np.array(list(map(int, input().split())))
ans = 0
for i in range(60):
	n1 = np.count_nonzero(A >> i & 1)
	n0 = n - n1
	ans += 2 ** i * n1 * n0 % mod
ans %= mod
print(ans)


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

def __starting_point():
	main()
__starting_point()


n = int(input())
A = list(map(int, input().split()))
mod = int(1000000000.0 + 7)
ans = 0
for i in range(61):
	t = 0
	for a in A:
		if a >> i & 1:
			t += 1
	ans = (ans + pow(2, i, mod) * t * (n - t)) % mod
print(ans)


N = int(input())
A = [int(c) for c in input().split()]
D = [0 for i in range(60)]
for a in A:
	for i in range(60):
		D[i] += a % 2
		a //= 2
t = 1
ans = 0
for i in range(60):
	ans += D[i] * (N - D[i]) * t
	t *= 2
print(ans % 1000000007)


def XorSum4():
	n = int(input())
	a = list(map(int, input().split()))
	mod = 10 ** 9 + 7
	ans = 0
	for i in range(60):
		count = 0
		for j in a:
			count += j >> i & 1
		num = count * (n - count) % mod
		ans += num * 2 ** i
		ans %= mod
	print(ans)

def __starting_point():
	XorSum4()
__starting_point()


M = 10 ** 9 + 7
N = int(input())
A = list(map(int, input().split()))
ans = 0
for k in range(61):
	N1 = 0
	N1 = sum([1 for a in A if a >> k & 1])
	ans += (1 << k) * (N - N1) * N1
	ans %= M
print(ans)


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.141592653589793

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)
Main()


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


import math
from math import gcd, pi, sqrt
INF = float('inf')
MOD = 10 ** 9 + 7
import sys
sys.setrecursionlimit(10 ** 6)
import itertools
import bisect
from collections import Counter, deque

def i_input():
	return int(input())

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

def i_list():
	return list(i_map())

def i_row(N):
	return [i_input() for _ in range(N)]

def i_row_list(N):
	return [i_list() for _ in range(N)]

def s_input():
	return input()

def s_map():
	return input().split()

def s_list():
	return list(s_map())

def s_row(N):
	return [s_input for _ in range(N)]

def s_row_str(N):
	return [s_list() for _ in range(N)]

def s_row_list(N):
	return [list(s_input()) for _ in range(N)]

def main():
	n = i_input()
	a = i_list()
	ans = 0
	for i in range(60):
		cnt = 0
		bit = 1 << i
		for j in a:
			if j & bit:
				cnt += 1
		num1 = cnt
		num0 = n - num1
		ans += num1 * num0 * bit % MOD
	print(ans % MOD)

def __starting_point():
	main()
__starting_point()


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


n = int(input())
A = list(map(int, input().split()))
a = 0
c = 0
m = max(A)
while m:
	o = sum(map(lambda x: x & 1, A))
	a += (n - o) * o * 2 ** c
	A = list(map(lambda x: x >> 1, A))
	c += 1
	a %= 10 ** 9 + 7
	m //= 2
print(a)


n = int(input())
a = [int(i) for i in input().split()]
ans = 0
for i in range(64):
	(x, y) = (0, 0)
	for j in a:
		if j >> i & 1:
			y += 1
		else:
			x += 1
	ans += x * y * (1 << i)
	ans %= 10 ** 9 + 7
print(ans)


import numpy as np
mod = 10 ** 9 + 7
N = int(input())
A = np.array(list(map(int, input().split())))
tmp = 0
for n in range(len(bin(max(A))) - 2):
	num_1 = np.count_nonzero(A >> n & 1)
	num_0 = N - num_1
	mul = num_1 * num_0
	tmp += 2 ** n * mul % mod
ans = tmp % mod
print(ans)


N = int(input())
M = 10 ** 9 + 7
A = list(map(int, input().split()))
ans = 0
for i in range(60):
	one = sum([a >> i & 1 for a in A])
	zero = N - one
	ans += one * zero * 2 ** i
	ans %= M
print(ans)


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)


M = 10 ** 9 + 7
(n, *l) = map(int, open(0).read().split())
a = 0
for i in range(60):
	t = sum((j >> i & 1 for j in l))
	a += t * (n - t) * pow(2, i, M)
print(a % M)


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


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


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)


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
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(len(bin(max(A)))):
	num_1 = np.count_nonzero(A >> n & 1)
	num_0 = N - num_1
	mul = num_1 * num_0
	ans += 2 ** n * mul % mod
ans %= mod
print(ans)


M = 10 ** 9 + 7
n = int(input())
l = list(map(int, input().split()))
a = 0
for i in range(60):
	t = sum((j >> i & 1 for j in l))
	a += (t * (n - t) << i) % M
print(a % M)


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


mod = 10 ** 9 + 7
N = int(input())
A = list(map(int, input().split()))
ans = 0
i = 0
while i < 60:
	mask = 2 ** i
	n = sum([1 if a & mask > 0 else 0 for a in A])
	ans += n * (N - n) * pow(2, i, mod)
	ans %= mod
	i += 1
print(ans)


n = int(input())
a = list(map(int, input().split()))
mod = 10 ** 9 + 7
ans = 0
d = 1
for i in range(61):
	s = 0
	for j in a:
		s += j >> i & 1
	ans += s * (n - s) * d % mod
	ans %= mod
	d *= 2
	d %= mod
print(ans)


n = int(input())
a = list(map(int, input().split()))
mod = 10 ** 9 + 7
c = [0] * 60
for aa in a:
	for i in range(60):
		if aa & 1 << i:
			c[i] += 1
ans = 0
for (i, cc) in enumerate(c):
	ans += cc * (n - cc) * 2 ** i
	ans %= mod
print(ans)


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


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)


(N, *A) = map(int, open(0).read().split())
mod = 10 ** 9 + 7
batch = 8
rg = tuple(range(63 // batch + 1))
mask = (1 << batch) - 1
B = [[0] * (1 << batch) for _ in rg]
for a in A:
	for i in rg:
		B[i][a & mask] += 1
		a >>= batch
xr = [[] for _ in [0] * (1 << batch)]
for i in range(1 << batch):
	for j in range(i + 1, 1 << batch):
		xr[i].append(i ^ j)
ans = 0
shift = 1
for b in B:
	x = sum((xr[i][j] * bi * bj for (i, bi) in enumerate(b) for (j, bj) in enumerate(b[i + 1:])))
	x %= mod
	x *= shift
	x %= mod
	shift <<= batch
	shift %= mod
	ans += x
	ans %= mod
print(ans)


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


import sys
input = sys.stdin.readline
import numpy as np
n = int(input())
a = np.array([int(i) for i in input().split()])
ans = 0
for i in range(60):
	cnt = np.count_nonzero(a & 1)
	ans += (n - cnt) * cnt * 2 ** i
	if ans >= 10 ** 9 + 7:
		ans %= 10 ** 9 + 7
	a >>= 1
print(ans)


N = int(input())
a = list(input().split())
A = [int(a[i]) for i in range(N)]
frag = [0 for i in range(60)]
mod = 10 ** 9 + 7
ans = 0
for i in range(60):
	j = 1 << i
	cnt = sum(((k & j) >> i for k in A))
	ans += cnt * (N - cnt) << i
	ans %= mod
print(ans)


N = int(input())
A = list(map(int, input().split()))
MOD = 10 ** 9 + 7
ans = 0
for i in range(60):
	n = sum([a >> i & 1 for a in A])
	ans = (ans + n * (N - n) * 2 ** i) % MOD
print(ans)


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)


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)


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


MOD = int(1000000000.0) + 7
n = int(input())
a = list(map(int, input().split()))
ans = 0
for b in range(60)[::-1]:
	ans <<= 1
	c = sum((a[i] >> b & 1 for i in range(n)))
	ans = (ans + c * (n - c)) % MOD
print(ans)


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)


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)


import sys
sys.setrecursionlimit(10 ** 7)
f_inf = float('inf')
mod = 10 ** 9 + 7

def resolve():
	n = int(input())
	A = list(map(int, input().split()))
	res = 0
	for mask in range(60):
		cnt1 = sum([1 if a & 1 << mask else 0 for a in A])
		cnt0 = n - cnt1
		res += pow(2, mask, mod) * cnt1 * cnt0 % mod
		res %= mod
	print(res)

def __starting_point():
	resolve()
__starting_point()


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


N = int(input())
A = [format(i, '060b') for i in map(int, input().split())]
ans = 0
mod = 10 ** 9 + 7
for k in range(60):
	count = [a[60 - 1 - k] for a in A].count('0')
	ans += count * (N - count) * 2 ** k % mod
print(ans % mod)


import numpy as np

def solve():
	ans = 0
	mask = 1
	for i in range(60):
		one_cnt = np.sum(A >> i & 1)
		tmp = one_cnt * (N - one_cnt)
		tmp %= MOD
		ans += tmp * mask
		ans %= MOD
		mask <<= 1
		mask %= MOD
	return ans
(N, *A) = list(map(int, open(0).read().split()))
A = np.array(A, dtype=np.int64)
MOD = 1000000007
print(solve())


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


N = int(input())
A = list(map(int, input().split()))
l = [0] * 60
for i in A:
	for j in range(60):
		if i & 1 << j:
			l[j] += 1
ans = 0
for i in range(60):
	ans += l[i] * (N - l[i]) * (1 << i)
	ans %= 10 ** 9 + 7
print(ans)


import numpy as np

def main():
	n = int(input())
	a = list(map(int, input().split()))
	a = np.array(a, dtype='int64')
	mod = 10 ** 9 + 7
	(div, ans) = (1, 0)
	for i in range(60):
		ca = a >> i & 1
		cnt = int(ca.sum())
		ans += cnt * (n - cnt) * div % mod
		div = div * 2 % mod
	print(ans % mod)

def __starting_point():
	main()
__starting_point()


def main():
	N = int(input())
	A = list(map(int, input().split()))
	mod = 10 ** 9 + 7
	ans = 0
	for i in range(60):
		a = 0
		for x in A:
			if x >> i & 1:
				a += 1
		ans += a * (N - a) * pow(2, i, mod)
		ans %= mod
	print(ans)

def __starting_point():
	main()
__starting_point()


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)

def __starting_point():
	main()
__starting_point()


MOD = 10 ** 9 + 7
N = int(input())
A = list(map(int, input().split()))
s = 0
n = len(bin(max(A))[2:])
for i in range(n):
	b = 1 << i
	N_t = sum([1 for Ai in A if b & Ai > 0])
	N_f = N - N_t
	s += (1 << i) * N_t * N_f
print(s % MOD)


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


mod = int(1000000000.0 + 7)
N = int(input())
A = [format(i, '060b') for i in map(int, input().split())]
S = 0
for k in range(60):
	s = [b[59 - k] for b in A]
	v = s.count('0') * s.count('1')
	S += v << k
S %= mod
print(S)


import numpy as np
n = int(input())
a = np.array(list(map(int, input().split())))
mod = 10 ** 9 + 7
s = 0
for i in range(60):
	bit = np.count_nonzero(a & 1)
	s += bit * (n - bit) * 2 ** i
	a >>= 1
print(s % mod)


n = int(input())
a = list(map(int, input().split()))
mod = 10 ** 9 + 7
cnt = [0] * 60
for elem in a:
	for i in range(60):
		cnt[i] += (elem >> i) % 2
ans = 0
for i in range(60):
	ans += (cnt[i] * (n - cnt[i]) << i) % mod
print(ans % mod)


MOD = 1000000007
n = int(input())
a = list(map(int, input().split()))
ans = 0
for k in range(60):
	mask = 1 << k
	cnt1 = sum((1 for x in a if x & mask != 0))
	ans += cnt1 * (n - cnt1) * (1 << k)
print(ans % MOD)


N = int(input())
A = list(map(int, input().split()))
ans = 0
for i in range(60):
	x = 1 << i
	o = sum((1 for j in A if j & x))
	ans += x * o * (N - o)
	ans %= 10 ** 9 + 7
print(ans)


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


mod = int(1000000000.0) + 7
n = int(input())
a = [int(i) for i in input().split()]
ans = 0
for b in range(60)[::-1]:
	ans <<= 1
	c = sum((a[i] >> b & 1 for i in range(n)))
	ans = (ans + c * (n - c)) % mod
print(ans)


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


N = int(input())
A = list(map(int, input().split()))
MOD = 10 ** 9 + 7
ans = 0
for d in range(62):
	mask = 1 << d
	zero = len([0 for a in A if a & mask == 0])
	ans += zero * (N - zero) * mask % MOD
print(ans % MOD)


N = int(input())
A = ''.join(list(map(lambda x: format(int(x), '060b'), input().split(' '))))
mod = 10 ** 9 + 7
ans = 0
for n in range(60):
	one = A[59 - n::60].count('1')
	ans = (ans + 2 ** n * one * (N - one)) % mod
print(ans)


n = int(input())
a = list(map(int, input().split()))
mod = 10 ** 9 + 7
ans = 0
p = 1
for i in range(60):
	s = sum((1 for b in a if b & p))
	ans += s * (n - s) * p
	ans %= mod
	p <<= 1
print(ans)


n = int(input())
a = list(map(int, input().split()))
mod = 10 ** 9 + 7
ans = 0
for bit in range(61):
	now = 0
	for x in a:
		if x & 1 << bit:
			now += 1
	ans += 2 ** bit * (now * (n - now))
	ans %= mod
print(ans)


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


n = int(input())
a = list(map(int, input().split()))
mod = 10 ** 9 + 7
ans = 0
for i in range(60):
	on = 0
	off = 0
	for j in a:
		if j >> i & 1:
			on += 1
		else:
			off += 1
	ans += on * off * 2 ** i
	ans %= mod
print(ans)


n = int(input())
a = list(map(int, input().split()))
MOD = 10 ** 9 + 7
ans = 0
for i in range(60):
	x = [bool(ai & 1 << i) for ai in a]
	sx = sum(x)
	count = sx * (n - sx)
	ans += count << i
	ans %= MOD
print(ans)


(n, *a) = map(int, open(0).read().split())
ans = 0
mod = 10 ** 9 + 7
for k in range(61):
	m = 1 << k
	c = 0
	for x in a:
		if m & x:
			c += 1
	ans += c * (n - c) * m
	ans %= mod
print(ans)


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)


n = int(input())
l = [int(c) for c in input().split()]
ans = 0
mod = 10 ** 9 + 7
for i in range(60):
	s = sum((a >> i & 1 for a in l))
	ans += s * (n - s) << i % mod
	ans %= mod
print(ans)


import sys
from itertools import chain, count
MOD = 1000000007

def solve(N: int, A: 'List[int]'):
	a_max = max(A)
	ans = 0
	for i in count(0):
		mask = 2 ** i
		if mask > a_max:
			return ans
		c0 = 0
		c1 = 0
		for a in A:
			if a & mask:
				c1 += 1
			else:
				c0 += 1
		mask = mask % MOD
		ans = (ans + mask * (c0 * c1)) % MOD

def main():
	tokens = chain(*(line.split() for line in sys.stdin))
	N = int(next(tokens))
	A = [int(next(tokens)) for _ in range(N)]
	answer = solve(N, A)
	print(answer)

def __starting_point():
	main()
__starting_point()


n = int(input())
xs = [int(x) for x in input().split()]
M = 10 ** 9 + 7
r = 0
for i in range(61):
	k = 0
	for x in xs:
		k += (x >> i) % 2
	r = (r + (n - k) * k % M * pow(2, i)) % M
print(r)


n = int(input())
a = list(map(int, input().split()))
mod = 10 ** 9 + 7
ans = 0
for i in range(60):
	mask = 1 << i
	count = sum((1 for j in a if mask & j == 0))
	ans += count * (n - count) * pow(2, i, mod)
print(ans % mod)


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


N = int(input())
A = list(map(int, input().split()))
M = 10 ** 9 + 7
ans = 0
for i in range(61):
	ones = sum([1 for a in A if a >> i & 1])
	ans += (1 << i) * ones * (N - ones)
	ans %= M
print(ans)


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))


import numpy as np

def main():
	MOD = 10 ** 9 + 7
	limit = 60
	N = int(input())
	A = np.array(input().split(), dtype=np.int64)
	ans = 0
	for n in range(limit):
		res = A & 1 << n
		x = np.count_nonzero(res)
		y = N - x
		x *= y
		for _ in range(n):
			x *= 2
			x %= MOD
		ans += x
	print(ans % MOD)

def __starting_point():
	main()
__starting_point()


(N, *A) = map(int, open(0).read().split())
mod = 10 ** 9 + 7
ans = 0
for bit in range(60):
	ctr = [0, 0]
	for i in range(N):
		ctr[A[i] >> bit & 1] += 1
	ans += (1 << bit) * (ctr[0] * ctr[1])
	ans %= mod
print(ans)


MOD = 10 ** 9 + 7
n = int(input())
values = list(map(int, input().split()))
pops = [sum([value >> i & 1 for value in values]) for i in range(60)]
print(sum([(1 << i) * pops[i] * (n - pops[i]) for i in range(60)]) % MOD)


import numpy as np
N = int(input())
A = np.array(list(map(int, input().split())))
ans = 0
mod = 10 ** 9 + 7
for i in range(60):
	cnt = np.count_nonzero(A & 1)
	ans += (N - cnt) * cnt * 2 ** i
	ans %= mod
	A >>= 1
print(ans)


import sys
sys.setrecursionlimit(10 ** 7)
f_inf = float('inf')
mod = 10 ** 9 + 7

def resolve():
	n = int(input())
	A = list(map(int, input().split()))
	res = 0
	for i in range(60):
		cnt_one = 0
		for a in A:
			if a >> i & 1:
				cnt_one += 1
		res += (n - cnt_one) * cnt_one * pow(2, i)
		res %= mod
	print(res)

def __starting_point():
	resolve()
__starting_point()


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


N = int(input())
bin_a = ''.join(['{:060b}'.format(a) for a in map(int, input().split())])
mod = 10 ** 9 + 7
xor = 0
for d in range(60):
	ones = bin_a[59 - d::60].count('1')
	xor += 2 ** d * ones * (N - ones)
print(xor % mod)


import bisect, collections, copy, heapq, itertools, math, string, sys
input = lambda : sys.stdin.readline().rstrip()
sys.setrecursionlimit(10 ** 7)
INF = float('inf')
MOD = 10 ** 9 + 7

def I():
	return int(input())

def F():
	return float(input())

def SS():
	return input()

def LI():
	return [int(x) for x in input().split()]

def LI_():
	return [int(x) - 1 for x in input().split()]

def LF():
	return [float(x) for x in input().split()]

def LSS():
	return input().split()

def resolve():
	N = I()
	A = LI()
	cnt = [0] * 60
	for i in A:
		for j in range(60):
			if i >> j & 1:
				cnt[j] += 1
	ans = 0
	for i in range(60):
		ans += cnt[i] * (N - cnt[i]) * pow(2, i, MOD)
		ans %= MOD
	print(ans)

def __starting_point():
	resolve()
__starting_point()


n = int(input())
arr = list(map(int, input().split()))
mod = 10 ** 9 + 7
res = 0
for d in range(60):
	one = sum((x & 1 for x in arr))
	res = (res + one * (n - one) * (1 << d)) % mod
	arr = [x >> 1 for x in arr]
print(res)


N = int(input())
A = [int(i) for i in input().split()]
maxdig = 60
mod = 10 ** 9 + 7
ans = 0
for i in range(60 + 1):
	cnt1 = sum([1 for a in A if a >> i & 1])
	ans += cnt1 * (N - cnt1) * (1 << i)
	ans = ans % mod
print(ans)


def resolve():
	MOD = 10 ** 9 + 7
	N = int(input())
	A = list(map(int, input().split()))
	ans = 0
	for i in range(60):
		p = 1 << i
		one = sum([1 for a in A if a & p])
		zero = N - one
		ans += p * one * zero
		ans %= MOD
	print(ans)

def __starting_point():
	resolve()
__starting_point()


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)


import numpy as np
N = int(input())
A = np.fromiter(list(map(int, input().split())), np.int64)
m = 1000000007
result = 0
for bit in range(60):
	c = int((A & 1).sum())
	A >>= 1
	result = (result + c * (N - c) * (1 << bit)) % m
print(result)


n = int(input())
a = list(map(int, input().split()))
cnt = [0] * 66
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 %= 10 ** 9 + 7
print(ans)


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)


n = int(input())
a = list(map(int, input().split()))
mod = 1000000007
ml = len(bin(max(a))) - 2
ans = 0
for i in range(ml):
	x = sum([1 for j in a if j >> i & 1])
	ans += x * (n - x) * 2 ** i
	ans %= mod
print(ans)


n = int(input())
ns = list(map(int, input().split()))
d = [0] * 60
ans = 0
mod = 10 ** 9 + 7
for i in range(60):
	for num in ns:
		d[i] += num >> i & 1
	ans = (ans + d[i] * (n - d[i]) * 2 ** i) % mod
print(ans)


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)


import numpy as np
n = int(input())
a = np.array(list(map(int, input().split())))
mod = 10 ** 9 + 7
ans = 0
two = 1
for i in range(61):
	one = np.count_nonzero(a & 1)
	a = a >> 1
	ans = (ans + one * (n - one) * two) % mod
	two = two * 2 % mod
print(ans)


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


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)


n = int(input())
a = [int(i) for i in input().split()]
a_bin = []
for i in a:
	a_bin.append(format(i, '#062b')[2:])

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)


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))