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

N = 10
ARR = [3, 1, 4, 1, 5, 9, 2, 6, 5, 3]

N = 10
ARR = [3, 14, 159, 2653, 58979, 323846, 2643383, 27950288, 419716939, 9375105820]

# N = 3
# ARR = [1, 2, 3]

# N = 5
# ARR = [3, 6, 8, 9, 10]

N = int(input())
ARR = list(map(int,input().split()))


def calculate(n, arr):
    if max(arr) == 0:
        mathNum = 1
    else:
        mathNum = math.ceil(math.log(max(arr), 2)) + 1
    result = 0
    for i in range(mathNum):

        oneSum = 0
        zeroSum = 0

        for j in range(n):
            if ((arr[j] >> i) & 1) == 0:
                zeroSum += 1
            else:
                oneSum += 1

        result += (2 ** i) * (zeroSum * oneSum)

    print(result % (10**9 + 7))


calculate(N, ARR)


Fixed submission:
import math
import numpy as np

N = 10
ARR = [3, 1, 4, 1, 5, 9, 2, 6, 5, 3]

N = 10
ARR = [3, 14, 159, 2653, 58979, 323846, 2643383, 27950288, 419716939, 9375105820]


# N = 3
# ARR = [1, 2, 3]

# N = 5
# ARR = [3, 6, 8, 9, 10]

N = int(input())
ARR = list(map(int, input().split()))


def calculate(n, arr):
    if max(arr) == 0:
        mathNum = 1
    else:
        mathNum = math.ceil(math.log(max(arr), 2))

    oneArray =  [0] * mathNum
    zeroArray = [0] * mathNum

    result = 0
    arr = np.array(arr)
    for i in range(mathNum):
        s = (arr >> i) & 1

        oneCount = np.count_nonzero(s)
        zeroCount = n - oneCount
        oneArray[i] = oneCount
        zeroArray[i] = zeroCount

    for i in range(mathNum):
        result += (2 ** i) * (oneArray[i] * zeroArray[i])

    print(result % (10 ** 9 + 7))


calculate(N, ARR)

Buggy python submission (verdict: Runtime Error):
import math

N = 10
ARR = [3, 1, 4, 1, 5, 9, 2, 6, 5, 3]

N = 10
ARR = [3, 14, 159, 2653, 58979, 323846, 2643383, 27950288, 419716939, 9375105820]

# N = 3
# ARR = [1, 2, 3]

# N = 5
# ARR = [3, 6, 8, 9, 10]

N = int(input())
ARR = list(map(int,input().split()))


def calculate(n, arr):
    mathNum = math.ceil(math.log(max(arr), 2)) + 1
    result = 0
    for i in range(mathNum):

        oneSum = 0
        zeroSum = 0
        for j in range(n):
            if ((arr[j] >> i) & 1) == 0:
                zeroSum += 1
            else:
                oneSum += 1

        result += 2 ** i * (zeroSum * oneSum)

    print(result % (10**9 + 7))


calculate(N, ARR)


Fixed submission:
import math
import numpy as np

N = 10
ARR = [3, 1, 4, 1, 5, 9, 2, 6, 5, 3]

N = 10
ARR = [3, 14, 159, 2653, 58979, 323846, 2643383, 27950288, 419716939, 9375105820]


# N = 3
# ARR = [1, 2, 3]

# N = 5
# ARR = [3, 6, 8, 9, 10]

N = int(input())
ARR = list(map(int, input().split()))


def calculate(n, arr):
    if max(arr) == 0:
        mathNum = 1
    else:
        mathNum = math.ceil(math.log(max(arr), 2))

    oneArray =  [0] * mathNum
    zeroArray = [0] * mathNum

    result = 0
    arr = np.array(arr)
    for i in range(mathNum):
        s = (arr >> i) & 1

        oneCount = np.count_nonzero(s)
        zeroCount = n - oneCount
        oneArray[i] = oneCount
        zeroArray[i] = zeroCount

    for i in range(mathNum):
        result += (2 ** i) * (oneArray[i] * zeroArray[i])

    print(result % (10 ** 9 + 7))


calculate(N, ARR)