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: Time Limit Exceeded

Solution code:
    # -*- coding: utf-8 -*-
def main():
    N = int(input())
    D = list(map(int,input().split()))
    ans = 0
    for i in range(N):
        for j in range(i+1,N):
            ans += D[i]^D[j]

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

if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
def main():
    length = int(input())
    data = [int(x) for x in input().split()]

    total = 0
    for i in range(length - 1):
        for j in range(i, length):
            total += (data[i] ^ data[j])
    print(total % (10 ** 9 + 7))


if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

Solution code:
mod=10**9+7
def num2bi(x, k):
  #10進数xを2進数k桁(string)で出力
  out=format(x, '0'+str(k)+'b')
  return out

N=int(input())
A=list(map(int, input().split()))
ma=max(A)
keta=1
while ma>=2**keta:
  keta+=1
  
onekazu=[0 for i in range(keta)]
k=str(keta)
for i in range(N):
  temp=format(A[i], '0'+str(k)+'b')
  onekazu=[onekazu[j]+int(temp[j]) for j in range(keta)]
    
out=0
out=sum([(onekazu[i]*(N-onekazu[i])%mod)*(2**(keta-1-i))%mod for i in range(keta)])
out%=mod  
print(out)

Submission status: Time Limit Exceeded

Solution code:
import numpy as np

n=int(input())

a=[]

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

ans=0
for i in range(n-1):
    for k in range(i,n):
        tmp=a[i]^a[k]
        #print(tmp)
        ans=(ans+tmp)%1000000007

print(ans)

Submission status: Time Limit Exceeded

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

max_a = max(a)
msb = -1
for i in range(60 + 1):
    if max_a < 2 ** i:
        msb = i

assert msb >= 0
msb += 1

t = [[] for _ in range(n)]

for s in range(msb):
    t[0].append(1 if a[0] & (1 << s) > 0 else 0)

for i in range(1, n):
    for s in range(msb):
        t[i].append(t[i - 1][s] + (1 if a[i] & (1 << s) > 0 else 0))


ans = 0
for i in range(n - 1):
    for s in range(msb):
        stand = t[-1][s] - t[i][s]
        no_stand = (n - (i + 1)) - stand
        if a[i] & (1 << s) == 0:
            ans += (1 << s) * stand
            ans %= (10 ** 9 + 7)
        else:
            ans += (1 << s) * no_stand
            ans %= (10 ** 9 + 7)
print(ans)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
nums = input().split()
sum = 0
for i in range(len(nums)):
    for j in range(i + 1,len(nums),1):
        sum = sum + (int(nums[i]) ^ int(nums[j]))
        #print(str(i) +' ' + str(j))
print(sum %(10**9 + 7))

Submission status: Time Limit Exceeded

Solution code:
import itertools

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

sum = 0
for v in itertools.combinations(A, 2):
  sum += v[0] ^ v[1]
print(sum % 1000000007)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

def xor(x, y):
    X = bin(max(x, y))
    Y = bin(min(x, y))
    s = len(X)
    l = len(Y)
    ans = ""
    for k in range(2, 2+s-l):
        ans += X[k]
    for i in range(2, l):
        ans += str(int(X[i+s-l]) ^ int(Y[i]))

    return int(ans, 2)


Ans = 0
mod = 10**9 + 7
for i in itertools.combinations(a, 2):
        Ans = (Ans + xor(i[0], i[1])) % mod
print(Ans)

Submission status: Time Limit Exceeded

Solution code:
from itertools import combinations
N = int(input())
A = list(map(int,input().split()))
mod = 10**9 + 7
comb = list(combinations(A, 2))
XOR = [(i ^ j)%mod for i, j in comb]
print(sum(XOR)%mod)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
A_list = list(map(int,input().split()))
sum = 0
 
for m in range(N-1):
    for n in range(m+1,N):
        sum += (A_list[m]^A_list[n])
 
