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):



N = int(input())
A = list(map(int, input().split()))

for i in range(N): A[i] = format(A[i], "059b") 

mod = 10**9+7

sum = 0
for i in range(1,61):
    count0 = 0
    count1 = 0
    for j in range(N):
        if A[j][-i] == "0": 
            count0 += 1
        else:
            count1 += 1 
    sum += (count0 * count1) << (i-1) 
print(sum%mod)





N = int(input())
A = list(map(int, input().split()))
mod = 10**9+7

for i in range(N): A[i] = format(A[i], "

sum = 0
c0 = [0]*60
c1 = [0]*60
for i in range(N):
    for j in range(60):
        if A[i][-(j+1)] == "0": 
            c0[j] += 1
        elif A[i][-(j+1)] == "1":
            c1[j] += 1
        else:
            break

for i in range(60):
    if c1[i] > 0:
        c0[i] = N - c1[i] 
    sum += (c0[i] * c1[i]) << i

print(sum%mod)


# N = int(input())
# A = list(map(int, input().split()))



# mod = 10**9+7



#     count0 = 0
#     count1 = 0
#     for j in range(N):
#         if A[j][-i] == "0": 
#             count0 += 1
#         else:
#             count1 += 1 

# print(sum%mod)





N = int(input())
A = list(map(int, input().split()))
mod = 10**9+7

for i in range(N): A[i] = format(A[i], "

sum = 0
c0 = [0]*60
c1 = [0]*60
for i in range(N):
    #print(A[i])
    for j in range(60):
        if A[i][-(j+1)] == "0": 
            c0[j] += 1
        elif A[i][-(j+1)] == "1":
            c1[j] += 1
        else:
            break

#print(c0[0], c0[1], c0[2], c1[0], c1[1], c1[2])
for i in range(60):
    if c1[i] > 0:
        c0[i] = N - c1[i] 
    sum += (c0[i] * c1[i]) << i

print(sum)


# N = int(input())
# A = list(map(int, input().split()))



# mod = 10**9+7



#     count0 = 0
#     count1 = 0
#     for j in range(N):
#         if A[j][-i] == "0": 
#             count0 += 1
#         else:
#             count1 += 1 

# print(sum%mod)


N = int(input())
A = list(map(int, input().split()))
mod = 10**9+7
 
for i in range(N): A[i] = format(A[i], "
#print(A)

sum = 0
c0 = [0]*60
c1 = [0]*60
for i in range(N):
    for j in range(60):
        if A[i][-(j+1)] == "0": 
            c0[j] += 1
        elif A[i][-(j+1)] == "1":
            c1[j] += 1
        else:
            break
 
for i in range(60):
    if c1[i] > 0:
        c0[i] = N - c1[i] 
    sum += (c0[i] * c1[i]) << i
    sum %= mod
 
print(sum%mod)

N = int(input())
A = list(map(int, input().split()))
mod = 10**9+7
 
for i in range(N): A[i] = format(A[i], "
#print(A)

sum = 0
c1 = [0]*60
for i in range(N):
    for j in range(60):
        #print(i,j,A[i][-(j+1)])
        if A[i][-(j+1)] == "0": 
            continue
        elif A[i][-(j+1)] == "1":
            c1[j] += 1
        else:
            break

#print("c1 =",c1)
for i in range(60):
    print
    sum += (c1[i] * (N-c1[i])) << i
    sum %= mod
 
print(sum%mod)

N = int(input())
A = list(map(int, input().split()))
mod = 10**9+7
xorsum = 0
for i in range(60):
  c1 = sum([1 for a in A if (a >> i) & 1]) #
  xorsum += (c1*(N-c1)*(1<<i))
  xorsum = xorsum%mod
print(xorsum%mod)


Verdicts: Runtime Error

Time Limit Exceeded

Wrong Answer

Time Limit Exceeded

Time Limit Exceeded

Accepted