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:
_ = input()
A = list(map(int, input().strip().split()))
n = len(A)
res = 0
for i in range(n-1):
    for j in range(i+1, n):
        res += (A[i]^A[j])
res = res % (int(1e9) + 7)
print(res)

Submission status: Time Limit Exceeded

Solution code:
MOD = 10**9 + 7

def main():
    n = int(input())
    a_list = list(map(int, input().split()))

    ans = 0
    for i in range(0, n-1):
        for j in range(i, n):
            temp = a_list[i] ^ a_list[j]
            ans += temp % MOD

    print(ans % MOD)


if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
A=list(map(int,input().split()))
l=[0]*60
for a in A:
    a_2=format(a,"060b")
    for i in range(60):
        if a_2[i]=="1":
            l[59-i]+=1
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()))

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

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

Submission status: Time Limit Exceeded

Solution code:
mod = 1000000007
n = int(input())
num = list(map(int,input().split()))
sum = 0
for i in range(n-1):
  for j in range(i+1,n):
    sum += num[i]^num[j]
print(sum%mod)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
mod = 10**9+7
num = [ int(v) for v in input().split() ]
bits = [ 0 for i in range(100) ]
num_bin_len = []
for i in num:
    t = bin(i)[2:][::-1]
    num_bin_len.append(len(t))
    for j, v in enumerate(t):
        bits[j] += int(v)

binmax = max(num_bin_len)+1
pow_2_list = [ pow(2,i,mod) for i in range(100) ]


ans = 0
for i, v in enumerate(bits[:binmax]):
    ans += v * (n-v)  * pow_2_list[i] 
print(ans % mod)

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))
for i in range(len(kumi)):
    sum+=kumi[i][0]^kumi[i][1]
print(sum%waru)

Submission status: Time Limit Exceeded

Solution code:
# -*- coding: utf-8 -*-
import math
import datetime
import itertools

# 入力
N = int(input())
S = str(input())
#N, A, B = map(int, input().split())
#A, B, C = map(int, input().split())

Z = (10 ** 9) + 7
list = S.split()
sum = 0
for v in itertools.combinations(list, 2):
    #print(v)
    sum += int(v[0]) ^ int(v[1])
print (sum%Z)

Submission status: Time Limit Exceeded

Solution code:
div = 10**9 + 7
ans = 0

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

for i in range(N):
    for j in range(i,N):
        #print(str(i) + " : " + str(j))
        ans += A[i]^A[j]

#print(ans)
print(ans%div)

Submission status: Time Limit Exceeded

Solution code:
import itertools
 
n = int(input())
a = list(map(int, input().split()))
 
mod = 10**9+7
 
s = 0
p = itertools.combinations(a,2)
for v in list(p):
  s += v[0]^v[1]
  
print(s%mod)

Submission status: Time Limit Exceeded

Solution code:
def solve():
    
    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))
    
n=int(input())
a=list(map(int,input().split()))
solve()

Submission status: Time Limit Exceeded

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

xor = 0

for i in range(N-1):
    newData  = [int(A[i]) ^ int(aa) for aa in A[i:]]
    xor += sum(newData)

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

Submission status: Time Limit Exceeded

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

ans = 0

for i in range(n):
  for j in range(i+1, n):
    ans += a[i] ^ a[j]
    
print(ans%1000000007)

Submission status: Time Limit Exceeded

Solution code:
N=int(input())
A=list(map(int,input().split()))
P=10**9+7
ans=0
BIN=[0]*N
for h in range(N):
    BIN[h]=bin(A[h])[2:].zfill(60)

for i in range(60):
    inc=0
    one=0
    zero=0
    for j in range(N):
        if BIN[j][59-i]=="0":
            zero+=1
        else:
            one+=1
    ans+=zero*one*2**i
print(ans%P)

Submission status: Time Limit Exceeded

Solution code:
import sys

n = int(sys.stdin.readline().strip())
a = [int(v) for v in sys.stdin.readline().strip().split()]
c = 0
for i in range(n-1):
  for j in range(i+1, n):
    # print('a[%d] ^ a[%d] = %d' %( i, j, a[i] ^ a[j]))
    c += a[i] ^ a[j]
print(c % (10 ** 9 + 7))

Submission status: Time Limit Exceeded

Solution code:
MOD = 10**9 + 7
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 += (A[i]^A[j])%MOD
print(ans%MOD)

