AtCoder Beginner Contest 147 - Xor Sum 4

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.

Source: atcoder | Difficulty: MEDIUM


Solutions:
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):
	s = np.count_nonzero(a >> i & 1)
	ans += pow(2, i, mod) * s * (N - s) % 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):
	keta = 1 << i
	cnt = 0
	for j in a:
		if keta & j:
			cnt += 1
	ans += keta * cnt * (n - cnt) % mod
print(ans % mod)


import numpy as np
N = int(input())
A = np.array([int(x) for x in input().split()])
ans = 0
M = pow(10, 9) + 7
for i in range(100):
	one = int(np.sum(A >> i & 1))
	zero = N - one
	ans += one * zero * pow(2, i, M)
	ans %= M
print(ans)


import sys
read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007

def main():
	(N, *A) = list(map(int, read().split()))
	ans = 0
	for i in range(60):
		one = 0
		for a in A:
			if a & 1 << i:
				one += 1
		ans = (ans + one * (N - one) * (1 << i)) % MOD
	print(ans)
	return

def __starting_point():
	main()
__starting_point()


def main():
	n = int(input())
	A = [int(x) for x in input().split()]
	ans = 0
	mod = 10 ** 9 + 7
	for d in range(60):
		x = 0
		for a in A:
			if a >> d & 1:
				x += 1
		ans += x * (n - x) * 2 ** d
		ans %= mod
	print(ans)

def __starting_point():
	main()
__starting_point()


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


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


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


(N, *A) = map(int, open(0).read().split())
print(sum(((b := (1 << i)) * (N - (z := sum((1 for a in A if a & b)))) * z % (m := (10 ** 9 + 7)) for i in range(60))) % m)


import sys
import numpy as np

def input():
	return sys.stdin.readline().rstrip()

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

def __starting_point():
	main()
__starting_point()


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)


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)


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

def __starting_point():
	main()
__starting_point()


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

def __starting_point():
	main()
__starting_point()


n = int(input())
a = list(map(int, input().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)


(n, *A) = map(int, open(0).read().split())
mod = 10 ** 9 + 7
ans = 0
d = 1
while any(A):
	c = 0
	for i in range(n):
		(q, r) = divmod(A[i], 2)
		A[i] = q
		c += r
	ans += c * (n - c) * d
	ans %= mod
	d *= 2
print(ans % mod)


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


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)


import sys
stdin = sys.stdin
mod = 10 ** 9 + 7

def ns():
	return stdin.readline().rstrip()

def ni():
	return int(ns())

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

def main():
	n = ni()
	a = na()
	ans = 0
	for i in range(61):
		cnt = 0
		for ai in a:
			if ai >> i & 1:
				cnt += 1
		ans += cnt * (n - cnt) * 2 ** i % mod
	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
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)


MOD = 10 ** 9 + 7
n = int(input())
A = ['{:060b}'.format(a)[::-1] for a in map(int, input().split())]
c = [a.count('1') for a in zip(*A)]
print(sum((c[d] * (n - c[d]) * pow(2, d, MOD) % MOD for d in range(60))) % 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()))
mod = 10 ** 9 + 7
ans = 0
for i in range(60):
	o = 0
	x = 1 << i
	for j in a:
		if j & x:
			o += 1
	ans += x * o * (n - o)
	ans %= mod
print(ans)


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


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


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


n = int(input())
A = list(map(int, input().split()))
ans = 0
for bit in range(60):
	m = 1 << bit
	c = sum((a & m for a in A)) >> bit
	ans += c * (n - c) << bit
	ans %= 10 ** 9 + 7
print(ans)


n = int(input())
a = list(map(int, input().split()))
b = [0] * 64
for i in range(n):
	for j in range(a[i].bit_length()):
		if a[i] >> j & 1:
			b[j] += 1
c = 0
for i in range(64):
	c += b[i] * (n - b[i]) * 2 ** i % 1000000007
print(c % 1000000007)


n = int(input())
a = list(map(int, input().split()))
mod = 10 ** 9 + 7
ans = 0
for k in range(60):
	t = 1 << k
	z = o = 0
	for i in a:
		if i & t:
			o += 1
		else:
			z += 1
	ans = (ans + z * o * t) % 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()


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

def __starting_point():
	main()
__starting_point()


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)


