Problem:


Score : 400 points

Problem Statement

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

Constraints

2 \leq N \leq 3 \times 10^5

0 \leq A_i < 2^{60}

All values in input are integers.

Input

Input is given from Standard Input in the following format:

N
A_1 A_2 ... A_N

Output

Print the value \sum_{i=1}^{N-1}\sum_{j=i+1}^{N} (A_i \mbox{ XOR } A_j), modulo (10^9+7).

Sample Input 1

3
1 2 3

Sample Output 1

6

We have (1\mbox{ XOR } 2)+(1\mbox{ XOR } 3)+(2\mbox{ XOR } 3)=3+2+1=6.

Sample Input 2

10
3 1 4 1 5 9 2 6 5 3

Sample Output 2

237

Sample Input 3

10
3 14 159 2653 58979 323846 2643383 27950288 419716939 9375105820

Sample Output 3

103715602

Print the sum modulo (10^9+7).



Sample input:
3
1 2 3


Sample output:
6

Submission status: Wrong Answer

Solution code:
N = int(input())
lst = [int(i) for i in input().split()]

sum = 0
for i in range(N):
    for j in range(i+1, N):
        sum += (lst[i] ^ lst[j]) 

print(int(sum % (1e9+7)))

Submission status: Wrong Answer

Solution code:
n = int(input())
lis = list(int(i) for i in input().split())  
sum = 0
for i in range(len(lis)):
  for j in range(len(lis)):
    if i != j:
	    sum += i ^ j
print(int(sum/2))        
#print(int(sum/2) % (100000000 + 7))

Submission status: Wrong Answer

Solution code:
N=int(input())
arr=list(map(int,input().split()))
outs=0
MODS=1e9+7
for i in range(60):
  zer=0
  one=0
  ids=0
  for j in range(N):
    if arr[j]%2==0:
      zer+=1
    else:
      one+=1
    arr[j]=int(arr[j]/2)
  ids=int((((one*zer)%MODS)*(1<<i))%MODS)
  outs+=ids
  outs%=MODS
  outs=int(outs)
print(outs)

Submission status: Wrong Answer

Solution code:

def sumXOR( arr, n): 
	sum = 0
	for i in range(0, 60): 
		zc = 0
		oc = 0
		idsum = 0
		for j in range(0, n): 
			if (arr[j] % 2 == 0): 
				zc = zc + 1
			else: 
				oc = oc + 1
			arr[j] = int(arr[j] / 2) 
		idsum = oc * zc * (1 << i) 
		sum = (sum + idsum)%(10**9+7); 
	return sum
sum = 0
n=int(input())
arr=list(map(int,input().split()))
sum = sumXOR(arr, n); 
print (sum%(10**9+7))

Submission status: Wrong Answer

Solution code:
# An efficient Python3 program to compute 
# sum of bitwise OR of all pair 

# Returns sum of bitwise OR 
# of all pairs 
def sumXOR( arr, n): 
	
	sum = 0
	for i in range(0, 32): 

		# Count of zeros and ones 
		zc = 0
		oc = 0
		
		# Individual sum at each bit position 
		idsum = 0
		for j in range(0, n): 
			if (arr[j] % 2 == 0): 
				zc = zc + 1
				
			else: 
				oc = oc + 1
			arr[j] = int(arr[j] / 2) 
		
		
		# calculating individual bit sum 
		idsum = oc * zc * (1 << i) 

		# final sum	 
		sum = sum + idsum; 
	
	return sum



# driver function 
sum = 0
n=int(input())
arr=list(map(int,input().split()))
 
sum = sumXOR(arr, n); 
print (sum)

Submission status: Wrong Answer

Solution code:
N = input()

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


ans = 0

for i in range(len(A)):
    for j in range(i+1, len(A)):
       ans += A[i]^A[j]

print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
A = [int(a) for a in input().split()]
ans = part = 0
for i in range(N-1):
    for j in range(i,N):
        part = A[i]^A[j]
        ans += (part)%(10e9+7)
print(int(ans))

Submission status: Wrong Answer

Solution code:
N = int(input())
A = list(map(int, input().split()))
ans = 0
for i in range(N-1):
  for j in range(i+1,N):
    ans += i ^ j
print(ans % 1000000007)

Submission status: Wrong Answer

Solution code:
n=int(input())
l=list(map(int,input().split()))
x=0
for i in range(n):
  for j in range(i+1,n):
    x+=(l[i]^l[j])%10**9+7
