Buggy python submission (verdict: Time Limit Exceeded):
mod=10**9+7
n=int(input())
A=map(int,input().split())

cnt=[0]*60
for a in A:
    for j in range(60):
        cnt[j]+=a&1
        a>>=1

ans=0
b=1
for c in cnt:
    ans+=b*c*(n-c)
    ans%=mod
    b=b*2%mod

print(ans)

Fixed submission:
import sys

sys.setrecursionlimit(10 ** 6)
int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep="\n")
def MI(): return map(int, sys.stdin.readline().split())
def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]

def main():
    md = 10 ** 9 + 7
    n = int(input())
    aa = LI()
    cnt = [[0] * 2 for _ in range(61)]
    for a in aa:
        for i in range(61):
            cnt[i][a & 1] += 1
            a >>= 1
    #print(cnt)
    base = 1
    ans = 0
    for c0, c1 in cnt:
        ans += base * c0 * c1
        ans %= md
        base = base * 2 % md
    print(ans)

main()

Buggy python submission (verdict: Time Limit Exceeded):
from collections import *
from heapq import *
import sys

sys.setrecursionlimit(10 ** 5)
int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep="\n")
def II(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def MI1(): return map(int1, sys.stdin.readline().split())
def LI(): return list(map(int, sys.stdin.readline().split()))
def LI1(): return list(map(int1, sys.stdin.readline().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def SI(): return sys.stdin.readline()[:-1]
dij = [(1, 0), (-1, 0), (0, 1), (0, -1)]

class mint:
    def __init__(self, x):
        self.__x = x % md

    def __str__(self):
        return str(self.__x)

    def __neg__(self):
        return mint(-self.__x)

    def __add__(self, other):
        if isinstance(other, mint): other = other.__x
        return mint(self.__x + other)

    def __sub__(self, other):
        if isinstance(other, mint): other = other.__x
        return mint(self.__x - other)

    def __rsub__(self, other):
        return mint(other - self.__x)

    def __mul__(self, other):
        if isinstance(other, mint): other = other.__x
        return mint(self.__x * other)

    __radd__ = __add__
    __rmul__ = __mul__

    def __truediv__(self, other):
        if isinstance(other, mint): other = other.__x
        return mint(self.__x * pow(other, md - 2, md))

    def __rtruediv__(self, other):
        return mint(other * pow(self.__x, md - 2, md))

    def __pow__(self, power, modulo=None):
        return mint(pow(self.__x, power, md))

md = 10**9+7

def main():
    ans=mint(0)
    n=II()
    aa=LI()
    for i in range(61):
        cnt1=0
        for a in aa:cnt1+=a>>i&1
        ans+=(1<<i)*cnt1*(n-cnt1)
    print(ans)

main()


Fixed submission:
import sys

sys.setrecursionlimit(10 ** 6)
int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep="\n")
def MI(): return map(int, sys.stdin.readline().split())
def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]

def main():
    md = 10 ** 9 + 7
    n = int(input())
    aa = LI()
    cnt = [[0] * 2 for _ in range(61)]
    for a in aa:
        for i in range(61):
            cnt[i][a & 1] += 1
            a >>= 1
    #print(cnt)
    base = 1
    ans = 0
    for c0, c1 in cnt:
        ans += base * c0 * c1
        ans %= md
        base = base * 2 % md
    print(ans)

main()

Buggy python submission (verdict: Time Limit Exceeded):
import sys

sys.setrecursionlimit(10 ** 6)
int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep="\n")
def MI(): return map(int, sys.stdin.readline().split())
def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]

def main():
    md = 10 ** 9 + 7
    n = int(input())
    aa = LI()
    cnt = [[0] * 2 for _ in range(61)]
    for a in aa:
        for i in range(61):
            cnt[i][a & 1] += 1
            a >>= 1
    #print(cnt)
    base = 1
    ans = 0
    for c0, c1 in cnt:
        ans += base * c0 * c1
        ans %= md
        base = base * 2 % md
    print(ans)

main()


Fixed submission:
import sys

sys.setrecursionlimit(10 ** 6)
int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep="\n")
def MI(): return map(int, sys.stdin.readline().split())
def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]

def main():
    md = 10 ** 9 + 7
    n = int(input())
    aa = LI()
    cnt = [[0] * 2 for _ in range(61)]
    for a in aa:
        for i in range(61):
            cnt[i][a & 1] += 1
            a >>= 1
    #print(cnt)
    base = 1
    ans = 0
    for c0, c1 in cnt:
        ans += base * c0 * c1
        ans %= md
        base = base * 2 % md
    print(ans)

main()