n = int(input())
a = [int(i) for i in input().split()]
MOD = int(1000000000.0 + 7)
ans = 0
for k in range(60):
	x = 0
	t = 1 << k
	for i in range(n):
		if a[i] & t:
			x += 1
	c = x * (n - x) * 2 ** k
	ans += c
print(ans % MOD)


n = int(input())
a = list(map(int, input().split()))
mod = 10 ** 9 + 7
ans = 0
for i in range(60):
	cou = 0
	bit = 1 << i
	for j in a:
		if j & bit:
			cou += 1
	num1 = cou
	num0 = n - num1
	ans += num1 * num0 * bit % mod
print(ans % mod)


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


def readinput():
	n = int(input())
	l = list(map(int, input().split()))
	return (n, l)

def main(n, a):
	MOD = 10 ** 9 + 7
	hist = [0] * 61
	bs = []
	for i in range(n):
		s = bin(a[i])[2:]
		for j in range(len(s)):
			if s[j] == '1':
				hist[len(s) - j - 1] += 1
	sum = 0
	b = 1
	for j in range(61):
		sum = (sum + hist[j] * (n - hist[j]) * b % MOD) % MOD
		b *= 2
	return sum

def __starting_point():
	(n, l) = readinput()
	ans = main(n, l)
	print(ans)
__starting_point()


n = int(input())
a = list(map(int, input().split()))
MOD = 10 ** 9 + 7
res = 0
for dig in range(61):
	one = 0
	for i in a:
		if i & 1 << dig != 0:
			one += 1
	res = (res + one * (n - one) * (1 << dig)) % MOD
print(res)


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)


import sys
stdin = sys.stdin

def main():
	N = int(stdin.readline().rstrip())
	A = list(map(int, stdin.readline().split()))
	mod = 10 ** 9 + 7
	ans = 0
	for i in range(61):
		bits = 0
		for x in A:
			if x >> i & 1:
				bits += 1
		ans += bits * (N - bits) * 2 ** i % mod
	ans %= mod
	print(ans)
main()


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)


import numpy as np
N = int(input())
A = tuple(map(int, input().split(' ')))
A = np.array(A, dtype=np.int64)
MOD = 10 ** 9 + 7
ans = 0
mask = 1
for i in range(60):
	ones = np.count_nonzero(A & mask)
	ans += ones * (N - ones) % MOD * (mask % MOD)
	ans %= MOD
	mask <<= 1
print(ans)


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

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

def __starting_point():
	do()
__starting_point()


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


import numpy as np
N = int(input())
num_list = np.array(input().split(), dtype='int')
max_num = max(num_list)
max_bit_num = format(max_num, 'b')
max_bit_num_length = len(max_bit_num)
ans = 0
radix = 1
for i in range(max_bit_num_length):
	new_num_list = num_list >> i & 1
	one_amount = np.count_nonzero(new_num_list == 1)
	zero_amount = len(num_list) - one_amount
	ans += one_amount * zero_amount * radix
	radix *= 2
print(ans % (10 ** 9 + 7))


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


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())
arr = list(map(int, input().split()))
MOD = 10 ** 9 + 7
ans = 0
for i in range(60):
	mask = 1 << i
	cnt = sum([1 for x in arr if x & mask == mask])
	ans += mask * cnt * (n - cnt) % MOD
print(ans % MOD)


import numpy as np
n = int(input())
a = np.array([int(x) for x in input().split()])
ans = 0
mod = pow(10, 9) + 7
for i in range(100):
	c = np.sum(a >> i & 1)
	ans += c * (n - c) % mod * pow(2, i, mod) % mod
	ans %= mod
print(ans)


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


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


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)


def main():
	import sys
	input = sys.stdin.readline
	n = int(input())
	A = [int(x) for x in input().split()]
	ans = 0
	mod = 10 ** 9 + 7
	for d in range(61):
		x = 0
		for a in A:
			if a >> d & 1:
				x += 1
		ans += x * (n - x) * 2 ** d
		ans %= mod
	print(ans)

def __starting_point():
	main()
__starting_point()


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)


def solve(N, As):
	import math
	x = 1 if max(As) == 0 else math.ceil(math.log2(max(As)))
	ans = 0
	mod = 10 ** 9 + 7
	for i in range(x):
		cnt = sum(((A >> i) % 2 for A in As))
		ans += cnt * (N - cnt) * pow(2, i, mod)
		ans = ans % mod
	print(ans)