Submission status: Time Limit Exceeded

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

from itertools import combinations
# ["a", "b", "c"] から 2 つ選ぶ組み合わせをすべて列挙する

count = 0
for t in combinations(A, 2):
  count += t[0]^t[1]
print(count%(10**9+7))

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]
        
ans = S % MOD
print(ans)

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)]
for i in range(N):
  temp=num2bi(A[i], keta)
  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])
  temp%=mod
  temp*=(2**(keta-1-i))
  temp%=mod
  out+=temp
  out%=mod
  
print(out)

Submission status: Time Limit Exceeded

Solution code:
def main():
    import sys

    input = sys.stdin.readline

    mod = 10 ** 9 + 7
    n = int(input())
    a = tuple(map(int, input().split()))

    b = [[0] * 60 for _ in range(n + 1)]

    for j in range(60):
        for i, x in enumerate(a, 1):
            if (x >> j) & 1:
                b[i][j] += 1

    for j in range(60):
        for i in range(1, n + 1):
            b[i][j] += b[i - 1][j]

    # print(b)

    s = b[-1]

    ret = 0
    for j in range(60):
        for i, x in enumerate(a, 1):
            if (x >> j) & 1:
                ret = (ret + (1 << j) * ((n - i) - (s[j] - b[i][j]))) % mod
            else:
                ret = (ret + (1 << j) * (s[j] - b[i][j])) % mod
    print(ret)


if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
from sys import stdin 
n = int(stdin.readline().rstrip())
s = [int(x) for x in stdin.readline().rstrip().split()]
answer = 0
for i in range(n):
    if i != n-1:
        for j in range(i+1,n):
            answer += s[i] ^ s[j]
print(answer % 1000000007)

Submission status: Time Limit Exceeded

Solution code:
import sys

def solve():
    input = sys.stdin.readline
    N = int(input())
    A = [int(a) for a in input().split()]
    mod = 7 + 10 ** 9

    bit = dict()
    for i in range(N):
        bit[i] = dict()
        for j in range(60):
            bit[i][j] = 0
            
    last = A[N-1]
    for j in range(60):
        bit[N-1][j] = last % 2
        last //= 2
    
    ans = 0
    for i in reversed(range(N-1)):
        total = N - 1 - i
        num = A[i]
        for j in range(60):
            if num % 2 == 1:
                ans += (total - bit[i+1][j]) * pow(2, j, mod)
                ans %= mod
            else:
                ans += bit[i+1][j] * pow(2, j, mod)
                ans %= mod
            bit[i][j] = bit[i+1][j]  + (num % 2)
            num //=2
    print(ans)

    return 0

if __name__ == "__main__":
    solve()

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
mod=10**9+7
a=list(map(int,input().split()))
L=len(format(max(a),"b"))
s=[0]*L
for i in range(n):
  c=format(a[i], 'b').zfill(L)
  for j in range(len(c))[::-1]:
    s[j]+=int(c[j])
ans=0
for i in range(len(s))[::-1]:
  add=(s[L-i-1])*(n-s[L-i-1])
  for j in range(i):
    add*=2
    add%=mod
  ans+=add
  ans%=mod
print(ans)

Submission status: Time Limit Exceeded

Solution code:
from itertools import combinations
N = int(input())
A = [int(i) for i in input().split()]

S = 0
for i, j in combinations(A, 2):
    S += i^j
    S %= 10**9+7

print(S)

Submission status: Time Limit Exceeded

Solution code:
import itertools
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 >= 10 ** 9:
    print(xor % (10 ** 9 + 7))
else:
    print(xor)

Submission status: Time Limit Exceeded

Solution code:
from itertools import combinations

n = int(input())
a = list(map(int, input().split()))
mod = 10**9 + 7
ans = 0
for i in combinations(a, 2):
    ans += i[0] ^ i[1]
    ans %= mod

print(ans)

Submission status: Time Limit Exceeded

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

num = 1000000007

sum = 0
for i in range(N+1):
    for j in range(i+1, N):
        sum += data[i] ^ data[j]
        while sum > num:
            sum -= num

print(sum)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
from collections import Counter,defaultdict,deque
import sys
import bisect
import math
import itertools
import string
import queue
import copy
# import numpy as np
# import scipy
from itertools import permutations, combinations
from heapq import heappop, heappush
input = sys.stdin.readline
sys.setrecursionlimit(10**8)
mod = 10**9+7
 