print(sum%(10**9+7))

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
a=list(map(int, input().split()))
for i in range(n):
	a[i]=format(a[i],'b')
#count1に1をカウントして入れる
#popは右側に行うとはやいらしいので気にせず行う
total=0
count1=0
for k in range(60):
	count1=0
	for i in range(n):
		if k<len(a[i]):
			if a[i][-1-k]=='1':
				count1+=1
	total+=count1*(n-count1)*(2**k)
	total=total%(10**9+7)
print(total)

Submission status: Time Limit Exceeded

Solution code:
import math
N = int(input())
A = [int(i) for i in input().split()]
#print(A)
ans1 = 0 
for i in range(0,N-1):
    for j in range(i+1,N):
        #print(A[i])
        #print(A[j])
        ans1 = ans1 + (A[i]^A[j])
print(ans1 % (10**9 + 7))

Submission status: Time Limit Exceeded

Solution code:
from collections import Counter
import sys
input = sys.stdin.readline


def main():
    mod = 10 ** 9 + 7
    n = int(input())
    a = list(map(int, input().split()))
    ans = 0
    for i in range(n):
        a_sub = a[i+1:]
        a_sub_dict = Counter(a_sub)
        for j in a_sub_dict:
            ans += a_sub_dict[j] * (a[i] ^ j)
    print(ans % mod)


if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
A = list(map(int,input().split()))
S = [0 for i in range(60)]
for i in range(N):
    a = A[i]
    for j in range(60):
        if (a>>j)&1:
            S[j] += 1
mod = 10**9 + 7
ans = 0
for i in range(60):
    s = S[i]
    t = N - s
    r = (s*t*(2**i))%mod
    ans = (ans + r)%mod
print(ans)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
A = list(map(int, input().split()))
digit = [0] * 60
for a in A:
    binary = bin(a)[-1:1:-1]
    for j in range(len(binary)):
        digit[j] += int(binary[j])
ans = 0
mod = 10**9+7
for i in range(60):
    ans += digit[i] * (N - digit[i]) * pow(2, i, mod)
    ans %= mod
print(ans)

Submission status: Time Limit Exceeded

Solution code:
def func(x, nn):
    value = 0
    for i in range(nn - 1):
        for j in range(i + 1, nn):
            value += x[i] ^ x[j]
    ans = value % (10 ** 9 + 7)
    return ans

n = int(input())
li = list(map(int, input().split()))
print(func(li, n))

Submission status: Time Limit Exceeded

Solution code:
import itertools
count = int(input())
waru = 10**9 + 7
intlist = list(map(int,input().split()))
sum = 0
kumi = list(itertools.combinations(intlist,2))
lenkumi = len(kumi)
for i in range(lenkumi):
    sum+=kumi[i][0]^kumi[i][1]
print(sum%waru)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())

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

sum = 0
count = 0

for i in range(0, n-1):
    for j in range(i+1, n):
        sum = sum + ((a[i] ^ a[j]) % (10**9 + 7))

sum = sum % (10**9 + 7)
print(sum)

Submission status: Time Limit Exceeded

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

A.sort()
visited = {}

ans_all = 0

for i in range(N-1):
    if A[i] in visited:
        diff = len(visited[A[i]]) - (N-(i+1))
        ans_all += sum(visited[A[i]][diff:])
        visited[A[i]] = visited[A[i]][diff:]
    else:
        visited[A[i]] = []
        for j in range(i+1, N):
            # print(A[i], A[j])
            ans = A[i] ^ A[j]
            visited[A[i]].append(ans)
            ans_all += ans

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

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
lst = [int(e)for e in input().split(' ')]
re = sum(lst[i]^lst[j] for i in range(n) for j in range(i, n))
print(re%(10**9 + 7))

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
nums = list(map(int, input().split(' ')))
print(sum([(x^y) for i, x in enumerate(nums[0:]) for y in nums[1+i:]]) % 1000000007)

