Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = [int(i) for i in input().split()]

mod = 10**9+7

bin_a = []

for i in range(n):
    bin_a.append(format(a[i],'060b'))

ans = 0

for i in range(60):
    one = 0
    zero = 0
    for j in range(n):
        #print(bin_a[j])
        if bin_a[j][i] == '1':
            one += 1
        else:
            zero += 1
    #print(i,zero,one)
    ans += zero * one * (2**(59-i))
    
print(ans%mod)

Fixed submission:
n = int(input())
a = [int(i) for i in input().split()]

mod = 10**9+7

bin_a = []

for i in range(n):
    bin_a.append(format(a[i],'060b'))

ans = 0

for i in range(60):
    one = 0
    zero = 0
    for j in range(n):
        #print(bin_a[j])
        if bin_a[j][i] == '1':
            one += 1
        else:
            zero += 1
    #print(i,zero,one)
    ans += zero * one * (2**(59-i))
    
print(ans%mod)

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = [int(i) for i in input().split()]

mod = 10**9+7

#sum_a = sum(a)

#bin_num = format(2, 'b')
#print(bin_num,len(bin_num))

max_a = max(a)
bin_max_a = format(max_a, 'b')

#print(bin_max_a)
ans = 0

for i in range(len(bin_max_a)):
    tmp = 0
    #print(i)
    kazu = 0
    for j in range(n):
        #print(j,kazu)
        kazu += int(format(a[j], 'b').zfill(len(bin_max_a))[i])
        #print(a[j],int(format(a[j], 'b').zfill(len(bin_max_a))[i]))
        #print(format(a[j], 'b').zfill(len(bin_max_a))[i])
        #print(kazu)
    if kazu == 0:
        continue
    tmp = kazu*(n-kazu) % mod
    tmp1 = 1
    """
    for i in range(len(bin_max_a)-1-i):
        tmp1 *= 2
        tmp1 %= mod
    """
    tmp1 = 2**(len(bin_max_a)-1-i) % mod
    tmp = tmp*tmp1%mod
    ans += tmp
    ans %= mod
    #print(ans,kazu)
    
print(ans)

Fixed submission:
n = int(input())
a = [int(i) for i in input().split()]

mod = 10**9+7

bin_a = []

for i in range(n):
    bin_a.append(format(a[i],'060b'))

ans = 0

for i in range(60):
    one = 0
    zero = 0
    for j in range(n):
        #print(bin_a[j])
        if bin_a[j][i] == '1':
            one += 1
        else:
            zero += 1
    #print(i,zero,one)
    ans += zero * one * (2**(59-i))
    
print(ans%mod)

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = [int(i) for i in input().split()]

mod = 10**9+7

#sum_a = sum(a)

#bin_num = format(2, 'b')
#print(bin_num,len(bin_num))

max_a = max(a)
bin_max_a = format(max_a, 'b')

#print(bin_max_a)
ans = 0

for i in range(len(bin_max_a)):
    tmp = 0
    #print(i)
    kazu = 0
    for j in range(n):
        #print(j,kazu)
        kazu += int(format(a[j], 'b').zfill(len(bin_max_a))[i])
        #print(a[j],int(format(a[j], 'b').zfill(len(bin_max_a))[i]))
        #print(format(a[j], 'b').zfill(len(bin_max_a))[i])
        #print(kazu)
    if kazu == 0:
        continue
    tmp = kazu*(n-kazu) % mod
    tmp1 = 1
    for i in range(len(bin_max_a)-1-i):
        tmp1 *= 2
        tmp1 %= mod
    #tmp1 = 2**(len(bin_max_a)-1-i) % mod
    tmp = tmp*tmp1%mod
    ans += tmp
    ans %= mod
    #print(ans,kazu)
    
print(ans)

Fixed submission:
n = int(input())
a = [int(i) for i in input().split()]

mod = 10**9+7

bin_a = []

for i in range(n):
    bin_a.append(format(a[i],'060b'))

ans = 0

for i in range(60):
    one = 0
    zero = 0
    for j in range(n):
        #print(bin_a[j])
        if bin_a[j][i] == '1':
            one += 1
        else:
            zero += 1
    #print(i,zero,one)
    ans += zero * one * (2**(59-i))
    
print(ans%mod)