Buggy python submission (verdict: Time Limit Exceeded):
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians, atan, degrees
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
from bisect import bisect

def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

def main():
	N = INT()
	A = LIST()

	upper_len = len("{:b}".format(max(A)))

	cnt = [defaultdict(int) for _ in range(upper_len)]
	for i in range(N):
		num = "{:b}".format(A[i]).zfill(upper_len)
		for j in range(len(num)):
			cnt[upper_len-j-1][num[j]] += 1

	ans = 0
	for i in range(upper_len):
		ans = (ans + (1<<i)*cnt[i]["0"]*cnt[i]["1"])%mod
	print(ans)

if __name__ == "__main__":
	main()


Fixed submission:
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians, atan, degrees
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
from bisect import bisect

def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

def main():
	N = INT()
	A = LIST()

	upper_len = len("{:b}".format(max(A)))

	cnt = [defaultdict(int) for _ in range(upper_len)]
	for i in range(N):
		num = "{:b}".format(A[i]).zfill(upper_len)
		for j in range(len(num)):
			cnt[upper_len-j-1][num[j]] += 1

	ans = 0
	for i in range(upper_len):
		ans = (ans + (1<<i)*cnt[i]["0"]*cnt[i]["1"])%mod
	print(ans)

if __name__ == "__main__":
	main()

Buggy python submission (verdict: Time Limit Exceeded):
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians, atan, degrees
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
from bisect import bisect

def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

N = INT()
A = LIST()

A.sort()
A_acc = list(accumulate(A))
upper_len = len("{:b}".format(max(A)))

upper = 10**6  # 必要そうな階乗の限界を入れる
factorial = [1]
for i in range(1, upper):
    factorial.append(factorial[i-1] * i % mod)

def power(x, y):
    if y == 0:
        return 1
    elif y == 1:
        return x % mod
    elif y % 2 == 0:
        return power(x, int(y/2)) ** 2 % mod
    else:
        return power(x, int((y-1)/2)) ** 2 * x % mod

def C(n, r):
    return (((factorial[n] * x_inv[r]) % mod) * x_inv[n-r]) % mod
x_inv = [0] * (upper)
x_inv[-1] = power(factorial[-1], mod-2)
for i in range(upper-2, -1, -1):
    x_inv[i] = x_inv[i+1] * (i+1) % mod

cnt = [defaultdict(int) for _ in range(upper_len)]
for i in range(N):
	num = "{:b}".format(A[i]).zfill(upper_len)
	for j in range(len(num)):
		cnt[upper_len-j-1][num[j]] += 1

ans = 0
for i in range(upper_len):
	ans = (ans + (2**i)*cnt[i]["0"]*cnt[i]["1"])%mod
print(ans)


Fixed submission:
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians, atan, degrees
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
from bisect import bisect

def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

def main():
	N = INT()
	A = LIST()

	upper_len = len("{:b}".format(max(A)))

	cnt = [defaultdict(int) for _ in range(upper_len)]
	for i in range(N):
		num = "{:b}".format(A[i]).zfill(upper_len)
		for j in range(len(num)):
			cnt[upper_len-j-1][num[j]] += 1

	ans = 0
	for i in range(upper_len):
		ans = (ans + (1<<i)*cnt[i]["0"]*cnt[i]["1"])%mod
	print(ans)

if __name__ == "__main__":
	main()