Buggy python submission (verdict: Time Limit Exceeded):
def main():
    n = int(input())
    A = list(map(int, input().split()))
    M = max(A)
    dig = len(bin(M)) - 2
    MOD = 10 ** 9 + 7
    ans = 0
    d = {i: 0 for i in range(dig)}
    for a in A:
        a = bin(a)[2:]
        for i in range(len(a)):
            if a[-(i+1)] == '1':
                d[i] += 1
    for i in range(dig):
        ans += d[i] * (n - d[i]) * pow(2, i, MOD)
        ans %= MOD
    print(ans)
main()


Fixed submission:
def main():
    n = int(input())
    A = list(map(int, input().split()))
    M = max(A)
    dig = len(bin(M)) - 2
    MOD = 10 ** 9 + 7
    ans = 0
    d = {i: [0, 0] for i in range(dig)}
    for a in A:
        a = bin(a)[2:].zfill(dig)
        for i in range(len(a)):
            if a[-(i+1)] == '0':
                d[i][0] += 1
            else:
                d[i][1] += 1
    for i in range(dig):
        ans += d[i][0] * d[i][1] * pow(2, i, MOD)
        ans %= MOD
    print(ans)
main()

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
A = list(map(int, input().split()))
M = max(A)
dig = len(bin(M)) - 2
MOD = 10 ** 9 + 7
ans = 0
d = {i: [0, 0] for i in range(dig)}
for a in A:
    a = bin(a)[2:].zfill(dig)
    for i in range(len(a)):
        if a[-(i+1)] == '0':
            d[i][0] += 1
        else:
            d[i][1] += 1
for i in range(dig):
    ans += d[i][0] * d[i][1] * pow(2, i, MOD)
    ans %= MOD
print(ans)


Fixed submission:
def main():
    n = int(input())
    A = list(map(int, input().split()))
    M = max(A)
    dig = len(bin(M)) - 2
    MOD = 10 ** 9 + 7
    ans = 0
    d = {i: [0, 0] for i in range(dig)}
    for a in A:
        a = bin(a)[2:].zfill(dig)
        for i in range(len(a)):
            if a[-(i+1)] == '0':
                d[i][0] += 1
            else:
                d[i][1] += 1
    for i in range(dig):
        ans += d[i][0] * d[i][1] * pow(2, i, MOD)
        ans %= MOD
    print(ans)
main()

Buggy python submission (verdict: Runtime Error):
n = int(input())
dig = 50
A = list(map(lambda x:bin(int(x))[2:].zfill(dig), input().split()))
MOD = 10 ** 9 + 7
ans = 0
d = {i: [0, 0] for i in range(dig)}
for a in A:
    for i in range(len(a)):
        if a[-(i+1)] == '0':
            d[i][0] += 1
        else:
            d[i][1] += 1
for i in range(dig):
    ans += d[i][0] * d[i][1] * (2 ** i)
    ans %= MOD
print(ans)


Fixed submission:
def main():
    n = int(input())
    A = list(map(int, input().split()))
    M = max(A)
    dig = len(bin(M)) - 2
    MOD = 10 ** 9 + 7
    ans = 0
    d = {i: [0, 0] for i in range(dig)}
    for a in A:
        a = bin(a)[2:].zfill(dig)
        for i in range(len(a)):
            if a[-(i+1)] == '0':
                d[i][0] += 1
            else:
                d[i][1] += 1
    for i in range(dig):
        ans += d[i][0] * d[i][1] * pow(2, i, MOD)
        ans %= MOD
    print(ans)
main()

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):
        ans += a[i] ^ a[j]
        ans %= MOD
print(ans)


Fixed submission:
def main():
    n = int(input())
    A = list(map(int, input().split()))
    M = max(A)
    dig = len(bin(M)) - 2
    MOD = 10 ** 9 + 7
    ans = 0
    d = {i: [0, 0] for i in range(dig)}
    for a in A:
        a = bin(a)[2:].zfill(dig)
        for i in range(len(a)):
            if a[-(i+1)] == '0':
                d[i][0] += 1
            else:
                d[i][1] += 1
    for i in range(dig):
        ans += d[i][0] * d[i][1] * pow(2, i, MOD)
        ans %= MOD
    print(ans)
main()