def __starting_point():
	N = int(input())
	As = [int(i) for i in input().split()]
	solve(N, As)
__starting_point()


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 queue
import numpy as np
import math
n = int(input())
A = list(map(int, input().split()))
A = np.array(A, np.int64)
ans = 0
for i in range(60 + 1):
	a = A >> i & 1
	count1 = np.count_nonzero(a)
	count0 = len(A) - count1
	ans += count1 * count0 * pow(2, i)
	ans %= 1000000007
print(ans)


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


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)


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


import math
import numpy as np
N = 10
ARR = [3, 1, 4, 1, 5, 9, 2, 6, 5, 3]
N = 10
ARR = [3, 14, 159, 2653, 58979, 323846, 2643383, 27950288, 419716939, 9375105820]
N = int(input())
ARR = list(map(int, input().split()))

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


import sys
import math
import os
import itertools
import string
import heapq
import _collections
from collections import Counter
from collections import defaultdict
from collections import deque
from functools import lru_cache
import bisect
import re
import queue
import decimal

class Scanner:

	@staticmethod
	def int():
		return int(sys.stdin.readline().rstrip())

	@staticmethod
	def string():
		return sys.stdin.readline().rstrip()

	@staticmethod
	def map_int():
		return [int(x) for x in Scanner.string().split()]

	@staticmethod
	def string_list(n):
		return [Scanner.string() for i in range(n)]

	@staticmethod
	def int_list_list(n):
		return [Scanner.map_int() for i in range(n)]

	@staticmethod
	def int_cols_list(n):
		return [Scanner.int() for i in range(n)]

class Math:

	@staticmethod
	def gcd(a, b):
		if b == 0:
			return a
		return Math.gcd(b, a % b)

	@staticmethod
	def lcm(a, b):
		return a * b // Math.gcd(a, b)

	@staticmethod
	def divisor(n):
		res = []
		i = 1
		for i in range(1, int(n ** 0.5) + 1):
			if n % i == 0:
				res.append(i)
				if i != n // i:
					res.append(n // i)
		return res

	@staticmethod
	def round_up(a, b):
		return -(-a // b)

	@staticmethod
	def is_prime(n):
		if n < 2:
			return False
		if n == 2:
			return True
		if n % 2 == 0:
			return False
		d = int(n ** 0.5) + 1
		for i in range(3, d + 1, 2):
			if n % i == 0:
				return False
		return True

	@staticmethod
	def fact(N):
		res = {}
		tmp = N
		for i in range(2, int(N ** 0.5 + 1) + 1):
			cnt = 0
			while tmp % i == 0:
				cnt += 1
				tmp //= i
			if cnt > 0:
				res[i] = cnt
		if tmp != 1:
			res[tmp] = 1
		if res == {}:
			res[N] = 1
		return res

def pop_count(x):
	x = x - (x >> 1 & 6148914691236517205)
	x = (x & 3689348814741910323) + (x >> 2 & 3689348814741910323)
	x = x + (x >> 4) & 1085102592571150095
	x = x + (x >> 8)
	x = x + (x >> 16)
	x = x + (x >> 32)
	return x & 127
MOD = int(1000000000.0) + 7
INF = int(1000000000000000.0)

def solve():
	N = Scanner.int()
	A = Scanner.map_int()
	ans = 0
	for i in range(61):
		p = 1
		for _ in range(i):
			p *= 2
			p %= MOD
		x = 0
		for a in A:
			if a >> i & 1:
				x += 1
		t = x * (N - x)
		t %= MOD
		t *= p
		t %= MOD
		ans += t
		ans %= MOD
	print(ans)

def main():
	solve()

def __starting_point():
	main()
__starting_point()


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


import sys
from io import StringIO
import unittest

def resolve():
	readline = sys.stdin.readline
	mod = 10 ** 9 + 7
	n = int(readline())
	arr = list(map(int, readline().rstrip().split()))
	ans = 0
	x = 1
	for i in range(60):
		c = 0
		for j in range(n):
			if arr[j] & x != 0:
				c += 1
		ans += c * (n - c) * x
		ans %= mod
		x = x * 2
	print(ans)
	return
if 'doTest' not in globals():
	resolve()
	return


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