Buggy python submission (verdict: Time Limit Exceeded):
import sys
mod = int(1e9+7)
input=sys.stdin.readline
N = int(input())
A = list(map(int, input().split()))
#S[0]は使わない
S = [[0]*60 for _ in range(N)]

tmp = A[-1]
idx = 0
while tmp > 0:
    if tmp%2:
        S[-1][idx] += 1
    idx += 1
    tmp //= 2


for i in range(N-2, 0, -1):
    for j in range(60):
        S[i][j] = S[i+1][j]
    tmp = A[i]
    idx = 0
    while tmp > 0:
        if tmp % 2:
            S[i][idx] += 1
        idx += 1
        tmp //= 2

ans = 0
for i in range(N-1):
    tmp = A[i]
    idx = 0
    while tmp > 0:
        if tmp % 2:
            ans += ((N-1-i)-S[i+1][idx])*pow(2, idx, mod)%mod

        else:
            ans += S[i+1][idx]*pow(2, idx, mod)%mod

        idx += 1
        tmp //= 2
        ans %= mod
    for x in S[i+1][idx:]:
        ans += x*pow(2, idx, mod)%mod
        idx += 1
        ans %= mod

print(ans)


Fixed submission:
mod = int(1e9+7)
N = int(input())
A = list(map(int, input().split()))
ans = 0
for i in range(60):
    a = 0
    b = 0
    for j in range(N):
        if A[j] % 2:
            a += 1
        else:
            b += 1
        A[j] //= 2
    ans += a*b*pow(2, i, mod)
    ans %= mod
print(ans)

Buggy python submission (verdict: Runtime Error):
import sys
mod = int(1e9+7)
input=sys.stdin.readline
N = int(input())
A = list(map(int, input().split()))
#S[0]は使わない
S = [[0]*60 for _ in range(N)]

tmp = A[-1]
idx = 0
while tmp > 0:
    if tmp%2:
        S[-1][idx] += 1
    idx += 1
    tmp //= 2

for i in range(N-2, 0, -1):
    for j in range(60):
        S[i][j] = S[i+1][j]
    tmp = A[i]
    idx = 0
    while tmp > 0:
        if tmp % 2:
            S[i][idx] += 1
        idx += 1
        tmp //= 2

ans = 0
for i in range(N-1):
    tmp = A[i]
    idx = 0
    while tmp > 0:
        if tmp % 2:
            ans += ((N-1-i)-S[i+1][idx])*pow(2, idx, mod)%mod

        else:
            ans += S[i+1][idx]*pow(2, idx, mod)%mod

        idx += 1
        tmp //= 2
        ans %= mod

    rest = S[i+1][idx:]
    for x in rest:
        ans += xpow(2, idx, mod)%mod
        idx += 1
        ans %= mod

print(ans)

Fixed submission:
mod = int(1e9+7)
N = int(input())
A = list(map(int, input().split()))
ans = 0
for i in range(60):
    a = 0
    b = 0
    for j in range(N):
        if A[j] % 2:
            a += 1
        else:
            b += 1
        A[j] //= 2
    ans += a*b*pow(2, i, mod)
    ans %= mod
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
mod = int(1e9+7)
N = int(input())
A = list(map(int, input().split()))
ans = 0
for i in range(60):
    a = 0
    b = 0
    for j in range(N):
        if A[j] % 2:
            a += 1
        else:
            b += 1
        A[j] //= 2
    ans += a*b*(2**i)
    ans %= mod
print(ans)


Fixed submission:
mod = int(1e9+7)
N = int(input())
A = list(map(int, input().split()))
ans = 0
for i in range(60):
    a = 0
    b = 0
    for j in range(N):
        if A[j] % 2:
            a += 1
        else:
            b += 1
        A[j] //= 2
    ans += a*b*pow(2, i, mod)
    ans %= mod
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
mod = int(1e9+7)
N = int(input())
A = list(map(int, input().split()))
#S[0]は使わない
S = [[0]*60 for _ in range(N)]

tmp = A[-1]
idx = 0
while tmp > 0:
    if tmp%2:
        S[-1][idx] += 1
    idx += 1
    tmp //= 2