Submission status: Time Limit Exceeded

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

cnt=[0]*60
p=10**9+7
for m in a:
    b=bin(m)
    l=len(b)-2
    #print(b)
    for i in range(l):
        cnt[i]+=int(b[-i-1])
    #kei=m
    #for i in range(100):
    #    cnt[i]+=kei%2
    #    kei//=2
    #    if(kei==0):
    #        break

#print(cnt)

lis=[]
jou=1
for i in range(60):
    lis.append(jou)
    jou*=2
    jou%=p

ans=0

for i in range(60):
    ans+=(lis[i]%p)*(cnt[i]%p)*((n-cnt[i])%p)
    ans%=p

print(ans)

Submission status: Time Limit Exceeded

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

def jouyo(X):
    return X%1000000007

MAX=A[0]
for i in range(N):
    if MAX<=A[i]:
        MAX = A[i]
    else:
        MAX = MAX

p = 1
M = 1
for i in range(60):
    if 2*p <= MAX:
        p = 2*p
        M = M+1
    else:
        break

List = []        
for i in range(1,M+1):
    count = 0
    for j in range(N):
        if A[j]%(2**i) >= 2**(i-1):
            count = count +1
        else:
            count = count
    List.append(count)
    
ans = 0   
for i in range(M):
    ans = ans + jouyo((2**i))*jouyo(List[i])*jouyo((N-List[i]))
    
print(jouyo(ans))

Submission status: Time Limit Exceeded

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

s = 0
for i in range(N):
    for j in range(i+1,N):
        s += A[i] ^ A[j]
print(s % (10**9+7))

Submission status: Time Limit Exceeded

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

res = 0

for i in range(b):
  for j in range(i, b):
    res += a[i] ^ a[j]
print(res % 1000000007)

Submission status: Time Limit Exceeded

Solution code:
import sys

sys.setrecursionlimit(10**7)
INF = 10 ** 18
MOD = 10 ** 9 + 7
def LI(): return list(map(int, sys.stdin.readline().split()))
def II(): return int(sys.stdin.readline())
def LS(): return list(map(list, sys.stdin.readline().split()))
def S(): return list(sys.stdin.readline())[:-1]

def main():
    n = II()
    a_s = LI()
    kaizyo = [1]
    keta = [0 for i in range(61)]
    ans = 0
    for i in range(61):
        kaizyo.append(kaizyo[i] * 2 % MOD)
    for i in a_s:
        for i, v in enumerate(bin(i)[:1:-1]):
            keta[i] += int(v)
    # print(kaizyo)
    # print(keta)
    for i, v in enumerate(keta):
        c = v * (n-v)
        ans += c * kaizyo[i]
        ans = ans % MOD
        # print(ans, c, kaizyo[i])

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

Submission status: Time Limit Exceeded

Solution code:
def main():
    N = int(input())
    a_list = list(map(int, input().split()))

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

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


if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
a_list = [int(i) for i in input().split()]
divide = 10 ** 9 + 7

sum = 0
for i in range(n):
    for j in range(i+1, n):
        # print(a_list[i], a_list[j] , a_list[i] ^ a_list[j])
        sum += (a_list[i] ^ a_list[j]) % divide

print(sum  % divide)

Submission status: Time Limit Exceeded

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

num = [0] * 60
for i in a:
    temp = bin(i + 2 ** 60)[3:]
    for i in range(len(temp)):
        if temp[i] == "1":
            num[i] += 1
ans = 0
for i in range(60):
    ans += (num[i] * (n - num[i]) * (2 ** (59 - i)))
    ans %= mod
print(ans)

Submission status: Time Limit Exceeded

Solution code:
def main():
    num = input()
    num_list = list(map(int, input().split(" ")))
    result = sum([sum([num_list[i]^num_list[j] for j in range(i)]) for i in range(int(num))])
    print(result%(10**9+7))    

if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
nums =["INF"] + list(map(int,input().split()))