print(x%(10**9+7))

Submission status: Wrong Answer

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

sum = 0

for i in range(n):
    for j in range(i + 1, n):
        sum += a[i]^a[j]

print(int(sum % (1E9 + 7)))

Submission status: Wrong Answer

Solution code:
n = int(input())
a = list(map(int, input().split()))
mod = 10**9 + 7

rest = 0
for i in range(n-1):
  for j in range(i+1, n):
    rest = (rest + (a[i] & a[j])) % mod
    
print(rest)

Submission status: Wrong Answer

Solution code:
n = int(input())
lis = list(int(i) for i in input().split())  
sum = 0
for i in range(len(lis)):
  for j in range(len(lis)):
    if i != j:
	    sum += i ^ j
        
print(int(sum/2) % (100000000 + 7))

Submission status: Wrong Answer

Solution code:
import sys
import numpy as np

MOD = 10 ** 9 + 7

n, *a = map(int, sys.stdin.read().split())
a = np.array(a, dtype=np.int64)

def main():
    s = 0
    for i in range(n-1):
        s += np.sum(a[i] ^ a[i+1:]) % MOD
        s %= MOD
    return s

if __name__ == '__main__':
    ans = main()
    print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
A = [int(val) for val in input().split(' ')]
sum_ = 0
for i in range(N):
    for j in range(i, N):
        sum_ += A[i] ^ A[j]
print(sum_ * 2)

Submission status: Wrong Answer

Solution code:
MOD=10**9+7 
def sumXOR( arr, n): 
	sum = 0
	for i in range(0, 75): 
		zc = 0
		oc = 0
		idsum = 0
		for j in range(0, n): 
			if (arr[j] % 2 == 0): 
				zc = zc + 1
			else: 
				oc = oc + 1
			arr[j] = int(arr[j] / 2) 
		idsum = oc * zc * (1 << i) 
		sum = sum + idsum; 
		sum%=MOD 
	return sum
sum = 0
n=int(input())
arr=[int(i) for i in input().split()]
MOD=10**9+7 
print(sumXOR(arr,n)%MOD)

Submission status: Wrong Answer

Solution code:

def sumXOR( arr, n): 
	sum = 0
	for i in range(0, 62): 
		zc = 0
		oc = 0
		idsum = 0
		for j in range(0, n): 
			if (arr[j] % 2 == 0): 
				zc = zc + 1
			else: 
				oc = oc + 1
			arr[j] = int(arr[j] / 2) 
		idsum = oc * zc * (1 << i) 
		sum = sum + idsum; 
	return sum
sum = 0
n=int(input())
arr=[int(i) for i in input().split()]
MOD=10**9+7 
print(sumXOR(arr,n)%MOD)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
a = list(map(int, input().split()))
def f(x):
    b = '0' * 64 + bin(x)[2:]
    b = b[::-1]
    b = b[:64]
    return list(map(int, list(b)))

bit_count = [0] * 64
for i in a:
    b = f(i)
    for j in range(64):
        bit_count[j] += b[j]

ans = 0
for i in range(64):
    bc = bit_count[i]
    ans += (2**i) * bc * (n - bc)
    ans %= 10**9 + 7

print(ans)

Submission status: Time Limit Exceeded

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

mod = 10**9+7

cnt = [0]*60
bt = [0]*60

for a in A:
    for i in range(60):
        cnt[i] += (a>>i)&1

for i in range(60):
    x = cnt[i]
    bt[i] += x*(N-x)%mod

ans = 0
for i in range(60):
    ans += bt[i]*2**i
    ans %= mod

print(ans)

Submission status: Time Limit Exceeded

Solution code:
from sys import stdin, stdout # only need for big input

MOD = int(1e9+7)

