Problem: We have N integers. The i-th integer is A_i.  Find \sum_{i=1}^{N-1}\sum_{j=i+1}^{N} (A_i \mbox{ XOR } A_j), modulo (10^9+7).  What is \mbox{ XOR }?  The XOR of integers A and B, A \mbox{ XOR } B, is defined as follows:    * When A \mbox{ XOR } B is written in base two, the digit in the 2^k's place (k \geq 0) is 1 if either A or B, but not both, has 1 in the 2^k's place, and 0 otherwise.  For example, 3 \mbox{ XOR } 5 = 6. (In base two: 011 \mbox{ XOR } 101 = 110.)

Submission attempts (in order):
#!/usr/bin/env python3

mod = 10**9+7

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

max_digit = 61

count_0 = [0 for _ in range(max_digit)]
count_1 = [0 for _ in range(max_digit)]

for i in range(len(a)):
    num_str = bin(a[i])[2:]
    # print(num_str)
    for j in range(len(num_str)):
        # print(num_str[-j-1])
        if num_str[-j-1] == "1":
            count_1[-j-1] += 1


#     count_0[i] = n-count_1[i]

ans = 0
# count = 1

#     # tmp = count_0[-i-1]*count_1[-i-1]
#     tmp = count_1[-i-1]*(n-count_1[-i-1])
#     ans += tmp*count
#     count = (count*2) % mod
print(ans % mod)

#!/usr/bin/env python3

mod = 10**9+7

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

count_0 = [0 for _ in range(61)]
count_1 = [0 for _ in range(61)]

for i in range(len(a)):
    num_str = bin(a[i])[2:]
    # print(num_str)
    for j in range(len(num_str)):
        if num_str[-j-1] == "0":
            count_0[-j-1] += 1
        else:
            count_1[-j-1] += 1

# print(count_0)
# print(count_1)

ans = 0
count = 1
for i in range(61):
    tmp = count_0[-i-1]*count_1[-i-1]
    ans += tmp*count
    count = (count*2) % mod
print(ans % mod)

#!/usr/bin/env python3

# mod = 10**9+7

# n = int(input())
# a = list(map(int, input().split()))



# count_0 = [0 for _ in range(max_digit)]
# count_1 = [0 for _ in range(max_digit)]


#     num_str = bin(a[i])[2:]
#     # print(num_str)
#     for j in range(len(num_str)):
#         # print(num_str[-j-1])
#         if num_str[-j-1] == "1":
#             count_1[-j-1] += 1


# #     count_0[i] = n-count_1[i]

# ans = 0
# count = 1

#     # tmp = count_0[-i-1]*count_1[-i-1]
#     tmp = count_1[-i-1]*(n-count_1[-i-1])
#     ans += tmp*count
#     count = (count*2) % mod



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

mod = 10**9+7
max_digit = 61

ans = 0
m = 1
for _ in range(max_digit):
    bit = sum(x&m x in a)
    bit //= m
    non_bit = n - bit
    ans = (ans+bit*nonbit*m)%mod
    m <<= 1
print(ans)

#!/usr/bin/env python3

# mod = 10**9+7

# n = int(input())
# a = list(map(int, input().split()))



# count_0 = [0 for _ in range(max_digit)]
# count_1 = [0 for _ in range(max_digit)]


#     num_str = bin(a[i])[2:]
#     # print(num_str)
#     for j in range(len(num_str)):
#         # print(num_str[-j-1])
#         if num_str[-j-1] == "1":
#             count_1[-j-1] += 1


# #     count_0[i] = n-count_1[i]

# ans = 0
# count = 1

#     # tmp = count_0[-i-1]*count_1[-i-1]
#     tmp = count_1[-i-1]*(n-count_1[-i-1])
#     ans += tmp*count
#     count = (count*2) % mod



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

mod = 10**9+7
max_digit = 61

ans = 0
m = 1
for _ in range(max_digit):
    bit = sum(x&m for x in a)
    bit //= m
    non_bit = n - bit
    ans = (ans+bit*non_bit*m)%mod
    m <<= 1
print(ans)

Verdicts: Wrong Answer

Wrong Answer

Runtime Error

Accepted