def inp(): # n=1
    return int(input())
def inpm(): # x=1,y=2
    return map(int,input().split())
def inpl(): # a=[1,2,3,4,5,...,n]
    return list(map(int, input().split()))
def inpls(): # a=['1','2','3',...,'n']
    return list(input().split())
def inplm(n): # x=[] 複数行
    return list(int(input()) for _ in range(n))
def inpll(n): # [[1,1,1,1],[2,2,2,2],[3,3,3,3]]
    return [list(map(int, input().split())) for _ in range(n)]

def main():
    n=inp()
    a=inpl()
    pre = (1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096, 8192, 16384, 32768, 65536, 131072, 262144, 524288, 1048576, 2097152, 4194304, 8388608, 16777216, 33554432, 67108864, 134217728, 268435456, 536870912, 1073741824, 2147483648, 4294967296, 8589934592, 17179869184, 34359738368, 68719476736, 137438953472, 274877906944, 549755813888, 1099511627776, 2199023255552, 4398046511104, 8796093022208, 17592186044416, 35184372088832, 70368744177664, 140737488355328, 281474976710656, 562949953421312, 1125899906842624, 2251799813685248, 4503599627370496, 9007199254740992, 18014398509481984, 36028797018963968, 72057594037927936, 144115188075855872, 288230376151711744, 576460752303423488, 1152921504606846976)
    x=[0 for _ in range(61)]
    ans=0
    for i in range(n):
        z=[0 for _ in range(61)]
        y = a[i]
        index=0
        while y>0:
            if y%2!=0:
                z[index]+=1
            index+=1
            y=y//2
        for j in range(61):
            num = i-x[j]
            if i!=0:
                if z[j]==0:
                    ans=(ans+x[j]*pre[j])%mod
                else:
                    ans=(ans+num*pre[j])%mod
            x[j]+=z[j]
    print(ans)


if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

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

e = 10**9 + 7
r = 0
for i in range(N-1):
  for j in range(i+1, N):
    r += (arr[i] ^ arr[j])
    
print(r%e)

Submission status: Time Limit Exceeded

Solution code:
import itertools

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

mod = 10**9+7

s = 0
p = itertools.combinations(a,2)
for v in list(p):
  s += v[0]^v[1]
  
print(s%mod)

Submission status: Time Limit Exceeded

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

for i in range(n-1):
    for j in range(i+1,n):
        an+=a[i]^a[j]
        an=an%MOD

print(an)

Submission status: Time Limit Exceeded

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

from itertools import combinations

ans = sum([_a^+_b for _a, _b in combinations(a, 2)])

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

Submission status: Time Limit Exceeded

Solution code:
N = int(input())

A = list(map(int, input().split()))
max_leng = len(bin(max(A))) - 2
A = list(map(bin, A))
A_processed = []

for a in A:
    a = a[2:]
    while len(a) < max_leng:
        a = '0' + a
    A_processed.append(a)

res = 0

for i in range(max_leng):
    num_0 = 0
    for a in A_processed:
        if a[max_leng - 1 - i] == '0':
            num_0 += 1
    res += 2**i * num_0 * (N - num_0)
    res = res % 1000000007

print(res)

Submission status: Time Limit Exceeded

Solution code:
import sys

def solve():
    input = sys.stdin.readline
    N = int(input())
    A = [int(a) for a in input().split()]
    mod = 7 + 10 ** 9

    bit = dict()
    for i in range(N):
        bit[i] = dict()
        for j in range(60):
            bit[i][j] = 0
    last = A[N-1]
    for j in range(60):
        bit[N-1][j] = last % 2
        last //= 2
    ans = 0
    for i in reversed(range(N-1)):
        total = N - 1 - i
        num = A[i]
        for j in range(60):
            if num % 2 == 1:
                ans += (total - bit[i+1][j]) * pow(2, j, mod)
                ans %= mod
            else:
                ans += bit[i+1][j] * pow(2, j, mod)
                ans %= mod
            bit[i][j] = bit[i+1][j]  + (num % 2)
            num //=2
    print(ans)

    return 0

if __name__ == "__main__":
    solve()

Submission status: Time Limit Exceeded

Solution code:

