Buggy python submission (verdict: Time Limit Exceeded):
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):
        c = 0
        while a[i]>0:
            if a[i] %2 == 1:
                div[c] += 1
            a[i] = a[i]//2
            c+=1
    ans = 0
    for k in div.keys():
        ans += div[k] * (n-div[k]) * 2**k
        ans = ans % mod
    print(ans)

if __name__ == "__main__":
    main()


Fixed submission:
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)

Buggy python submission (verdict: Time Limit Exceeded):
def main():
    n = int(input())
    a = list(map(int,input().split()))
    mod = 10**9+7
    div = {}
    for i in range(n):
        c = 0
        while a[i]>0:
            if a[i]%2==1:
                if c not in div.keys():
                    div[c] = 1
                else:
                    div[c] += 1
            a[i] = a[i]//2
            c += 1
    ans = 0
    for k in div.keys():
        ans += div[k] * (n-div[k]) * 2**k
        ans = ans % mod
    print(ans)

if __name__ == "__main__":
    main()


Fixed submission:
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)

Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
a = list(map(lambda x:format(x,'060b'),map(int,input().split())))

p = 10**9+7
ans = 0

for i in range(60):
    one = 0
    for j in range(n):
        if a[j][59-i]=='1':
            one += 1
    ans += pow(2,i,p)*one*(n-one)

print(ans%p)


Fixed submission:
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)

Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
a = list(map(lambda x:format(x,'b'),map(int,input().split())))
b = list(map(len,a))

p = 10**9+7
s = 0
for i in range(max(b)):
    zero = 0
    one = 0
    for j in range(n):
        if len(a[j]) < i+1:
            zero += 1
            continue
        if a[j][-(1+i)]=='1':
            one += 1
        else:
            zero += 1
    cnt = one*zero%p
    s += (cnt*pow(2,i,p))%p

print(s%p)


Fixed submission:
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)

Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
a = list(map(lambda x:format(x,'b'),map(int,input().split())))
b = list(map(len,a))

p = 10**9+7
s = 0
for i in range(max(b)):
    zero = 0
    one = 0
    for j in range(n):
        if len(a[j]) < i+1:
            zero += 1
            continue
        if a[j][-(1+i)]=='1':
            one += 1
        else:
            zero += 1
    s += (one*zero)*2**i%p

print(s%p)


Fixed submission:
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)

Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
a = list(map(lambda x: x[2:],map(bin,map(int,input().split()))))

p = 10**9+7
def xor(a,b):
    a,b = int(a),int(b)
    c = str(a+b)
    c = list(map(lambda x: '1' if x=="1" else '0',c))
    s = 0
    for i in range(len(c)):
        s += int(c[len(c)-1-i])*2**i % p
    return s%p
s = 0
for i in range(n-1):
    for j in range(i+1,n):
        s += xor(a[i],a[j])
        s = s%p
print(s)

Fixed submission:
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)