for i in range(N-2, 0, -1):
    for j in range(60):
        S[i][j] = S[i+1][j]
    tmp = A[i]
    idx = 0
    while tmp > 0:
        if tmp % 2:
            S[i][idx] += 1
        idx += 1
        tmp //= 2

ans = 0
for i in range(N-1):
    tmp = A[i]
    idx = 0
    while tmp > 0:
        if tmp % 2:
            ans += ((N-1-i)-S[i+1][idx])*2**idx%mod

        else:
            ans += S[i+1][idx]*2**idx%mod

        idx += 1
        tmp //= 2

    rest = S[i+1][idx:]
    for x in rest:
        ans += x*2**idx%mod
        idx += 1

    ans %= mod

print(ans)


Fixed submission:
mod = int(1e9+7)
N = int(input())
A = list(map(int, input().split()))
ans = 0
for i in range(60):
    a = 0
    b = 0
    for j in range(N):
        if A[j] % 2:
            a += 1
        else:
            b += 1
        A[j] //= 2
    ans += a*b*pow(2, i, mod)
    ans %= mod
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
def main():
    import sys
    mod = int(1e9+7)
    input=sys.stdin.readline
    N = int(input())
    A = list(map(int, input().split()))
    #S[0]は使わない
    S = [[0]*60 for _ in range(N)]

    tmp = A[-1]
    idx = 0
    while tmp > 0:
        if tmp%2:
            S[-1][idx] += 1
        idx += 1
        tmp //= 2
    S[-1] = tuple(S[-1])

    for i in range(N-2, 0, -1):
        for j in range(60):
            S[i][j] = S[i+1][j]
        tmp = A[i]
        idx = 0
        while tmp > 0:
            if tmp % 2:
                S[i][idx] += 1
            idx += 1
            tmp //= 2
        S[i] = tuple(S[i])

    ans = 0
    for i in range(N-1):
        tmp = A[i]
        idx = 0
        while tmp > 0:
            if tmp % 2:
                ans += ((N-1-i)-S[i+1][idx])*2**idx

            else:
                ans += S[i+1][idx]*2**idx

            idx += 1
            tmp //= 2

        for x in S[i+1][idx:]:
            ans += x*2**idx%mod
            idx += 1

        ans %= mod

    print(ans)

if __name__ == '__main__':
    main()

Fixed submission:
mod = int(1e9+7)
N = int(input())
A = list(map(int, input().split()))
ans = 0
for i in range(60):
    a = 0
    b = 0
    for j in range(N):
        if A[j] % 2:
            a += 1
        else:
            b += 1
        A[j] //= 2
    ans += a*b*pow(2, i, mod)
    ans %= mod
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
def main():
    import sys
    mod = int(1e9+7)
    input=sys.stdin.readline
    N = int(input())
    A = list(map(int, input().split()))
    #S[0]は使わない
    S = [[0]*60 for _ in range(N)]

    tmp = A[-1]
    idx = 0
    while tmp > 0:
        if tmp%2:
            S[-1][idx] += 1
        idx += 1
        tmp //= 2

    for i in range(N-2, 0, -1):
        for j in range(60):
            S[i][j] = S[i+1][j]
        tmp = A[i]
        idx = 0
        while tmp > 0:
            if tmp % 2:
                S[i][idx] += 1
            idx += 1
            tmp //= 2

    ans = 0
    for i in range(N-1):
        tmp = A[i]
        idx = 0
        while tmp > 0:
            if tmp % 2:
                ans += ((N-1-i)-S[i+1][idx])*2**idx

            else:
                ans += S[i+1][idx]*2**idx

            idx += 1
            tmp //= 2

        for x in S[i+1][idx:]:
            ans += x*2**idx%mod
            idx += 1

        ans %= mod

    print(ans)

if __name__ == '__main__':
    main()

Fixed submission:
mod = int(1e9+7)
N = int(input())
A = list(map(int, input().split()))
ans = 0
for i in range(60):
    a = 0
    b = 0
    for j in range(N):
        if A[j] % 2:
            a += 1
        else:
            b += 1
        A[j] //= 2
    ans += a*b*pow(2, i, mod)
    ans %= mod
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
import sys
mod = int(1e9+7)
input=sys.stdin.readline
N = int(input())
A = list(map(int, input().split()))
#S[0]は使わない
S = [[0]*60 for _ in range(N)]