n = int(input())
a = [int(i) for i in input().split()]
c = [0] * 63
for i in a:
	for j in range(0, 63):
		if (i & (1 << j)):
			c[j] += 1

ans = 0
for i in range(0, 63):
	ans += (1 << i) * (c[i] * (n - c[i]))

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

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
li=list(map(int, input().split()))
cnt=0

for i in range(n):
  for j in range(n-i-1):
    cnt+=li[i]^li[i+j+1]

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

Submission status: Time Limit Exceeded

Solution code:
from collections import Counter
N = int(input())
MAXBIT = 60
MOD = 10 ** 9 + 7
A = list(map(int, input().split()))
B = []
C = [Counter() for _ in range(MAXBIT)]
for a in A:
    b = format(a, '0'+str(MAXBIT)+'b')
    for d in range(MAXBIT):
        C[d].update([b[d]])
ans = 0
for d in range(MAXBIT):
    ans += (C[d]['0'] * C[d]['1']) * (2 ** (MAXBIT-d-1))
    ans %= MOD
print(ans)

Submission status: Time Limit Exceeded

Solution code:
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

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

s = 0
b = 10 * 10 * 10 * 10 * 10 * 10 * 10 * 10 * 10 + 7
for i in range(1 - 1, N - 1):
    for j in range(i + 1 - 1, N + 1 - 1):
        s += A[i] ^ A[j]
        while s >= b:
            s -= b

print(s)

Submission status: Time Limit Exceeded

Solution code:
def add(a,b):
    mod=1000000007
    return (a+b)%mod

a=int(input())
b=list(map(int,input().split()))
s=0
for i in range(len(b)-1):
  for j in range(i+1,len(b)):
    s=add(s,b[i]^b[j])    
print(s)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
S_str = str(input()).split()
S = [int(s) for s in S_str]

Sum = 0

for i in range(0, N-1):
    for j in range(i+1, N):
        Sum += S[i]^S[j]
print(Sum%1000000007)

Submission status: Time Limit Exceeded

Solution code:
# -*- coding: utf-8 -*-
n = int(input())
mb = 0b111111111111111111111111111111
a = list(map(lambda x: int(x) ^ mb, input().split()))

rst = 0
mod = 1000000007
for i in range(n-1):
    for j in range(i+1, n):
        tmp = (a[i] ^ a[j])
        rst = (rst + tmp) % mod

print(rst)

Submission status: Time Limit Exceeded

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

sum = 0

for i in range(N):
  for j in range(i,N):
    if (i!=j):
      sum += A[i] ^ A[j]
      #print(A[i] ^ A[j])

ans = sum % (1000000007)
#出力
#print(N)
#print(A)
#print(' ')
#print(sum)
print(ans)

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)]
for i in range(N):
  temp=num2bi(A[i], keta)
  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])*(2**(keta-1-i))
  out+=temp
  out%=mod
  
print(out)

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

Submission status: Time Limit Exceeded

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

print(result%(1000000000+7))

Submission status: Time Limit Exceeded

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

MOD = 10 ** 9 + 7

b = [0] * 60
for x in a:
    for i, temp in enumerate(list(map(int, reversed(bin(x)[2:])))):
        b[i] += temp

ans = 0
d = 1
for x in b:
    ans = (ans + ((x * (n-x)) % MOD) * d) % MOD
    d = d * 2 % MOD

print(ans)

Submission status: Time Limit Exceeded

Solution code:
import math

N = int(input())

nums = [int(e) for e in input().split()]

ans = 0

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

print(ans%1000000007)

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

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

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

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] 
    ans %= mod
print(ans)

Submission status: Time Limit Exceeded

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 += int(bin(A[i]^A[j]), 2)

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

Submission status: Time Limit Exceeded

Solution code:
import sys
input = sys.stdin.readline

N = int(input())
M = 60
*A, = map(lambda x: (bin(int(x))[2:].zfill(M))[::-1],input().split())
A = [list(map(int,a)) for a in A]

mod = 10**9+7

c = [0]*M
for a in A:
    for i,n in enumerate(a):
        if n:c[i]+=1

ans = 0
for a in A:
    for i,n in enumerate(a):
        if n:
            ans += ((1<<i)%mod)*(N-c[i])%mod
        else:
            ans += ((1<<i)%mod)*c[i]%mod
        ans %= mod

ans *= (mod+1)//2
ans %= mod
print(ans)

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

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