def pow_mod(a , p , m):
    if p < 2:
        ans = 1
        for _ in range(p):
            ans *= a
            if ans >= m:
                ans = ans % m
        return ans
    ans = pow_mod(a , p //2 , m)
    ans = ans * ans

    if ans >= m :
        ans = ans % m
    if p % 2 :
        ans = ans * a 
        if ans >= m :
            ans = ans % m 
    return ans

    

def solve():
    n = int(input())
    A = [int(inp) for inp in input().split()]
    count_1 = [0] * 61 
    pow_2 = [pow_mod(2, i, MOD) for i in range(61)]
    for a in A :
        x = a
        while x :
           for i in range(61):
               if x & 1 :
                   count_1[i] += 1
               x = x >> 1
    # print(count_1)
    # print(pow_2)
    sum = 0
    # print(len(pow_2))
    # print(len(count_1))
    # for a in A:
    #     x = a
    #     while x :
    #         for i in range(61):
    #             # print(i)
    #             if x & 1:
    #                 sum += pow_2[i] * (n - count_1[i])
    #             else:
    #                 sum += pow_2[i] * (count_1[i])

    #             if sum >= MOD:
    #                 sum = sum % MOD
    #             x = x >> 1 
    for i in range(61):
        sum += pow_2[i] * count_1[i] * ( n - count_1[i])
        if sum >= MOD:
            sum = sum % MOD
    # print(sum)
    #sum = (sum * pow_mod(2, MOD - 2, MOD) ) % MOD
    print(sum)


def main():
    solve()


if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
A = list(map(int, input().split()))
B = [[0 for i in range(N)]for j in range(60)]
M = 1000000007
ans = [0 for i in range(60)]
sumB = [[0 for i in range(N)]for j in range(60)]
for j in range(N):
  for i in range(60):
    B[i][j] = A[j]>>i & 1
    sumB[i][j] = A[j]>>i & 1
    if j > 0:
      sumB[i][j] += sumB[i][j-1]
for i in range(1, N):
  for j in range(60):
    if B[j][-i]==0:
      ans[j] += sumB[j][-(i+1)]
    else:
      ans[j] += N-i-sumB[j][-(i+1)]
a = 0
for i in range(60):
  a += (ans[i]*pow(2, i, M))%M
  a %= M
print(a)

Submission status: Time Limit Exceeded

Solution code:
### ----------------
### ここから
### ----------------

import sys
from io import StringIO
import unittest

def resolve():
    readline=sys.stdin.readline
    mod=10**9+7
    n=int(readline())
    arr=list(map(int, readline().rstrip().split()))
    ans = 0
    x = 1
    for i in range(60):
        c = 0
        for j in range(n):
            c += (arr[j]>>i)&1
        ans += (c * (n-c)) * x
        ans %= mod
        x = (x*2)%mod
    print(ans)
    return

if 'doTest' not in globals():
    resolve()
    sys.exit()

### ----------------
### ここまで 
### ----------------

Submission status: Time Limit Exceeded

Solution code:
### ----------------
### ここから
### ----------------

import sys
from io import StringIO
import unittest

def resolve():
    readline=sys.stdin.readline
    mod=10**9+7
    n=int(readline())
    arr=list(map(int, readline().rstrip().split()))
    cnt=[0]*60
    for i in range(n):
        b = bin(arr[i])
        j = -1
        while b[j]!="b":
            if b[j]=="1":
                k=j*-1 -1
                cnt[k]+=1
            j-=1

    ans=[0]*60
    answer = 0
    for i in range(60):
        ans[i]=(cnt[i] * (n-cnt[i]))%mod
    x=1
    for i in range(60):
        answer += ans[i]*x
        answer %= mod
        x*=2
        x%=mod
    print(answer)
    return

if 'doTest' not in globals():
    resolve()
    sys.exit()

### ----------------
### ここまで 
### ----------------

Submission status: Time Limit Exceeded

Solution code:
### ----------------
### ここから
### ----------------

import sys
from io import StringIO
import unittest

def resolve():
    readline=sys.stdin.readline
    mod=10**9+7
    n=int(readline())
    arr=list(map(int, readline().rstrip().split()))
    cnt=[0]*60
    for i in range(n):
        b = bin(arr[i])
        j = -1
        while b[j]!="b":
            if b[j]=="1":
                k=j*-1 -1
                cnt[k]+=1
            j-=1

    ans=[0]*60
    answer = 0
    for i in range(60):
        ans[i]=cnt[i] * (n-cnt[i])
    x=1
    for i in range(60):
        answer += ans[i]*x
        answer %= mod
        x*=2
        x%=mod
    print(answer)
    return

if 'doTest' not in globals():
    resolve()
    sys.exit()

### ----------------
### ここまで 
### ----------------

Submission status: Time Limit Exceeded

Solution code:
### ----------------
### ここから
### ----------------

import sys
from io import StringIO
import unittest

def resolve():
    readline=sys.stdin.readline
    mod=10**9+7
    n=int(readline())
    arr=list(map(int, readline().rstrip().split()))
    cnt=[0]*60
    for i in range(n):
        b = bin(arr[i])
        lenb = len(b)
        for j in range(2,lenb):
            if int(b[lenb+1-j])==1:
                cnt[j-2]+=1
    ans=[0]*60
    answer = 0
    for i in range(60):
        ans[i]=cnt[i] * (n-cnt[i])
    x=1
    for i in range(60):
        answer += ans[i]*x
        answer %= mod
        x*=2
        x%=mod
    print(answer)
    return

if 'doTest' not in globals():
    resolve()
    sys.exit()

### ----------------
### ここまで 
### ----------------

Submission status: Time Limit Exceeded

Solution code:
### ----------------
### ここから
### ----------------

import sys
from io import StringIO
import unittest

def resolve():
    readline=sys.stdin.readline
    mod=10**9+7
    n=int(readline())
    arr=list(map(int, readline().rstrip().split()))
    binArr = [[False for i in range(60)] for j in range(n)]
    cnt=[0]*60
    for i in range(n):
        b = bin(arr[i])
        lenb = len(b)
        for j in range(2,lenb):
            if int(b[lenb+1-j])==1:
                binArr[i][j-2] = True
                cnt[j-2]+=1
    ans=[0]*60
    answer = 0
    for i in range(n):
        for j in range(60):
            # 1: cnt[j]
            # 0: n-cnt[j]
            cnt[j]-=binArr[i][j]
            if binArr[i][j] == False:
                ans[j] += cnt[j]
            else:
                ans[j] += (n-cnt[j]-i-1)
    x=1
    for i in range(60):
        answer += ans[i]*x
        answer %= mod
        x*=2
        x%=mod
    print(answer)
    return

if 'doTest' not in globals():
    resolve()
    sys.exit()

### ----------------
### ここまで 
### ----------------

Submission status: Time Limit Exceeded

Solution code:
### ----------------
### ここから
### ----------------

import sys
from io import StringIO
import unittest

def resolve():
    readline=sys.stdin.readline
    mod=10**9+7
    n=int(readline())
    arr=list(map(int, readline().rstrip().split()))
    binArr = [[False for i in range(60)] for j in range(n)]
    cnt=[0]*60
    for i in range(n):
        b = bin(arr[i])[2:]
        lenb = len(b)
        for j in range(lenb):
            if int(b[lenb-1-j])==1:
                binArr[i][j] = True
                cnt[j]+=1
    ans=[0]*60
    answer = 0
    for i in range(n):
        for j in range(60):
            # 1: cnt[j]
            # 0: n-cnt[j]
            cnt[j]-=binArr[i][j]
            if binArr[i][j] == False:
                ans[j] += cnt[j]
            else:
                ans[j] += (n-cnt[j]-i-1)
    x=1
    for i in range(60):
        answer += ans[i]*x
        answer %= mod
        x*=2
        x%=mod
    print(answer)
    return

if 'doTest' not in globals():
    resolve()
    sys.exit()

### ----------------
### ここまで 
### ----------------

Submission status: Time Limit Exceeded

Solution code:
### ----------------
### ここから
### ----------------

import sys
from io import StringIO
import unittest

def resolve():
    readline=sys.stdin.readline
    mod=10**9+7
    n=int(readline())
    arr=list(map(int, readline().rstrip().split()))
    binArr = [[0 for i in range(60)] for j in range(n)]
    cnt=[0]*60
    for i in range(n):
        b = bin(arr[i])[2:]
        lenb = len(b)
        for j in range(lenb):
            binArr[i][j] = int(b[lenb-1-j])
            cnt[j]+=binArr[i][j]
    ans=[0]*60
    answer = 0
    for i in range(n):
        for j in range(60):
            # 1: cnt[j]
            # 0: n-cnt[j]
            cnt[j]-=binArr[i][j]
            if binArr[i][j] == 0:
                ans[j] += cnt[j]
            else:
                ans[j] += (n-cnt[j]-i-1)
    x=1
    for i in range(60):
        answer += ans[i]*x
        answer %= mod
        x*=2
        x%=mod
    print(answer)
    return

if 'doTest' not in globals():
    resolve()
    sys.exit()

### ----------------
### ここまで 
### ----------------

Submission status: Time Limit Exceeded

Solution code:
### ----------------
### ここから
### ----------------

import sys
from io import StringIO
import unittest

def resolve():
    readline=sys.stdin.readline
    mod=10**9+7
    n=int(readline())
    arr=list(map(int, readline().rstrip().split()))
    binArr = [[0 for i in range(60)] for j in range(n)]
    cnt=[0]*60
    for i in range(n):
        b = bin(arr[i])[2:]
        lenb = len(b)
        for j in range(lenb):
            binArr[i][j] = int(b[lenb-1-j])
            cnt[j]+=binArr[i][j]
    ans=[0]*60
    answer = 0
    for i in range(n):
        for j in range(60):
            # 1: cnt[j]
            # 0: n-cnt[j]
            cnt[j]-=binArr[i][j]
            if binArr[i][j] == 0:
                ans[j] += cnt[j]
            else:
                ans[j] += (n-cnt[j]-i-1)
    x=1
    for i in range(60):
        answer += ans[i]*x
        answer %= mod
        x*=2
    print(answer)
    return

if 'doTest' not in globals():
    resolve()
    sys.exit()

### ----------------
### ここまで 
### ----------------

Submission status: Time Limit Exceeded

Solution code:
### ----------------
### ここから
### ----------------

import sys
from io import StringIO
import unittest

def resolve():
    readline=sys.stdin.readline
    mod=10**9+7
    n=int(readline())
    arr=list(map(int, readline().rstrip().split()))
    ans=0
    for i in range(n-1):
        for j in range(i+1,n):
            ans+=arr[i]^arr[j]
            ans%=mod
    print(ans)
    return

if 'doTest' not in globals():
    resolve()
    sys.exit()

### ----------------
### ここまで 
### ----------------

Submission status: Time Limit Exceeded

Solution code:
N, *A = map(int, open(0).read().split())
MOD = 1_000_000_007
ans = 0
for i in range(61):
    p, q, = 0, 0
    for a in A:
        if a >> i & 1:
            p += 1
        else:
            q += 1
    ans += pow(2, i, MOD) * p * q
    ans %= MOD
print(ans)

Submission status: Time Limit Exceeded

Solution code:
N, *A = map(int, open(0).read().split())
MOD = 1_000_000_007
ans = 0
for i in range(64):
    p, q, = 0, 0
    for a in A:
        if a >> i & 1:
            p += 1
        else:
            q += 1
    ans += pow(2, i, MOD) * p * q
    ans %= MOD
print(ans)

Submission status: Time Limit Exceeded

Solution code:
def main():
    n = int(input())
    A = sorted(map(int, input().split()), reverse=True)
    ans = 0
    mod = 10 ** 9 + 7
    m=A[0]
    for i in range(61):
        cnt0 = cnt1 = 0
        if m < 2 ** i:
            break
        for j, a in enumerate(A):
            if a < 2 ** i:
                cnt0 += n - j
                break
            if (a >> i) & 1:
                cnt1 += 1
            else:
                cnt0 += 1
        ans += (((2 ** i) % mod) * ((cnt1 * cnt0) % mod)) % mod
        ans %= mod

    print(ans)

if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
A = sorted(map(int, input().split()), reverse=True)
ans = 0
mod = 10 ** 9 + 7
m=A[0]
for i in range(61):
    cnt0 = cnt1 = 0
    if m < 2 ** i:
        break
    for j, a in enumerate(A):
        if a < 2 ** i:
            cnt0 += n - j
            break
        if (a >> i) & 1:
            cnt1 += 1
        else:
            cnt0 += 1
    ans += (((2 ** i) % mod) * ((cnt1 * cnt0) % mod)) % mod
    ans %= mod

print(ans)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
A = sorted(map(int, input().split()), reverse=True)
ans = 0
mod = 10 ** 9 + 7
for i in range(61):
    cnt0 = cnt1 = 0
    for j, a in enumerate(A):
        if a < 2 ** i:
            cnt0 += n - j
            break
        if (a >> i) & 1:
            cnt1 += 1
        else:
            cnt0 += 1
    ans += (((2 ** i) % mod) * ((cnt1 * cnt0) % mod)) % mod
    ans %= mod

print(ans)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
A = sorted(map(int, input().split()), reverse=True)
ans = 0
mod = 10 ** 9 + 7
m = A[0]
for i in range(61):
    cnt0 = cnt1 = 0
    if m < 2 ** i:
        break
    for a in A:
        if (a >> i) & 1:
            cnt1 += 1
        else:
            cnt0 += 1
    ans += (((2 ** i) % mod) * ((cnt1 * cnt0) % mod)) % mod
    ans %= mod

print(ans)

Submission status: Time Limit Exceeded

Solution code:
# coding: utf-8
import math
#n, k, s = map(int,input().split())
n = int(input())
A = list(map(int,input().split()))
ans = 0
MOD=10**9+7
for i in range(n-1):
    for j in range(i+1, n):
        ans += A[i] ^ A[j]
        ans %= MOD
print(ans)

Submission status: Time Limit Exceeded

Solution code:
n, *a = map(int, open(0).read().split())
# すべての組み合わせ
# あるビットについて、そのビットが立つ回数
mod = 10 ** 9 + 7
ans = 0
for i in range(60):
    cnt = 0
    for j in range(n):
        cnt += a[j] >> i & 1
    ans = (ans + (1 << i) * cnt * (n - cnt) % mod) % mod
print(ans)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
al = list(map(int, input().split()))

ans = 0
for i in range(n-1):
    for j in range(i+1, n):
        ans += al[i]^al[j]

print(ans%(10**9+7))

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
A = list(map(int, input().split()))
mod = 10**9+7
D = {}
for a in A:
    bit = bin(a)[2:][::-1]
    for i in range(len(bit)):
        if bit[i] == '1':
            if i not in D:
                D[i] = 1
            else:
                D[i] += 1

ans = 0
for k, v in D.items():
    ans += (N-v)*v*2**k % mod
    ans = ans % mod

print(ans)

Submission status: Time Limit Exceeded

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

mod = 10**9+7

table = [0 for i in range(60)]
for i in a:
    for t in range(60):
        if i&1:
            table[t] += 1
        i >>= 1

ans = 0
for j, s in enumerate(table):
    ans += s*(n-s)*2**j
    ans %= mod
print(ans)

# -- | 01 | 10 | 11
# 01 | 00 | 11 | 10
# 10 | 11 | 00 | 01
# 11 | 10 | 01 | 00
# 12

# --- | 001 | 100 | 111
# 001 | 000 | 101 | 110
# 100 | 101 | 000 | 011
# 111 | 110 | 011 | 000
# 28

Submission status: Time Limit Exceeded

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

mod = 10**9+7

table = [0 for i in range(60)]
for i in a:
    for t in range(60):
        if i&1:
            table[t] += 1
        i >>= 1

ans = 0
for i in a:
    for j, s in enumerate(table):
        if i&1:
            ans += (n-s)*2**j
            ans %= 2*mod
        else:
            ans += s*2**j
            ans %= 2*mod
        i >>= 1
print(ans//2)

# -- | 01 | 10 | 11
# 01 | 00 | 11 | 10
# 10 | 11 | 00 | 01
# 11 | 10 | 01 | 00
# 12

# --- | 001 | 100 | 111
# 001 | 000 | 101 | 110
# 100 | 101 | 000 | 011
# 111 | 110 | 011 | 000
# 28

Submission status: Time Limit Exceeded

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

mod = 10 ** 9 + 7
ans = 0
for i in range(60):
    ones = 0
    for a in A:
        # 数列Aの全要素の(二進法表記の)i桁目の１の数を集計する
        if a & (1 << i):
            ones += 1
    # Aの要素から任意の2つを選んで排他的論理和をとってできた数列をBとすると、
    # 数列Bの全要素のi桁目の合計は、(Aのi桁目の１の数)*(0の数)となる
    # 選んだ２つのAの要素が(0,1)の組み合わせになっている場合(XOR)だけに、Bの桁を構成する要素になるため
    ans = (ans + ones * (N - ones) * (1 << i)) % mod

print(ans)

Submission status: Time Limit Exceeded

Solution code:
# coding: utf-8
import sys
#from operator import itemgetter
sysread = sys.stdin.buffer.readline
read = sys.stdin.buffer.read
#from heapq import heappop, heappush
#from collections import defaultdict
sys.setrecursionlimit(10**7)
#import math
#from itertools import product, accumulate, combinations, product
#import bisect
#import numpy as np
#from copy import deepcopy
#from collections import deque
#from decimal import Decimal
#from numba import jit

INF = 1 << 50
EPS = 1e-8
mod = 10 ** 9 + 7

def mapline(t = int):
    return map(t, sysread().split())
def mapread(t = int):
    return map(t, read().split())

def generate_inv(n,mod):
    """
    逆元行列
    n >= 2
    Note: mod must bwe a prime number
    """
    ret = [0, 1]
    for i in range(2,n+1):
        next = -ret[mod%i] * (mod // i)
        next %= mod
        ret.append(next)
    return ret

def run():
    N, *A = mapread()
    maxA = max(A)
    L = maxA.bit_length()
    subs = [0] * L
    for k in range(L):
        sum = 0
        for a in A:
            if (a >> k) & 1:
                sum += 1 << k
            sum %= mod
        subs[k] = sum

    sumA = 0
    for a in A:
        sumA += a
        sumA %= mod
    ret = 0
    ret += (sumA * N) % mod
    ret += (sumA * N) % mod

    sub_sum = 0
    for a in A:
        sums = 0
        for k in range(L):
            if (a >> k) & 1:
                sums += subs[k] * 2
                sums %= mod
        sub_sum += sums
        sub_sum %= mod

    ret -= sub_sum
    ret %= mod

    inv = generate_inv(2, mod)
    ret *= inv[2]
    ret %= mod
    print(ret)


if __name__ == "__main__":
    run()

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
A=list(map(int,input().split()))
ans=0
for d in range(61):
    n_1 = 0
    for a in A:
        if (a>>d)&1 == 1:
            n_1 += 1
    n_0 = n - n_1
        
    ans += n_0*n_1 * 2**d
    ans %= 10**9+7
print(ans)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
ls = list(map(int,input().split()))
mod = 10**9+7
ans = 0
for i in range(n-1):
    for j in range(i+1,n):
        ans += (ls[i]^ls[j]) % mod
print(ans%mod)

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
table=[0]*60
for v  in map(int,input().split()):
    for j in range(60):
        if v%2:table[j]+=1
        v//=2
        if v==0:break
ans=0
mod=10**9+7
a=1

for o in table:
    z=(n-o)
    ans=(ans+o*z%mod*a)%mod
    a=a*2%mod
print(ans)

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
table=[0]*60
for i,v  in enumerate(map(int,input().split())):
    for j in range(60):
        table[j]+=v%2
        v//=2
        if v==0:break
ans=0
mod=10**9+7
a=1
n%=mod
for o in table:
    z=(n-o)%mod
    o%=mod
    ans=(ans+o*z*a)%mod
    a=a*2%mod
print(ans)

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
table=[0]*60
for i,v  in enumerate(map(int,input().split())):
    for j in range(60):
        table[j]+=v%2
        v//=2
        if v==0:break
#print(*table,sep='\n')
ans=0
mod1,mod2=10**9+7,998244353
mod=mod1
a=1
for o in table:
    z=n-o
    ans=(ans+o*z*a)%mod
    a=a*2%mod
print(ans)

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
table=[[0]*n for i in range(60)]
for i,v  in enumerate(map(int,input().split())):
    for j in range(60):
        table[j][n-1-i]=v%2
        v//=2
        if v==0:break
#print(*table,sep='\n')
ans=0
mod1,mod2=10**9+7,998244353
mod=mod1
a=1
for t in table:
    o,z=0,0
    
    for v in t:
        if v:
            o+=1
            ans=(ans+z*a)%mod
        else:
            z+=1
            ans=(ans+o*a)%mod

    a=a*2%mod
print(ans)

Submission status: Time Limit Exceeded

Solution code:
N=input()
N=int(N)
A=[0]*60
B=list(map(int,input().split()))
for i in range(len(B)):
  for j in range(60):
    if(B[i]&(1<<j)):
      A[j]+=1
ans=0
for i in range(60):
  ans+=A[i]*(N-A[i])*(1<<i)
  ans%=1000000007
print(ans)

Submission status: Time Limit Exceeded

Solution code:
N=input()
N=int(N)
A=[0]*60
B=list(map(int,input().split()))
for i in range(len(B)):
  for j in range(60):
    if(B[i]&(1<<j)):
      A[j]+=1
ans=0
for i in range(60):
  ans+=A[i]*(N-A[i])*(1<<i)
ans%=1000000007
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import sys

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007


def main():
    N, *A = map(int, read().split())

    ans = 0
    for i in range(60):
        s = 0
        for a in A:
            if a & (1 << i):
                s += 1
        tmp = 0
        for j in range(N):
            if A[j] & (1 << i):
                s -= 1
                tmp += (N - j - 1) - s
            else:
                tmp += s
        ans = (ans + tmp * pow(2, i, MOD)) % MOD

    print(ans)
    return


if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
a = list(map(int,input().split()))
tmp = [0]*61
MOD = 1_000_000_007
for i in range(n):
    for j in range(61):
        mask = 1<<j
        if a[i]&mask>0:
            tmp[j]+=1
ans = 0
for i in range(61):
    mask = 1<<i
    ans = (ans + mask*tmp[i]*(n-tmp[i])) % MOD
print(ans)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
a = list(map(int,input().split()))
ans = 0
MOD = 1_000_000_007
for i in range(n-1):
    for j in range(i+1,n):
        ans = (ans + (a[i]^a[j])) % MOD
print(ans)

Submission status: Time Limit Exceeded

Solution code:
n,*a = map(int,open(0).read().split())
mod = 10**9+7
ans = 0
for i in range(61):
  b = sum(map(lambda x:x>>i&1,a))
  ans += b*(n-b)*1<<i
print(ans%mod)

Submission status: Time Limit Exceeded

Solution code:
n,*a = map(int,open(0).read().split())
mod = 10**9+7
print(sum([sum([a[i]^j for j in a[i+1:]]) for i in range(n-1)])%mod)

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
a=list(map(int,input().split()))
mod=10**9+7
cnt=[0]*60
for elem in a:
    for i in range(60):
        cnt[i]+=(elem>>i)%2
ans=0
for i in range(60):
    ans+=((cnt[i]*(n-cnt[i]))<<i)%mod
print(ans%mod)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
A = list(map(int, input().split()))

ans = 0

for i in range(60 + 1):
    count1 = 0
    for a in A:
        count1 += (a >> i) & 1

    count0 = len(A) - count1
    ans += count1*count0 * pow(2, i)
    ans%=1000000007

print(ans)

Submission status: Time Limit Exceeded

Solution code:
import math
N = int(input())
A = list(map(int, input().split()))
bit = [0] * 60
MOD = 10 ** 9 + 7
for a in A:
    b = a
    i = 0
    waru = 1
    while a > 0:
        if a % (waru * 2) != 0:
            a -= waru
            bit[i] += 1
        waru *= 2
        i += 1
answer = 0
for i, b in enumerate(bit):
    answer += (2 ** i) * (b * (N-b))
print(answer % MOD)

Submission status: Time Limit Exceeded

Solution code:
import math
N = int(input())
A = list(map(int, input().split()))
bit = [0] * 60
MOD = 10 ** 9 + 7
for a in A:
    b = a
    i = 0
    while a > 0:
        if a % (2 ** (i+1)) != 0:
            a -= 2 ** i
            bit[i] += 1
        i += 1
answer = 0
for i, b in enumerate(bit):
    answer += (2 ** i) * (b * (N-b))
print(answer % MOD)

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
A=list(map(int,input().split()))
MOD=10**9+7
ans=0
for i in range(60):
    a=0
    for x in A:
        if x>>i&1:
            a+=1
    ans+=a*(n-a)*pow(2,i,MOD)
    ans%=MOD
print(ans)

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
A=list(map(int,input().split()))
ans=0
MOD=10**9+7
for i in range(n-1):
    for j in range(i+1, n):
        ans+=(A[i] ^ A[j])
        ans%=MOD

print(ans)

Submission status: Time Limit Exceeded

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

mod = 10**9 + 7
ans = 0
two = 1
for i in range(61):
    one = 0
    for j in range(n):
        if (a[j] >> i) & 1:
            one += 1
    ans = (ans + (one*(n-one))*two) % mod
    two = (two * 2) % mod
print(ans)

Submission status: Time Limit Exceeded

Solution code:
N=int(input())
S=list(map(int,input().split()))
ans=0
mod=10**9+7
for i in range(1,61):
   zero,one=0,0
   for j in S:
      tmp=bin(j)[2:]
      tmp=tmp.zfill(60)
      if tmp[-i]=="1":
         one+=1
      else:
         zero+=1
   s=pow(2,i-1,mod)
   ans+=s*zero*one%mod
   ans%=mod
print(ans)

Submission status: Time Limit Exceeded

Solution code:
N=int(input())
S=list(map(int,input().split()))
ans=0
mod=10**9+7
for i in range(1,61):
   zero,one=0,0
   for j in S:
      tmp=bin(j)[2:]
      tmp=tmp.zfill(60)
      if tmp[-i]=="1":
         one+=1
      else:
         zero+=1
   ans+=(2**(i-1)*zero*one)%mod
   ans%=mod
print(ans)