Buggy python submission (verdict: Time Limit Exceeded):
import sys
sys.setrecursionlimit(1000000000)
from itertools import count
from functools import lru_cache
from collections import defaultdict
from pprint import pprint
ii = lambda: int(input())
mis = lambda: map(int, input().split())
lmis = lambda: list(mis())
INF = float('inf')
N1097 = 10**9 + 7

def meg(f, ok, ng):
    while abs(ok-ng)>1:
        mid = (ok+ng)//2
        if f(mid):
            ok=mid
        else:
            ng=mid
    return ok
#

def main():
    N = ii()
    S1 = [0] * 100
    for a in mis():
        b = 1
        for i in count():
            if b > a:
                break
            if a & b:
                S1[i] += 1
            b <<= 1
    ans = 0
    b = 1
    for i in range(len(S1)):
        s1 = S1[i]
        s0 = N - s1
        ans += (s1*s0) * (b%N1097)
        ans %= N1097
        b <<= 1

    print(ans)




main()


Fixed submission:
import sys
sys.setrecursionlimit(1000000000)
from itertools import count
from functools import lru_cache
from collections import defaultdict
from pprint import pprint
ii = lambda: int(input())
mis = lambda: map(int, input().split())
lmis = lambda: list(mis())
INF = float('inf')
N1097 = 10**9 + 7

def meg(f, ok, ng):
    while abs(ok-ng)>1:
        mid = (ok+ng)//2
        if f(mid):
            ok=mid
        else:
            ng=mid
    return ok
#

def main():
    N = ii()
    S1 = [0] * 100
    for a in mis():
        b = 1
        for i in count():
            if b > a:
                break
            if a & b:
                S1[i] += 1
            b <<= 1
    ans = 0
    b = 1
    for i in range(len(S1)):
        s1 = S1[i]
        s0 = N - s1
        ans += (s1*s0) * (b%N1097)
        ans %= N1097
        b <<= 1

    print(ans)




main()

Buggy python submission (verdict: Time Limit Exceeded):
import sys
sys.setrecursionlimit(1000000000)
from itertools import count
from functools import lru_cache
from collections import defaultdict
from pprint import pprint
ii = lambda: int(input())
mis = lambda: map(int, input().split())
lmis = lambda: list(mis())
INF = float('inf')
N1097 = 10**9 + 7

def meg(f, ok, ng):
    while abs(ok-ng)>1:
        mid = (ok+ng)//2
        if f(mid):
            ok=mid
        else:
            ng=mid
    return ok
#

def main():
    N = ii()
    A = lmis()
    maxA = max(A)
    ans = 0
    for i in count():
        b = 1<<i
        if b > maxA:
            break
        S1 = sum(bool(a & b) for a in A)
        S0 = N - S1
        ans += (S1*S0) * (b%N1097)
        ans %= N1097
    print(ans)

main()


Fixed submission:
import sys
sys.setrecursionlimit(1000000000)
from itertools import count
from functools import lru_cache
from collections import defaultdict
from pprint import pprint
ii = lambda: int(input())
mis = lambda: map(int, input().split())
lmis = lambda: list(mis())
INF = float('inf')
N1097 = 10**9 + 7

def meg(f, ok, ng):
    while abs(ok-ng)>1:
        mid = (ok+ng)//2
        if f(mid):
            ok=mid
        else:
            ng=mid
    return ok
#

def main():
    N = ii()
    S1 = [0] * 100
    for a in mis():
        b = 1
        for i in count():
            if b > a:
                break
            if a & b:
                S1[i] += 1
            b <<= 1
    ans = 0
    b = 1
    for i in range(len(S1)):
        s1 = S1[i]
        s0 = N - s1
        ans += (s1*s0) * (b%N1097)
        ans %= N1097
        b <<= 1

    print(ans)




main()