tmp = A[-1]
idx = 0
while tmp > 0:
    if tmp%2:
        S[-1][idx] += 1
    idx += 1
    tmp //= 2

for i in range(N-2, 0, -1):
    for j in range(60):
        S[i][j] = S[i+1][j]
    tmp = A[i]
    idx = 0
    while tmp > 0:
        if tmp % 2:
            S[i][idx] += 1
        idx += 1
        tmp //= 2

ans = 0
for i in range(N-1):
    tmp = A[i]
    idx = 0
    while tmp > 0:
        if tmp % 2:
            ans += ((N-1-i)-S[i+1][idx])*2**idx

        else:
            ans += S[i+1][idx]*2**idx

        idx += 1
        tmp //= 2

    for x in S[i+1][idx:]:
        ans += x*2**idx%mod
        idx += 1

    ans %= mod

print(ans)

Fixed submission:
mod = int(1e9+7)
N = int(input())
A = list(map(int, input().split()))
ans = 0
for i in range(60):
    a = 0
    b = 0
    for j in range(N):
        if A[j] % 2:
            a += 1
        else:
            b += 1
        A[j] //= 2
    ans += a*b*pow(2, i, mod)
    ans %= mod
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
import sys
mod = int(1e9+7)
input=sys.stdin.readline
N = int(input())
A = list(map(int, input().split()))
#S[0]は使わない
S = [[0]*60 for _ in range(N)]

tmp = A[-1]
idx = 0
while tmp > 0:
    if tmp%2:
        S[-1][idx] += 1
    idx += 1
    tmp //= 2

for i in range(N-2, 0, -1):
    for j in range(60):
        S[i][j] = S[i+1][j]
    tmp = A[i]
    idx = 0
    while tmp > 0:
        if tmp % 2:
            S[i][idx] += 1
        idx += 1
        tmp //= 2

ans = 0
for i in range(N-1):
    tmp = A[i]
    idx = 0
    while tmp > 0:
        if tmp % 2:
            ans += ((N-1-i)-S[i+1][idx])*2**idx

        else:
            ans += S[i+1][idx]*2**idx

        idx += 1
        tmp //= 2

    rest = S[i+1][idx:]
    for x in rest:
        ans += x*2**idx
        idx += 1

    ans %= mod

print(ans)

Fixed submission:
mod = int(1e9+7)
N = int(input())
A = list(map(int, input().split()))
ans = 0
for i in range(60):
    a = 0
    b = 0
    for j in range(N):
        if A[j] % 2:
            a += 1
        else:
            b += 1
        A[j] //= 2
    ans += a*b*pow(2, i, mod)
    ans %= mod
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
mod = int(1e9+7)
N = int(input())
A = list(map(int, input().split()))
#S[0]は使わない
S = [[0]*60 for _ in range(N)]

tmp = A[-1]
idx = 0
while tmp > 0:
    if tmp%2:
        S[-1][idx] += 1
    idx += 1
    tmp //= 2

for i in range(N-2, 0, -1):
    for j in range(60):
        S[i][j] = S[i+1][j]
    tmp = A[i]
    idx = 0
    while tmp > 0:
        if tmp % 2:
            S[i][idx] += 1
        idx += 1
        tmp //= 2

ans = 0
for i in range(N-1):
    tmp = A[i]
    idx = 0
    while tmp > 0:
        if tmp % 2:
            ans += ((N-1-i)-S[i+1][idx])*2**idx

        else:
            ans += S[i+1][idx]*2**idx

        idx += 1
        tmp //= 2

    rest = S[i+1][idx:]
    for x in rest:
        ans += x*2**idx
        idx += 1

    ans %= mod

print(ans)

Fixed submission:
mod = int(1e9+7)
N = int(input())
A = list(map(int, input().split()))
ans = 0
for i in range(60):
    a = 0
    b = 0
    for j in range(N):
        if A[j] % 2:
            a += 1
        else:
            b += 1
        A[j] //= 2
    ans += a*b*pow(2, i, mod)
    ans %= mod
print(ans)