Buggy python submission (verdict: Time Limit Exceeded):
M = 1000000007
def pow(k):
    ans = 1
    for _ in range(k):
        ans *= 2
        ans %= M
    return ans

def main():
    n = int(input())
    a = list(map(int, input().split()))
    bit_size = len(bin(max(a))[2:])
    for i in range(n):
        a[i] = bin(a[i])[2:].zfill(bit_size)

    sum = 0
    for i in range(bit_size):
        one = 0
        zero = 0
        for j in range(n):
            if a[j][i] == '1':
                one += 1
            else: 
                zero += 1
        sum += pow(bit_size - i - 1) * (one % M) * (zero % M)
        sum %= M
    print(sum)

if __name__ == '__main__':
    main()

Fixed submission:
M = 1000000007
def pow(k):
    ans = 1
    for _ in range(k):
        ans *= 2
        ans %= M
    return ans

def main():
    n = int(input())
    a = list(map(int, input().split()))
    bit_size = len(bin(max(a))[2:])
    for i in range(n):
        a[i] = bin(a[i])[2:].zfill(bit_size)

    sum = 0
    for i in range(bit_size):
        one = 0
        zero = 0
        for j in range(n):
            if a[j][i] == '1':
                one += 1
            else: 
                zero += 1
        sum += pow(bit_size - i - 1) * (one % M) * (zero % M)
        sum %= M
    print(sum)

if __name__ == '__main__':
    main()

Buggy python submission (verdict: Time Limit Exceeded):
M = 1000000007

def pow(k):
    ans = 1
    for _ in range(k):
        ans *= 2
        ans % M
    return ans

def main():
    n = int(input())
    a = list(map(int, input().split()))
    bit_size = len(bin(max(a))[2:])
    for i in range(n):
        a[i] = bin(a[i])[2:].zfill(bit_size)

    sum = 0
    for i in range(bit_size):
        one = 0
        zero = 0
        for j in range(n):
            if a[j][i] == '1':
                one += 1
            else: 
                zero += 1
        sum += pow(bit_size - i - 1) * (one % M) * (zero % M)
        sum %= M
    print(sum)

if __name__ == '__main__':
    main()



Fixed submission:
M = 1000000007
def pow(k):
    ans = 1
    for _ in range(k):
        ans *= 2
        ans %= M
    return ans

def main():
    n = int(input())
    a = list(map(int, input().split()))
    bit_size = len(bin(max(a))[2:])
    for i in range(n):
        a[i] = bin(a[i])[2:].zfill(bit_size)

    sum = 0
    for i in range(bit_size):
        one = 0
        zero = 0
        for j in range(n):
            if a[j][i] == '1':
                one += 1
            else: 
                zero += 1
        sum += pow(bit_size - i - 1) * (one % M) * (zero % M)
        sum %= M
    print(sum)

if __name__ == '__main__':
    main()

Buggy python submission (verdict: Time Limit Exceeded):
def main():
    M = 1000000007
    n = int(input())
    a = list(map(int, input().split()))
    bit_size = len(bin(max(a))[2:])
    for i in range(n):
        a[i] = bin(a[i])[2:].zfill(bit_size)
        
    sum = 0
    for i in range(bit_size):
        one = 0
        zero = 0
        for j in range(n):
            if a[j][i] == '1':
                one += 1
            else: 
                zero += 1
        sum += (2**(bit_size - i - 1) % M) * (one % M) * (zero % M)
        sum %= M
    print(sum)

if __name__ == '__main__':
    main()



Fixed submission:
M = 1000000007
def pow(k):
    ans = 1
    for _ in range(k):
        ans *= 2
        ans %= M
    return ans

def main():
    n = int(input())
    a = list(map(int, input().split()))
    bit_size = len(bin(max(a))[2:])
    for i in range(n):
        a[i] = bin(a[i])[2:].zfill(bit_size)

    sum = 0
    for i in range(bit_size):
        one = 0
        zero = 0
        for j in range(n):
            if a[j][i] == '1':
                one += 1
            else: 
                zero += 1
        sum += pow(bit_size - i - 1) * (one % M) * (zero % M)
        sum %= M
    print(sum)

if __name__ == '__main__':
    main()

Buggy python submission (verdict: Time Limit Exceeded):
def main():
    M = 1000000007
    n = int(input())
    a = list(map(int, input().split()))
    a.sort()
    bit_size = len(bin(a[-1])[2:])
    for i in range(n):
        a[i] = bin(a[i])[2:].zfill(bit_size)

    sum = 0
    for i in range(bit_size):
        one = 0
        zero = 0
        for j in range(n):
            if a[j][i] == '1':
                one += 1
            else: 
                zero += 1
        sum += (2**(bit_size - i - 1) % M) * (one % M) * (zero % M)
        sum %= M
    print(sum)

if __name__ == '__main__':
    main()

Fixed submission:
M = 1000000007
def pow(k):
    ans = 1
    for _ in range(k):
        ans *= 2
        ans %= M
    return ans

def main():
    n = int(input())
    a = list(map(int, input().split()))
    bit_size = len(bin(max(a))[2:])
    for i in range(n):
        a[i] = bin(a[i])[2:].zfill(bit_size)

    sum = 0
    for i in range(bit_size):
        one = 0
        zero = 0
        for j in range(n):
            if a[j][i] == '1':
                one += 1
            else: 
                zero += 1
        sum += pow(bit_size - i - 1) * (one % M) * (zero % M)
        sum %= M
    print(sum)

if __name__ == '__main__':
    main()

Buggy python submission (verdict: Time Limit Exceeded):
def main():
    M = 1000000007
    n = int(input())
    a = list(map(int, input().split()))
    a.sort()
    bit_size = len(bin(a[-1])[2:])
    for i in range(n):
        a[i] = bin(a[i])[2:].zfill(bit_size)

    sum = 0
    for i in range(bit_size):
        one = 0
        zero = 0
        for j in range(n):
            if a[j][i] == '1':
                one += 1
            else: 
                zero += 1
        sum += 2**(bit_size - i - 1) * one * zero
        sum %= M
    print(sum)

if __name__ == '__main__':
    main()



Fixed submission:
M = 1000000007
def pow(k):
    ans = 1
    for _ in range(k):
        ans *= 2
        ans %= M
    return ans

def main():
    n = int(input())
    a = list(map(int, input().split()))
    bit_size = len(bin(max(a))[2:])
    for i in range(n):
        a[i] = bin(a[i])[2:].zfill(bit_size)

    sum = 0
    for i in range(bit_size):
        one = 0
        zero = 0
        for j in range(n):
            if a[j][i] == '1':
                one += 1
            else: 
                zero += 1
        sum += pow(bit_size - i - 1) * (one % M) * (zero % M)
        sum %= M
    print(sum)

if __name__ == '__main__':
    main()