counter = 0

sigma1 = [x for x in range(1,n)]

for s1 in sigma1:
  sigma2 = [x for x in range(s1 + 1,n+1)]
  for s2 in sigma2:
    counter += nums[s1] ^ nums[s2]



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

Submission status: Time Limit Exceeded

Solution code:
#%%
inf = 10**9 + 7
import numpy as np

def p(x):
    tmp = (bin(x)[2:])
    l = len(tmp)
    ans = '0'*(70-l) + tmp
    return ans


n = int(input())
a = list(map(int, input().split()))
count = np.array([0] * 70)
for i in range(n):
    tmp = np.array(list(p(a[i])))
    #print(tmp)
    count[tmp=='1'] += 1


ans = 0
for i in range(70):
    k = 2 ** (69 - i)
    k %= inf
    x = count[i] % inf
    y = (n - x) % inf
    ans += (x * y * k) % inf
    ans %= inf

ans %= inf
print(ans)

Submission status: Time Limit Exceeded

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

for i in range(n - 1):
    for j in range(i, n):
        try:
            xor_sum += a[i] ^ a[j + 1]
        except:
            pass

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

Submission status: Time Limit Exceeded

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

res = 0

for i in range(len(a)):
  for j in range(i, len(a)):
    res += a[i] ^ a[j]
print(res % 1000000007)

Submission status: Time Limit Exceeded

Solution code:
import operator
n = int(input())
a = list(map(int, input().split()))
sum = 0
for i in range(n -1):
	for j in range(i + 1, n) :
		sum += operator.xor(a[i], a[j])
while sum > 1000000007 :
	sum -= 1000000007
print(sum)

Submission status: Time Limit Exceeded

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

sum = 0
for i in range(n-1):
  for j in range(i, n):
    sum += (a[i] ^ a[j])%num
  sum %= num
    
print(sum)

Submission status: Time Limit Exceeded

Solution code:
mod=10**9+7
def num2bi(x, k):
  #10進数xを2進数k桁(string)で出力
  out=format(x, '0'+str(k)+'b')
  return out

N=int(input())
A=list(map(int, input().split()))
ma=max(A)
keta=1
while ma>=2**keta:
  keta+=1
  
onekazu=[0 for i in range(keta)]
k=str(keta)
for i in range(N):
  temp=format(A[i], '0'+str(k)+'b')
  onekazu=[onekazu[j]+int(temp[j]) for j in range(keta)]
    
out=0
for i in range(keta):
  temp=onekazu[i]*(N-onekazu[i])%mod
  temp*=(2**(keta-1-i))%mod
  out+=temp
  out%=mod
  
print(out)

Submission status: Time Limit Exceeded

Solution code:
from itertools import combinations

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

print(sum(a ^ b for a, b in combinations(A, 2)) % (10**9+7))

Submission status: Time Limit Exceeded

Solution code:
import sys
input=sys.stdin.readline
n=int(input())
lists=list(map(int,input().split()))
aa=[0 for i in range(n)]
bb=[0 for i in range(n)]
length=61
use=[0 for i in range(61)]
for  j in range(n):
    k=format(lists[j],"0%ib"%length)
    k=k[::-1]
    aa[j]=k[:30]  
    bb[j]=k[30:]
for p in aa:    
    for some in range(30):
        use[some]+=int(p[some])
for q in bb:    
    for some in range(31):
        use[some+30]+=int(q[some])
answer=0

for j in range(61):
    answer+=(2**j)*use[j]*(n-use[j])%(10**9+7)
print(answer%(10**9+7))

Submission status: Time Limit Exceeded

Solution code:
import sys
from itertools import combinations

INPUT = lambda: sys.stdin.readline().rstrip()
INT = lambda: int(INPUT())
LIST = lambda: list(map(int, INPUT().split()))

sys.setrecursionlimit(10 ** 9)
mod = 10 ** 9 + 7