num = 1000000007

sum = 0
for i in range(N+1):
    for j in range(i+1, N):
        sum += data[i] ^ data[j]
        if sum > num:
            sum %= num

print(sum)

Submission status: Time Limit Exceeded

Solution code:
#%%
inf = 10**9 + 7

n = int(input())
a = list(map(int, input().split()))
count = [0] * 70
for i in range(n):
    tmp = list(str(bin(a[i])[2:]))[::-1]
    #print(tmp)
    for j in range(len(tmp)):
        if tmp[j] == '1':
            k = 69 - j
            count[k] += 1

#print(count)

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:
MOD = 10**9+7
N = int(input())
A = list(map(int, input().split()))
s = 0
for i in range(N-1):
    for j in range(i+1, N):
      s = (s + (A[i]^A[j])) % MOD
print(s)

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:
def main():
    def accumulate(array):
        for i in range(len(array) - 1):
            array[i + 1] += array[i]
        return array

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

    X = [[0] * N for i in range(61)]
    for i, a in enumerate(A):
        for j in range(61):
            if (1 << j) & a:
                X[j][i] = 1

    for i in range(61):
        X[i] = accumulate(X[i])


    ans = 0
    for i, a in enumerate(A):
        for j in range(61):
            x = X[j][-1] - X[j][i]
            if (1 << j) & a:
                ans += (1 << j) * ((N - i - 1) - x)
                ans %= MOD

            else:
                ans += (1 << j) * x
                ans %= MOD


    print(ans % MOD)


if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
a=list(map(int,input().split()))
mod=10**9+7
cnt=[]
for i in range(60):
	p=0
	for j in range(n):
		if a[j]%2==1:
			p+=1
		a[j]//=2
	cnt.append(p)
ans=0
for i in range(60):
	ans+=(n-cnt[i])*cnt[i]*(2**i)
	ans%=10**9+7
print(ans)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
#coding: utf-8
# from bisect import bisect_left
# from decimal import Decimal

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

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

print(ans%1000000007)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())

l = [int(i) for i in input().split()]

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

Submission status: Time Limit Exceeded

Solution code:
#D
mod = 10**9+7
N = int(input())
A = list(map(int,input().split()))

B = []
for a in A:
    b = bin(a)
    b = b.lstrip("0b")
    while len(b) < 60:
        b = "0"+b
    B.append(b)
    
ans = 0
for i in range(60):
    rui = [0]
    for b in B:
        if b[i] == "1":
            rui.append(rui[-1]+1)
        else:
            rui.append(rui[-1])
    
    N1 = rui[N]
    kari = 0
    for j,b in enumerate(B):
        if b[i] == "1":
            kari+=(N-j-1)-(N1-rui[j+1])
        else:
            kari+=(N1-rui[j+1])
    ans+=kari*(2**(59-i))
    ans%=mod
print(ans)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
M = 60
*A, = map(lambda x: (bin(int(x))[2:].zfill(M))[::-1],input().split())
A = [list(map(int,a)) for a in A]

mod = 10**9+7

c = [0]*M
for a in A:
    for i,n in enumerate(a):
        if n:c[i]+=1

ans = 0
for a in A:
    for i,n in enumerate(a):
        if n:
            ans += ((1<<i)%mod)*(N-c[i])%mod
        else:
            ans += ((1<<i)%mod)*c[i]%mod
        ans %= mod

ans *= (mod+1)//2
ans %= mod
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import itertools

divisor = (10 ** 9) + 7

N = int(input())
numbers = [int(i) for i in input().split()]
combinations = list(itertools.combinations(numbers, 2))

xors = [c[0] ^ c[1] for c in combinations]

output = sum(xors) % divisor
print(output)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
A = list(map(int, input().split()))
M = 10**9+7
ans = 0

for i in range(61):
    b = 1<<i
    count = 0
    for a in A:
        c = a & b
        if c != 0:
            count += 1
    ans += b*count*(N-count)

print(ans%M)

Submission status: Time Limit Exceeded

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

sum_A = 0

for i in range(1,N):
    for j in range(i+1,N+1):
        sum_A +=int(bin(A_list[i-1] ^ A_list[j-1]),2)

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

Submission status: Time Limit Exceeded

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

