Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = list(map(int, input().split()))

cnt = [[[0, 0] for _ in range(n + 1)] for _ in range(60)]
for i in range(60): # <= 2^60
    for j, v in enumerate(a):
        if v & (1 << i):
            cnt[i][j][1] = cnt[i][j - 1][1] + 1
            cnt[i][j][0] = cnt[i][j - 1][0]
        else:
            cnt[i][j][1] = cnt[i][j - 1][1]
            cnt[i][j][0] = cnt[i][j - 1][0] + 1

result = 0
for p, delete in enumerate(a):
    for i, cs in enumerate(cnt):
        if delete & (1 << i):
            target = 0
        else:
            target = 1

        result += (cs[n - 1][target] - cs[p - 1][target]) * (1 << i)
print(result % (10**9 + 7))


Fixed submission:
n = int(input())
a = list(map(int, input().split()))

cnt = [[0, 0] for _ in range(60)]
for i in range(60): # <= 2^60
    for j, v in enumerate(a):
        cnt[i][bool(v & (1 << i))] += 1


# print(cnt[:5])
sub = [[0, 0] for _ in range(60)]

# "001"
# "010"
# "011"

result = 0
for i, c in enumerate(cnt):
    for j, delete in enumerate(a[:-1]):
        target = not (delete & (1 << i))
        result += (c[target] - sub[i][target]) * (1 << i)

        # print(i, ":", int(target), c[target], result, sub[i], "->", sub[i][target])

        sub[i][not target] += 1

    # print(result)
    # print("-----")
    # if i > 5: break

# print(result)


# for p, delete in enumerate(a):
#     for i, cs in enumerate(cnt):
#         if delete & (1 << i):
#             target = 0
#         else:
#             target = 1
#
#         result += (cs[n - 1][target] - cs[p - 1][target]) * (1 << i)
print(result % (10**9 + 7))

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = list(map(int, input().split()))

cnt = [[[0, 0] for _ in range(n + 1)] for _ in range(60)]
for i in range(60): # <= 2^60
    for j, v in enumerate(a):
        if v & (1 << i):
            cnt[i][j][1] = cnt[i][j - 1][1] + 1
            cnt[i][j][0] = cnt[i][j - 1][0]
        else:
            cnt[i][j][1] = cnt[i][j - 1][1]
            cnt[i][j][0] = cnt[i][j - 1][0] + 1

result = 0
for p, delete in enumerate(a):
    for i, cs in enumerate(cnt):
        if delete & (1 << i):
            target = 0
        else:
            target = 1

        result += (cs[n - 1][target] - cs[p - 1][target]) * (1 << i)
print(result % (10**9 + 7))


Fixed submission:
n = int(input())
a = list(map(int, input().split()))

cnt = [[0, 0] for _ in range(60)]
for i in range(60): # <= 2^60
    for j, v in enumerate(a):
        cnt[i][bool(v & (1 << i))] += 1


# print(cnt[:5])
sub = [[0, 0] for _ in range(60)]

# "001"
# "010"
# "011"

result = 0
for i, c in enumerate(cnt):
    for j, delete in enumerate(a[:-1]):
        target = not (delete & (1 << i))
        result += (c[target] - sub[i][target]) * (1 << i)

        # print(i, ":", int(target), c[target], result, sub[i], "->", sub[i][target])

        sub[i][not target] += 1

    # print(result)
    # print("-----")
    # if i > 5: break

# print(result)


# for p, delete in enumerate(a):
#     for i, cs in enumerate(cnt):
#         if delete & (1 << i):
#             target = 0
#         else:
#             target = 1
#
#         result += (cs[n - 1][target] - cs[p - 1][target]) * (1 << i)
print(result % (10**9 + 7))