def main():
    N = INT()
    A = LIST()

    cnt = 0
    for i, j in list(combinations(A, 2)):
        cnt += int(bin(i ^ j), 2)

    print(cnt % mod)


if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
from itertools import combinations
N = int(input())

A_list = list(map(int,input().split()))
ans = 0

for i in combinations(A_list, 2):
    ans += i[0]^i[1]
    
print(ans%1000000007)

Submission status: Time Limit Exceeded

Solution code:
import itertools
import numpy as np

x = 10**9
S = int(input())
a = [int(i) for i in input().split()]

xor = 0
patern = list(itertools.combinations(a, 2))
for p in patern:
    xor += p[0] ^ p[1]
if xor >= x:
    print(np.mod(xor, (x + 7)))
else:
    print(xor)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
a = list(map(lambda x: int(x), input().split()))
res = 0
MOD = 1e9 + 7
for i in range(60):
    w = 1 << i
    c1 = 0
    c0 = 0
    for j in a:
        t = w & j
        if t == 0:
            c0 += 1
        else:
            c1 += 1
    res = (res + w * c0 % MOD * c1 % MOD) % MOD
print ('%d' % res)

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

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

xor_sum = 0
for i in range(len(a_list) - 1):
    for j in range(i + 1, len(a_list)):
        xor_sum += int(bin(a_list[i]), 2) ^ int(bin(a_list[j]), 2)

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

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
arr = list(map(int,input().split()))
cnt = 0
for i in range(N):
  for j in range(i+1,N):
    cnt += arr[i]^arr[j]
    
print(cnt%1000000007)

Submission status: Time Limit Exceeded

Solution code:
import numpy as np

def preprocess(x):
    x = int(x)
    x = bin(x)[2:]
    return x
def preprocess2(x):
    x = x.zfill(max_len)
    x = list(x)
    x = list(map(int, x))
    return x

N = int(input())
A = list(map(preprocess, input().split()))
max_len = max(list(map(lambda b:len(b), A)))
A = list(map(preprocess2, A))
A = np.array(A).T.tolist()


if __name__ == "__main__":
    res = 0
    mod = 10**9+7
    for i, col in enumerate(reversed(A)):
        col = np.array(col)
        num_1 = np.count_nonzero(col)
        num_0 = len(col)-num_1

        tmp = 1
        tmp = tmp*num_0%mod
        tmp = tmp*num_1%mod
        for _ in range(i):
            tmp = tmp*2%mod
        
        res = (res+tmp)%mod
    
    print(res)

Submission status: Time Limit Exceeded

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


def xor(x, y):
    X = bin(max(x, y))
    Y = bin(min(x, y))
    s = len(X)
    l = len(Y)
    ans = ""
    for k in range(2, 2+s-l):
        ans += X[k]
    for i in range(2, l):
        ans += str(int(X[i+s-l]) ^ int(Y[i]))

    return int(ans, 2)


Ans = 0
mod = 10**9 + 7
for i in range(n-1):
    for j in range(i+1, n):
        Ans = (Ans + xor(a[i], a[j])) % mod
print(Ans)

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
A=list(map(int,input().split()))
l=[0]*60
for i in range(60):
    for j in range(n):
        l[i]+=A[j]%2
        A[j]//=2  
ans=0
k=1
for i in range(60):
    ans=(ans+k*l[i]*(n-l[i]))%1000000007
    k=(k*2)%1000000007
print(ans)

Submission status: Time Limit Exceeded

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

s = 0
for i in range(N):
    for j in range(i+1,N):
        s += A[i] ^ A[j]
print(s % (10**9+7))

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
a = [int(i) for i in input().split()]

ans = 0
for i in range(n - 1):
    for j in range(i + 1, n):
        ans += a[i] ^ a[j]
print(ans % (10 ** 9 + 7))

Submission status: Time Limit Exceeded

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

t = [[] for _ in range(n)]

