Buggy python submission (verdict: Time Limit Exceeded):
def main():
    MOD = 10 ** 9 + 7

    N = int(input())
    *a, = map(int, input().split())

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

    t = 1
    ans = 0
    for j in range(60):
        ans = (ans + b[j] * (N - b[j]) * t) % MOD
        t <<= 1
    print(ans)


if __name__ == '__main__':
    main()

# import sys
#
# sys.setrecursionlimit(10 ** 7)
#
# input = sys.stdin.readline
# rstrip()
# int(input())
# map(int, input().split())


Fixed submission:
def main():
    import sys

    input = sys.stdin.readline

    mod = 10 ** 9 + 7
    n = int(input())
    a = tuple(map(int, input().split()))

    b = [0] * 60

    for j in range(60):
        for x in a:
            if (x >> j) & 1:
                b[j] += 1

    ret = 0
    for j in range(60):
        ret = (ret + b[j] * (n - b[j]) * (1 << j)) % mod

    print(ret)


if __name__ == '__main__':
    main()

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

    input = sys.stdin.readline

    mod = 10 ** 9 + 7

    n = int(input())
    a = tuple(map(int, input().split()))

    ret = 0
    for j in range(60):
        cnt1 = sum((x >> j) & 1 for x in a)
        cnt0 = n - cnt1
        ret = (ret + cnt0 * cnt1 * (1 << j)) % mod

    print(ret)


if __name__ == '__main__':
    main()


Fixed submission:
def main():
    import sys

    input = sys.stdin.readline

    mod = 10 ** 9 + 7
    n = int(input())
    a = tuple(map(int, input().split()))

    b = [0] * 60

    for j in range(60):
        for x in a:
            if (x >> j) & 1:
                b[j] += 1

    ret = 0
    for j in range(60):
        ret = (ret + b[j] * (n - b[j]) * (1 << j)) % mod

    print(ret)


if __name__ == '__main__':
    main()

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

    input = sys.stdin.readline

    mod = 10 ** 9 + 7
    n = int(input())
    a = tuple(map(int, input().split()))

    b = [[0] * 60 for _ in range(n + 1)]

    for j in range(60):
        for i, x in enumerate(a, 1):
            if (x >> j) & 1:
                b[i][j] += 1

    for j in range(60):
        for i in range(1, n + 1):
            b[i][j] += b[i - 1][j]

    # print(b)

    s = b[-1]

    ret = 0
    for j in range(60):
        for i, x in enumerate(a, 1):
            if (x >> j) & 1:
                ret = (ret + (1 << j) * ((n - i) - (s[j] - b[i][j]))) % mod
            else:
                ret = (ret + (1 << j) * (s[j] - b[i][j])) % mod
    print(ret)


if __name__ == '__main__':
    main()


Fixed submission:
def main():
    import sys

    input = sys.stdin.readline

    mod = 10 ** 9 + 7
    n = int(input())
    a = tuple(map(int, input().split()))

    b = [0] * 60

    for j in range(60):
        for x in a:
            if (x >> j) & 1:
                b[j] += 1

    ret = 0
    for j in range(60):
        ret = (ret + b[j] * (n - b[j]) * (1 << j)) % mod

    print(ret)


if __name__ == '__main__':
    main()

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

    b = [[0] * 60]

    for i, x in enumerate(a):
        t = list(b[-1])
        for j in range(60):
            if (x >> j) & 1:
                t[j] += 1
        b.append(t)

    ret = 0
    for i, x in enumerate(a, 1):
        for j in range(60):
            j_on = (b[-1][j] - b[i][j])
            if (x >> j) & 1:
                ret += (1 << j) * ((n - i) - j_on)
            else:
                ret += (1 << j) * j_on
            ret %= mod
    print(ret)


if __name__ == '__main__':
    main()


Fixed submission:
def main():
    import sys

    input = sys.stdin.readline

    mod = 10 ** 9 + 7
    n = int(input())
    a = tuple(map(int, input().split()))

    b = [0] * 60

    for j in range(60):
        for x in a:
            if (x >> j) & 1:
                b[j] += 1

    ret = 0
    for j in range(60):
        ret = (ret + b[j] * (n - b[j]) * (1 << j)) % mod

    print(ret)


if __name__ == '__main__':
    main()