print(result%(1000000000+7))

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
lists=list(map(int,input().split()))
length=61
use=[0 for i in range(61)]
for  j in range(n):
    k=format(lists[j],"0%ib"%length)
    k=k[::-1]
    for some in range(len(k)):
        use[some]+=int(k[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 math

N = int(input())
A = [int(i) for i in input().split()]
maxA = max(A)
if maxA == 0:
    print(0)
else:   
    digs = int(math.log(maxA, 2)+1)
    count = [0] * digs
    
    for A_i in A:
        A_bit = format(A_i, 'b')
        for j in range(len(A_bit)):
            count[j] += int(A_bit[len(A_bit)-1-j])
    total = 0
    for i in range(digs):
        total += (2**i * count[i] * (N - count[i])) % 1000000007
        
    print(total % 1000000007)

Submission status: Time Limit Exceeded

Solution code:
# coding: utf-8
# Your code here!

from collections import deque

N = int(input())
A = deque(list(map(int,input().split())))
tmp, ans = 0, 0

for i in range(N):
    if A == deque([]):
        break
    tmp = A.popleft()
    for j in range(N - i - 1):
        ans += tmp ^ A[j]
print(ans % (pow(10,9) + 7))

Submission status: Time Limit Exceeded

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

print(s % m)

Submission status: Time Limit Exceeded

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

s = 0
for i in range(N - 1):
    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=list(map(int,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()))
ans = 0
for i in range (0,N):
  for j in range (i+1,N):
    ans = ans + (A[i] ^ A[j])
print(ans % (1000000007))

Submission status: Time Limit Exceeded

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

total = 0

for i in range(len(a)-1):
    for j in range(i+1, len(a)):
        total += a[i] ^ a[j]

result = total % (10 ** 9 + 7)

print(result)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

lis = [0]*60

for a in A:
    for i in range(60):
        lis[i] += a%2
        a = a //2
        if a == 0:
            break

ans = 0
for i, j in enumerate(lis):
    ans += j * (N-j) *(2**i)
    ans = ans % (10**9 + 7)

print(ans)

Submission status: Time Limit Exceeded

Solution code:
def main():
    from itertools import accumulate
    N = int(input())
    A = list(map(int, input().split()))
    MOD = 10 ** 9 + 7

    X = [[0] * N for i in range(61)]
    for i, a in enumerate(A):
        for j in range(61):
            if (1 << j) & a:
                X[j][i] = 1

    for i in range(61):
        X[i] = list(accumulate((X[i])))


    ans = 0
    for i, a in enumerate(A):
        for j in range(61):
            x = X[j][-1] - X[j][i]
            if (1 << j) & a:
                ans += (1 << j) * ((N - i - 1) - x)
                ans %= MOD

            else:
                ans += (1 << j) * x
                ans %= MOD


    print(ans % MOD)


if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
from itertools import combinations
from operator import xor
from functools import lru_cache


@lru_cache(maxsize=None)
def xor_w_cache(x, y):
    _xor = xor
    return _xor(x, y) % R


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

print(sum(xor_w_cache(x, y) for x, y in combinations(A, 2)) % R)

Submission status: Time Limit Exceeded

Solution code:
import sys
sys.setrecursionlimit(1000000000)
from itertools import count
from functools import lru_cache
from collections import defaultdict
from pprint import pprint
ii = lambda: int(input())
mis = lambda: map(int, input().split())
lmis = lambda: list(mis())
INF = float('inf')
N1097 = 10**9 + 7

def meg(f, ok, ng):
    while abs(ok-ng)>1:
        mid = (ok+ng)//2
        if f(mid):
            ok=mid
        else:
            ng=mid
    return ok
#

def main():
    N = ii()
    S1 = [0] * 100
    for a in mis():
        b = 1
        for i in count():
            if b > a:
                break
            if a & b:
                S1[i] += 1
            b <<= 1
    ans = 0
    b = 1
    for i in range(len(S1)):
        s1 = S1[i]
        s0 = N - s1
        ans += (s1*s0) * (b%N1097)
        ans %= N1097
        b <<= 1

    print(ans)




main()

Submission status: Time Limit Exceeded

Solution code:
N=int(input())
import itertools
L=list(map(int,input().split()))
CM = itertools.combinations(L, 2)
ANS = 0
MD = 10**9 + 7
for s in list(CM):
  ANS += (s[0] ^ s[1])

if ANS >= MD:
  print(ANS % MD)
else:
  print(ANS)