for s in range(60 + 1):
    t[0].append(1 if a[0] & (1 << s) > 0 else 0)

for i in range(1, n):
    for s in range(60 + 1):
        t[i].append(t[i - 1][s] + (1 if a[i] & (1 << s) > 0 else 0))


ans = 0
for i in range(n - 1):
    for s in range(60 + 1):
        stand = t[-1][s] - t[i][s]
        no_stand = (n - (i + 1)) - stand
        if a[i] & (1 << s) == 0:
            ans += (1 << s) * stand
            ans %= (10 ** 9 + 7)
        else:
            ans += (1 << s) * no_stand
            ans %= (10 ** 9 + 7)
print(ans)

Submission status: Time Limit Exceeded

Solution code:
MOD = 10**9 + 7

N = int(input())
A = [int(s) for s in input().split()]

ans = sum(A[i] ^ A[j] for i in range(N-1) for j in range(i+1, N))

print(ans % 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(n):
  for j in range(i,n):
    ans+=(A[i]^A[j])
print(ans%mod)

Submission status: Time Limit Exceeded

Solution code:
import itertools
import scipy.misc as scm

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

loopnum = scm.comb(n, 2, exact=True)
c = itertools.combinations(nums, 2)
sum = 0
for i in range(loopnum):
  temp = next(c)
  sum += temp[0]^temp[1]
print(sum%(10**9+7))

Submission status: Time Limit Exceeded

Solution code:
import sys
from itertools import combinations as combi
input = sys.stdin.readline
N = int(input())
a = list(map(int, input().split()))
cs = [[0] * 61 for _ in range(N + 1)]
mod = 10 ** 9 + 7
for i in range(N):
  for j in range(61):
    t = 1 << j
    #print(a[i], t, a[i] & t)
    cs[i + 1][j] = (cs[i][j] + (a[i] & t)) % mod
res = 0
#print(cs[-1])
#print(cs[2])
for i in range(N):
  t = 0
  for j in range(61):
    if a[i] & (1 << j) != 0:
      #if i == 1: print((1 << j) * (N - i - 1), (cs[-1][j] - cs[i + 1][j]))
      t += (1 << j) * (N - i - 1) - (cs[-1][j] - cs[i + 1][j])
    else:
      #if i == 1: print(a[i] & (1 << j), (cs[-1][j] - cs[i + 1][j]))
      t += (cs[-1][j] - cs[i + 1][j])
    #if i == 1: print(t)
    t %= mod
  res += t
  res %= mod
print(res % mod)

Submission status: Time Limit Exceeded

Solution code:
MOD = 1000000007
ans = 0
N = int(input())
s = list(map(int,input().split()))
for i in range(0,N):
    for j in range(i,N):
        if i!=j:
            ans += s[i]^s[j]
print(ans%MOD)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

res = 0

for i in range(len(a)):
  for j in range(i, len(a)):
    res += a[i] ^ a[j]
print(res % 1000000007)

Submission status: Time Limit Exceeded

Solution code:
import itertools
N = int(input())
A = list(map(int, input().split()))
ans = 0

for v in itertools.combinations(A, 2):
    ans += v[0] ^ v[1]
    
print(ans % (10**9 + 7))

Submission status: Time Limit Exceeded

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

c = [0] * 60

const = 10 ** 9 + 7

ans = 0

"""
for i in range(n):
    b = str(bin(a[i]))
    for j in range(len(b) - 2):
        k = - j - 1
        c[j] += int(b[k])
"""

for i in range(n):
    b = a[i]
    t = 0
    while t <= 60:
        if b == 0:
            break
        elif b == 1:
            c[t] += 1
            break
        else:
            q, mod = divmod(b, 2)
            b = q
            c[t] += mod
            t += 1

for i in range(60):
    ans += (((2 ** i) % const) * (c[i] * (n - c[i]))) % const

print(ans % const)

Submission status: Time Limit Exceeded

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

ans = 0
for i in range(60 + 1):
    cnt = 0
    for a in A:
        if a >> i & 1:
            cnt += 1
    ans = (ans + 2 ** i * cnt * (N - cnt)) % (10 ** 9 + 7)
print(ans)

Submission status: Time Limit Exceeded

Solution code:
N=int(input())
A=[int(x) for x in input().split()]
A.sort()

mod = 10**9 + 7
ans = 0
k=1
while A[-1]>0:
    t = 0
    for i in range(N):
        t+=A[i]%2
        A[i]//=2
    ans = (ans + (N-t)*t*(2**(k-1))%mod)%mod
    k +=1
print(ans)

Submission status: Time Limit Exceeded

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

sums = 0
for x in itertools.combinations(a, 2):
    sums += int(bin(x[0] ^ x[1]), 2)

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

Submission status: Time Limit Exceeded

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

MAX=A[0]
for i in range(N):
    if MAX<=A[i]:
        MAX = A[i]
    else:
        MAX = MAX

p = 1
M = 1
for i in range(60):
    if 2*p <= MAX:
        p = 2*p
        M = M+1
    else:
        break

List = []        
for i in range(1,M+1):
    count = 0
    for j in range(N):
        if A[j]%(2**i) >= 2**(i-1):
            count = count +1
        else:
            count = count
    List.append(count)
    
ans = 0   
for i in range(M):
    ans = ans + (2**i)*List[i]*(N-List[i])
    
print(ans%1000000007)

Submission status: Time Limit Exceeded

Solution code:
import unittest


class TestD(unittest.TestCase):
    def test_1(self):
        self.assertEqual(think([1, 2, 3]), 6)

    def test_2(self):
        self.assertEqual(think([3, 1, 4, 1, 5, 9, 2, 6, 5, 3]), 237)

    def test_3(self):
        self.assertEqual(think([3, 14, 159, 2653, 58979, 323846, 2643383, 27950288, 419716939, 9375105820]), 103715602)


def solve():
    a = read()
    result = think(a)
    write(result)


def read():
    n = read_int(1)[0]
    return read_int(n)


def read_int(n):
    return read_type(int, n)


def read_float(n):
    return read_type(float, n)


def read_type(t, n):
    return list(map(lambda x: t(x), read_line().split(' ')))[:n]


def read_line(n=0):
    if n == 0:
        return input().rstrip()
    else:
        return input().rstrip()[:n]


def think(data):
    mode = 10 ** 9 + 7
    result = 0
    # TODO: avoid from TLE
    for i in range(len(data)):
        for j in range(i + 1, len(data)):
            result += data[i] ^ data[j]
            result %= mode
    return result


def write(result):
    print(result)


if __name__ == '__main__':
    # unittest.main()
    solve()

Submission status: Time Limit Exceeded

Solution code:
mod=10**9+7
def num2bi(x, k):
  #10進数xを2進数k桁(string)で出力
  out=format(x, '0'+str(k)+'b')
  return out

N=int(input())
A=list(map(int, input().split()))
ma=max(A)
keta=1
while ma>=2**keta:
  keta+=1
  
onekazu=[0 for i in range(keta)]
k=str(keta)
for i in range(N):
  temp=format(A[i], '0'+str(k)+'b')
  for j in range(keta):
    onekazu[-1-j]+=int(temp[-1-j])
    
out=0
for i in range(keta):
  temp=onekazu[i]*(N-onekazu[i])%mod
  temp*=(2**(keta-1-i))%mod
  out+=temp
  out%=mod
  
print(out)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
import sys
from itertools import combinations as combi
input = sys.stdin.readline
N = int(input())
a = list(map(int, input().split()))
cs = [[0] * 61 for _ in range(N + 1)]
mod = 10 ** 9 + 7
for i in range(N):
  for j in range(61):
    t = 1 << j
    #print(a[i], t, a[i] & t)
    cs[i + 1][j] = cs[i][j] + (a[i] & t)
res = 0
#print(cs[-1])
#print(cs[2])
for i in range(N):
  t = 0
  for j in range(61):
    if a[i] & (1 << j) != 0:
      #if i == 1: print((1 << j) * (N - i - 1), (cs[-1][j] - cs[i + 1][j]))
      t += (1 << j) * (N - i - 1) - (cs[-1][j] - cs[i + 1][j])
    else:
      #if i == 1: print(a[i] & (1 << j), (cs[-1][j] - cs[i + 1][j]))
      t += (cs[-1][j] - cs[i + 1][j])
    #if i == 1: print(t)
    t %= mod
  res += t
  res %= mod
print(res % mod)

Submission status: Time Limit Exceeded

Solution code:
import itertools
N = int(input())
w = [int(x) for x in input().split()]
x = [balls for balls in itertools.combinations(w, 2)]
count = [i[0]^i[1] for i in x]
result = sum(count) % (10**9+7)
print(result)

Submission status: Time Limit Exceeded

Solution code:
import sys
input = sys.stdin.readline
n = int(input())
alist = list(map(int,input().split()))
binlist = [0]*60
mod_number = 10**9+7
for a in alist:
    a_bin = bin(a)
    for i in range(len(a_bin)-2):
        if int(a_bin[-(i+1)])==1:
            binlist[-(i+1)] += 1
            #print(a,a_bin,i,binlist)
ans = 0
for i in range(60):
    ans = (ans + binlist[-(i+1)]*(n-binlist[-(i+1)])*pow(2,i))%mod_number
    
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])%mod
print(ans%mod)

