Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A = list(map(int, input().split()))
mod = 10**9+7
ans = 0
for i in range(61):
    bit = 1 << i
    count = 0
    for j in range(N):
        if bit & A[j]:
            count += 1
    ans += 2**i * count * (N-count) % mod
print(ans % mod)


Fixed submission:
mod = 10**9 + 7
N = int(input())
A = list(map(int, input().split()))
ans = 0
loop_count = len(format(max(A), "b"))

for i in range(loop_count):
    tmp = 0
    for ai in A:
        if ((1 << i) & ai) > 0:
            tmp += 1
    ans += (1 << i) * tmp * (N - tmp) % mod
print(ans % mod)

Buggy python submission (verdict: Time Limit Exceeded):
mod = 10**9 + 7
N = int(input())
A = list(map(int, input().split()))
ans = 0
loop_count = len(format(max(A), "b"))

for i in range(loop_count):
    tmp = 0
    for ai in A:
        if ((1 << i) & ai) > 0:
            tmp += 1
    ans += (1 << i) * tmp * (N - tmp) % mod
print(ans % mod)


Fixed submission:
mod = 10**9 + 7
N = int(input())
A = list(map(int, input().split()))
ans = 0
loop_count = len(format(max(A), "b"))

for i in range(loop_count):
    tmp = 0
    for ai in A:
        if ((1 << i) & ai) > 0:
            tmp += 1
    ans += (1 << i) * tmp * (N - tmp) % mod
print(ans % mod)

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A = list(map(int, input().split()))
max_a = max(A)
bit_count = {}
for i in range(len(format(max_a, "b"))):
    bit_count[i] = [0, 0]
# 辞書の初期化が完了
max_value = i
zero_ume = "0" + str(len(format(max_a, "b"))) + "b"
for i in range(N):
    for j in reversed(range(len(format(A[i], zero_ume)))):
        if format(A[i], zero_ume)[j] == "0":
            bit_count[max_value-j][0] += 1
        else:
            bit_count[max_value-j][1] += 1
mod = 10**9+7
ans = 0
for k, v in bit_count.items():
    ans += (2**k) * v[0] * v[1] % mod
print(ans % mod)


Fixed submission:
mod = 10**9 + 7
N = int(input())
A = list(map(int, input().split()))
ans = 0
loop_count = len(format(max(A), "b"))

for i in range(loop_count):
    tmp = 0
    for ai in A:
        if ((1 << i) & ai) > 0:
            tmp += 1
    ans += (1 << i) * tmp * (N - tmp) % mod
print(ans % mod)

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A = list(map(int, input().split()))
max_a = max(A)
bit_count = {}
for i in range(len(format(max_a, "b"))):
    bit_count[i] = [0, 0]
# 辞書の初期化が完了
max_value = i
zero_ume = "0" + str(len(format(max_a, "b"))) + "b"
for i in range(N):
    for j in reversed(range(len(format(A[i], zero_ume)))):
        if format(A[i], zero_ume)[j] == "0":
            bit_count[max_value-j][0] += 1
        else:
            bit_count[max_value-j][1] += 1
mod = 10**9+7
ans = 0
for k, v in bit_count.items():
    ans += (2**k) * v[0] * v[1] % mod
print(ans % mod)


Fixed submission:
mod = 10**9 + 7
N = int(input())
A = list(map(int, input().split()))
ans = 0
loop_count = len(format(max(A), "b"))

for i in range(loop_count):
    tmp = 0
    for ai in A:
        if ((1 << i) & ai) > 0:
            tmp += 1
    ans += (1 << i) * tmp * (N - tmp) % mod
print(ans % mod)

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A = list(map(int, input().split()))
mod = 10**9+7
ans = 0
for i in range(N-1):
    for j in range(i+1, N):
        # print(A[i], A[j], A[i]^A[j])
        ans += (A[i] ^ A[j]) % mod
        # print(A[i]^A[j])
print(ans % mod)


Fixed submission:
mod = 10**9 + 7
N = int(input())
A = list(map(int, input().split()))
ans = 0
loop_count = len(format(max(A), "b"))

for i in range(loop_count):
    tmp = 0
    for ai in A:
        if ((1 << i) & ai) > 0:
            tmp += 1
    ans += (1 << i) * tmp * (N - tmp) % mod
print(ans % mod)

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A = list(map(int, input().split()))
mod = 10**9+7
ans = 0
for i in range(N-1):
    for j in range(i+1, N):
        # print(A[i], A[j], A[i]^A[j])
        ans += (A[i] ^ A[j]) % mod
        # print(A[i]^A[j])
print(ans % mod)


Fixed submission:
mod = 10**9 + 7
N = int(input())
A = list(map(int, input().split()))
ans = 0
loop_count = len(format(max(A), "b"))

for i in range(loop_count):
    tmp = 0
    for ai in A:
        if ((1 << i) & ai) > 0:
            tmp += 1
    ans += (1 << i) * tmp * (N - tmp) % mod
print(ans % mod)