Buggy python submission (verdict: Time Limit Exceeded):
def main():
    n = int(input())
    a = [int(i) for i in input().split()]
    mod = 10**9 + 7
    b = [0] * 60
    for ai in a:
        for k in range(ai.bit_length()):
            b[k] += ai & 1
            ai //= 2
    c = 0
    for k in range(60):
        c = (c + b[k] * (n - b[k]) * pow(2, k, mod)) % mod
    print(c)

if __name__ == '__main__':
    main()

Fixed submission:
def main():
    n = int(input())
    a = [int(i) for i in input().split()]
    k = max(a).bit_length()
    mod = 10**9 + 7
    c = 0
    for kk in range(k):
        h, l = 0, 0
        for ai in a:
            if ai // 2**kk % 2:
                h += 1
            else:
                l += 1
        kc = h * l * pow(2, kk, mod) % mod
        c = (c + kc) % mod
    print(c)

if __name__ == '__main__':
    main()

Buggy python submission (verdict: Time Limit Exceeded):
def main():
    n = int(input())
    a = [int(i) for i in input().split()]
    mod = 10**9 + 7
    b = [0] * 60
    for ai in a:
        for k in range(60):
            if ai == 0:
                break
            b[k] += ai % 2
            ai //= 2
    c = 0
    for k in range(60):
        c = (c + b[k] * (n - b[k]) * pow(2, k, mod)) % mod
    print(c)

if __name__ == '__main__':
    main()

Fixed submission:
def main():
    n = int(input())
    a = [int(i) for i in input().split()]
    k = max(a).bit_length()
    mod = 10**9 + 7
    c = 0
    for kk in range(k):
        h, l = 0, 0
        for ai in a:
            if ai // 2**kk % 2:
                h += 1
            else:
                l += 1
        kc = h * l * pow(2, kk, mod) % mod
        c = (c + kc) % mod
    print(c)

if __name__ == '__main__':
    main()

Buggy python submission (verdict: Time Limit Exceeded):
def main():
    n = int(input())
    a = [int(i) for i in input().split()]
    k = max(a).bit_length()
    mod = 10**9 + 7
    bk = [[0] * n for _ in range(k)]
    for kk in range(k):
        for i in range(n):
            bk[kk][i] = a[i] // 2**kk % 2
    bc = [[bk[kk][-1]] * n for kk in range(k)]
    for kk in range(k):
        for i in range(n - 1, 0, -1):
            bc[kk][i - 1] = bc[kk][i] + bk[kk][i - 1]
    c = 0
    for kk in range(k):
        kc = 0
        for i in range(n - 1):
            if bk[kk][i] == 0:
                kc = (kc + bc[kk][i + 1]) % mod
            else:
                kc = (kc + n - 1 - i - bc[kk][i + 1]) % mod
        kc = kc * pow(2, kk, mod) % mod
        c = (c + kc) % mod
    print(c)

if __name__ == '__main__':
    main()

Fixed submission:
def main():
    n = int(input())
    a = [int(i) for i in input().split()]
    k = max(a).bit_length()
    mod = 10**9 + 7
    c = 0
    for kk in range(k):
        h, l = 0, 0
        for ai in a:
            if ai // 2**kk % 2:
                h += 1
            else:
                l += 1
        kc = h * l * pow(2, kk, mod) % mod
        c = (c + kc) % mod
    print(c)

if __name__ == '__main__':
    main()

Buggy python submission (verdict: Time Limit Exceeded):
def main():
    n = int(input())
    a = [int(i) for i in input().split()]
    k = max(a).bit_length()
    mod = 10**9 + 7
    c = 0
    for kk in range(k):
        h, l = 0, 0
        for ai in a:
            if ai // 2**kk % 2:
                h += 1
            else:
                l += 1
        kc = h * l * pow(2, kk, mod) % mod
        c = (c + kc) % mod
    print(c)

if __name__ == '__main__':
    main()

Fixed submission:
def main():
    n = int(input())
    a = [int(i) for i in input().split()]
    k = max(a).bit_length()
    mod = 10**9 + 7
    c = 0
    for kk in range(k):
        h, l = 0, 0
        for ai in a:
            if ai // 2**kk % 2:
                h += 1
            else:
                l += 1
        kc = h * l * pow(2, kk, mod) % mod
        c = (c + kc) % mod
    print(c)

if __name__ == '__main__':
    main()

Buggy python submission (verdict: Time Limit Exceeded):
def main():
    n = int(input())
    a = [int(i) for i in input().split()]
    k = max(a).bit_length()
    mod = 10**9 + 7
    bk = [[0] * n for _ in range(k)]
    for kk in range(k):
        for i in range(n):
            bk[kk][i] = a[i] // 2**kk % 2
    bc = [[bk[kk][-1]] * n for kk in range(k)]
    for kk in range(k):
        for i in range(n - 1, 0, -1):
            bc[kk][i - 1] = bc[kk][i] + bk[kk][i - 1]
    c = 0
    for kk in range(k):
        kc = 0
        for i in range(n - 1):
            if bk[kk][i] == 0:
                kc = (kc + bc[kk][i + 1]) % mod
            else:
                kc = (kc + n - 1 - i - bc[kk][i + 1]) % mod
        kc = kc * pow(2, kk, mod) % mod
        c = (c + kc) % mod
    print(c)

if __name__ == '__main__':
    main()

Fixed submission:
def main():
    n = int(input())
    a = [int(i) for i in input().split()]
    k = max(a).bit_length()
    mod = 10**9 + 7
    c = 0
    for kk in range(k):
        h, l = 0, 0
        for ai in a:
            if ai // 2**kk % 2:
                h += 1
            else:
                l += 1
        kc = h * l * pow(2, kk, mod) % mod
        c = (c + kc) % mod
    print(c)

if __name__ == '__main__':
    main()

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = sorted([int(i) for i in input().split()], reverse=True)
mod = 10**9 + 7
ans = 0
for j in range(len(bin(a[0])) - 2):
  k = [0, 0]
  for i in a:
    k[i >> j & 1] += 1
  ans = (ans + (k[0] * k[1]) * 2**j) % mod
print(ans)

Fixed submission:
def main():
    n = int(input())
    a = [int(i) for i in input().split()]
    k = max(a).bit_length()
    mod = 10**9 + 7
    c = 0
    for kk in range(k):
        h, l = 0, 0
        for ai in a:
            if ai // 2**kk % 2:
                h += 1
            else:
                l += 1
        kc = h * l * pow(2, kk, mod) % mod
        c = (c + kc) % mod
    print(c)

if __name__ == '__main__':
    main()