Submission status: Time Limit Exceeded

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

tmp = 0
for i in range(1,N):
  for j in range(i+1, N+1):
    tmp += A[i-1] ^ A[j-1]

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

Submission status: Time Limit Exceeded

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

total = 0
for i in range(n-1):
    for j in range(i+1, n):
        total += a[i]^a[j]
        total = total%((10**9)+7)

print(total)

Submission status: Time Limit Exceeded

Solution code:
N=int(input())
A = list(map(int,input().split()))
l = len(A)
ans=0
for idx, val in enumerate(A):
    if idx == l - 1:
        print(ans%(10**9+7))
        exit()
    for x in range(idx+1, l):
        num = A[idx] ^ A[x]
        ans += num

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
A = [int(i) for i in input().split()]
j = 0
k = 1
cnt = 0
while(j<=N-2):
    cnt += A[j]^A[k]
    k += 1
    if k == N:
        j += 1
        k = j+1
print(cnt%(10**9+7))

Submission status: Time Limit Exceeded

Solution code:
n = int(input())

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

sum = 0
count = 0

for i in range(0, n-1):
    for j in range(i+1, n):
        sum = (sum + (a[i] ^ a[j])) % (10**9 + 7)


print(sum)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
A_list = list(map(int, input().split()))
sum = 0

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

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

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
a_list = [int(i) for i in input().split()]
divide = 10 ** 9 + 7

sum = 0
for i in range(n):
    for j in range(i+1, n):
        # print(a_list[i], a_list[j] , a_list[i] ^ a_list[j])
        sum += (a_list[i] ^ a_list[j])

print(sum % divide)

Submission status: Time Limit Exceeded

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

cnt=[0]*100
p=10**9+7
for m in a:
    b=bin(m)
    l=len(b)-2
    #print(b)
    for i in range(l):
        cnt[i]+=int(b[-i-1])
    #kei=m
    #for i in range(100):
    #    cnt[i]+=kei%2
    #    kei//=2
    #    if(kei==0):
    #        break

#print(cnt)

lis=[]
jou=1
for i in range(100):
    lis.append(jou)
    jou*=2
    jou%=p

ans=0

for i in range(100):
    ans+=(lis[i]%p)*(cnt[i]%p)*((n-cnt[i])%p)
    ans%=p

print(ans)