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:
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 = [[0 for _ in range(msb)] for _ in range(n)]

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

for i in range(1, n):
    for s in range(msb):
        t[i][s] = 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]
        if a[i] & (1 << s) == 0:
            ans += (1 << s) * stand
            ans %= (10 ** 9 + 7)
        else:
            no_stand = (n - (i + 1)) - stand
            ans += (1 << s) * no_stand
            ans %= (10 ** 9 + 7)
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):
        k=0
        if a[i]>a[j]:
            m=a[i]
            s1=a[j]
        else:
            m=a[j]
            s1=a[i]
        while s1>0:
            if m%2!=s1%2:
                s+=2**k
            m=m//2
            s1=s1//2
            k+=1
        s+=m*(2**k)
print(s%(10**9+7))

Submission status: Time Limit Exceeded

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

cnt = 0
#count = 0

for i in range(n-1):
  for j in range(i+1, n):
    cnt += (A[i] ^ A[j]) % (10** 9 + 7)
    #count += 1
    
print(cnt % (10** 9 + 7))

Submission status: Time Limit Exceeded

Solution code:
int_i = int(input())
result = 0
s_x = input().split(' ')
i_x = list([int(n) for n in s_x])
for i in range(int_i):
    for hoge in i_x[i + 1:]:
        if i_x[i] == hoge:
            continue
        result += int(bin(i_x[i] ^ hoge), 2)
print(result % (10 ** 9 + 7))

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
N = int(input())

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

bin_list = [0 for i in range(60)]

for i in range(N):
    for j in range(len(bin(A[i]))-2):
        if bin(A[i])[-(j+1)] == '1':
            bin_list[j] += 1

div = 1000000007

ans = 0

for i in range(60):
    ans += (bin_list[i] * (N-bin_list[i]) % div) * ((1 << i) % div) % div
    ans = ans % div

print(ans)

Submission status: Time Limit Exceeded

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

    result = 0

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

if __name__ == '__main__':
    abc147_d()

Submission status: Time Limit Exceeded

Solution code:
# coding: utf-8
from itertools import combinations

line = int(input().rstrip())
x = input().rstrip().split(' ')
xors = combinations(x, 2)
print(sum(int(xor[0]) ^ int(xor[1]) for xor in xors) % (10 ** 9 + 7))

Submission status: Time Limit Exceeded

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

l = (10 ** 9) + 7

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

print(res % l)

Submission status: Time Limit Exceeded

Solution code:
import itertools
def main():
    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] 
    print((sum(count) % (10**9+7)))

if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

Solution code:
import itertools
MOD = 1000000007
s = 0
n = int(input())
a = list(map(int, input().split()))
b = list(itertools.combinations(a, 2))
for c in b:
	s += c[0]^c[1]
	s = s % MOD
print(s)

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, N):
        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()))
l=[0]*60
for a in A:
    a_2=bin(a)
    for i in range(60):
        if a_2[-i-1]=="1":
            l[i]+=1
        if a_2[-i-1]=="b":
            break
ans=0
k=1
for i in range(60):
    ans=(ans+(k*l[i]%1000000007)*(n-l[i])%1000000007)%1000000007
    k=(k*2)%1000000007
print(ans)

Submission status: Time Limit Exceeded

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

INF = 10**9 + 7

res = 0

for i in range(N-1):
    for j in range(i+1,N):
        res += A[i] ^ A[j]
        res %= INF

print(res)

Submission status: Time Limit Exceeded

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

print(Sum)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
A = list(map(int,input().split()))
MOD = 10**9 + 7
for i in range(n):
  b = format(A[i],'b').zfill(61)
  A[i] = b


bit = [0]*61
for i in range(n):
  for j in range(61):
    if A[i][j] =='1':
      bit[j] += 1

ans = 0
for k in range(61):
  multi = ((bit[k]%MOD)*(n-bit[k])%MOD)%MOD
  if k > 30:
    ans += (((2**(60-k))%MOD) * multi)%MOD
  else:
    ooo = ((2**(30-k))%MOD * (2**20)%MOD * (2**10)%MOD) %MOD
    ans += (ooo * multi)%MOD
  ans %= MOD
print(ans)

Submission status: Time Limit Exceeded

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

  result = 0
  for b in range(60):
    B = 1 << b
    a = [(e >> b) & 1 for e in A]
    bs = [0] * N
    bs[N - 1] = a[N - 1]
    for i in range(N - 2, -1, -1):
      bs[i] = bs[i + 1] + a[i]

    for i in range(N - 1):
      if a[i] == 0:
        t = bs[i + 1]
      else:
        t = (N - (i + 1)) - bs[i + 1]
      result = (result + t * B) % 1000000007
  print(result)
main()

Submission status: Time Limit Exceeded

Solution code:
# -*- coding: utf-8 -*-
N = int(input())
A = list(map(int, input().split()))

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
N=int(input())
MOD=10**9+7
L=60
ls=[int(s) for s in input().split()]
bils=[]
for i in range(N):
  val_ls=[0 for j in range(L)]
  for j in range(L):
    if (2**j)&ls[i]>0:
      val_ls[j]=1
  bils.append(val_ls)
bisumls=[[0 for _ in range(L)] for _ in range(N)]
bisumls[N-1]=bils[N-1]
for i in range(2,N):
  for j in range(L):
    bisumls[-i][j]=bisumls[-i+1][j]+bils[-i][j]
#[[0, 0, 0], [3, 0, 2], [2, 0, 2], [2, 0, 1], [1, 0, 1]]
ans=0
for i in range(N-1):
  base=1
  #print(bils[i],bisumls[i+1])
  for k in range(L):
    if bils[i][k]==1:
      a=N-i-1-bisumls[i+1][k]
    else:
      a=bisumls[i+1][k]
   #   print(a)
    ans+=a*base
    base*=2
  #  print(ans,a,k)
  ans=ans%MOD
print(ans)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
A = list(map(int,input().split()))
d = []
num = 10**9 + 7
for i in range(N-1):
    #print(i)
    for j in range(i+1,N):
        #print(j)
        b = A[i] ^ A[j]
        #b %= num
        d.append(b)
print(sum(d)%num)

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
mod = 10**9+7
n = int(input())
a = [int(x) for x in input().split()]
a = np.array(a)
count = 0


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

count = count%(mod)
print(count)

Submission status: Time Limit Exceeded

Solution code:
# encoding:utf-8
import copy
import random
import bisect #bisect_left　これで二部探索の大小検索が行える
import fractions #最小公倍数などはこっち
import math
import sys
import bisect

mod = 10**9+7
sys.setrecursionlimit(mod) # 再帰回数上限はでdefault1000

def LI(): return list(map(int, sys.stdin.readline().split()))

N = int(input())
A = LI()

count_list = [0 for i in range(61)]
def counts(count_list, a):
    for i in range(61):
        count_list[i] += a % 2
        a = a // 2
    return count_list

A.reverse()
ans = 0
for i in range(N-1):
    count_list = counts(count_list, A[i])
    # print(count_list)
    hikaku = counts([0 for i in range(61)], A[i + 1])
    # print(i)
    for j in range(61):
        if hikaku[j] == 1:
            ans += (i+1 - count_list[j]) * 2 ** j % mod
        else:
            ans += count_list[j] * 2 ** j % mod
        ans = ans % mod
print(ans)

Submission status: Time Limit Exceeded

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

X=0
for i in range(N-1):
    for j in range(N):
        if (j > i):
            X+= nums[i] ^ nums[j]
            
            
ans = X % (10**9 + 7)

print(str(ans))

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
lis=list(map(int,input().split()))
ans=0
for i in range(n):
    for j in range(n-1-i):
        m=0
        lislis=[lis[i],lis[i+1+j]]
        lislis.sort()
        lislis[0]=bin(lislis[0])
        lislis[1]=bin(lislis[1])
        x=len(lislis[0])-2
        for k in range(x):
            if lislis[0][len(lislis[0])-1-k]!=lislis[1][len(lislis[1])-1-k]:
                m+=1*(10**k)
        for l in range(len(lislis[1])-len(lislis[0])):
            if lislis[1][len(lislis[1])-x-1-l]=="1":
                m+=1*(10**(x+l))
        #print(m)
        ans+=int(str(m),2)

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

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]+1 if temp[j]=='1' else onekazu[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:
N = int(input())
A = list(map(int,input().split()))
T =[0 for k in range(60)]
F =[0 for k in range(60)]
c = 0
for k in range(N):
	S = format(A[k], '060b')
	for s in range(60):
		if S[s] == '1':
			T[s] +=1
		else:
			F[s] +=1
for k in range(60):
	c += (T[k]*F[k]*(2**(59-k)))
print(c%(10**9+7))

Submission status: Time Limit Exceeded

Solution code:
from sys import stdout
printn = lambda x: stdout.write(x)
inn = lambda : int(input())
inl   = lambda: list(map(int, input().split()))
inm   = lambda:      map(int, input().split())
DBG = True # and False
BIG = 999999999
R = 10**9 + 7

def ddprint(x):
  if DBG:
    print(x)

n = inn()
a = inl()
b = [ [0]*n for i in range(60) ]
acc = [ [0]*n for i in range(60) ]
sums = [0]*60
for bit in range(60):
    for i in range(n):
        b[bit][i] = (a[i]>>bit)&1
    acc[bit][n-1] = b[bit][n-1]
    for i in range(n-2,-1,-1):
        acc[bit][i] = acc[bit][i+1] + b[bit][i]
    for i in range(n-1):
        sums[bit] += acc[bit][i+1] if b[bit][i]==0 else \
                     (n-1-i-acc[bit][i+1])

x = 0
for bit in range(60):
    x = (x + sums[bit]*(2**bit)) % R
print(x)

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 = list(map(int, list(S.split())))
list.sort()

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

Submission status: Time Limit Exceeded

Solution code:
import sys
input = sys.stdin.readline
# sys.setrecursionlimit(100000)


class Solver(object):
    def __init__(self):
        pass

    def solve(self, n, arr):
        sum = 0
        bitcount = [0]*100
        for num in arr:
            b = reversed(list(bin(num))[2:])
            for i, s in enumerate(b):
                bitcount[i] += int(s)
        for i, b in enumerate(bitcount):
            sum += b * (n-b) * 2**i
        return sum % (10**9 + 7)


def main():
    N = int(input())
    A_l = [int(i) for i in input().split()]
    solver = Solver()
    print(solver.solve(N, A_l))


if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

Solution code:
# import sys
# input = sys.stdin.readline
n = int(input())
a = list(map(int,input().split()))
mod = 10**9 + 7
ans = 0
l = len(a)
for i in range(l-1):
    for j in range(i,l):
        if a[i]!=a[j]:
            ans += ( a[i]^a[j] ) % mod
print(ans%mod)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
N = map(int, input())
A = [x for x in 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 % (10**9+7))

Submission status: Time Limit Exceeded

Solution code:
import itertools

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

maxA = max(A)
bmaxA = format(maxA, 'b')
n_bmaxA = len(bmaxA)


cmb = itertools.combinations(A, 2)

ans = 0
for item in cmb:

    bfirst = format(item[0], '0{}b'.format(n_bmaxA))
    blast = format(item[1], '0{}b'.format(n_bmaxA))

    cXOR = []
    for i in range(len(bfirst)):
        if bfirst[i] == blast[i]:
            cXOR.append("0")
        else:
            cXOR.append("1")

    cXOR = ''.join(cXOR)
    ans += int(cXOR, 2)


base = 1000000000 + 7
print(ans % base)

Submission status: Time Limit Exceeded

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

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

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

Submission status: Time Limit Exceeded

Solution code:
mod = 10**9 + 7

def pow_k(x, n):
    """
    O(log n)
    """
    if n == 0:
        return 1
    K = 1
    while n > 1:
        if n % 2 != 0:
            K = (K * x) % mod 
            x = (x ** 2) % mod
            n = (n - 1) // 2
        else:
            x = (x ** 2) % mod
            n = n // 2

    return (K * x) % mod # 指数を割り続け n が 1 に至ったら終了

N = int(input())
A = list(map(int,input().split()))
cnt_1 = [0]*61
for i in range(N):
    A_tmp = A[i]
    for j in range(61):
        if (A_tmp >> j & 1):
            cnt_1[j] += 1
ans = 0
for i in range(61):
    ans += (cnt_1[i]*(N - cnt_1[i]) * pow_k(2,i)) % mod
print(ans % mod)

Submission status: Time Limit Exceeded

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

import itertools
L = list(itertools.combinations(A, 2))
for i in range(len(L)):
    S += L[i][0] ^ L[i][1]
      
print(S % MOD)

Submission status: Time Limit Exceeded

Solution code:
from collections import defaultdict

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

max_A = max(A)
j = 0
while max_A >> j > 0:
    j += 1
max_j = j

c = defaultdict(int)
ans = 0
MOD = 10 ** 9 + 7
for i in range(N - 2, -1, -1):
    Ai = A[i + 1]
    for j in range(max_j):
        c[(j, Ai >> j & 1)] += 1
    Ai = A[i]
    for j in range(max_j):
        ans += (1 << j) * c[(j, (Ai >> j & 1 ^ 1))]
        ans %= MOD
print(ans)

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])
    m = 10 ** 9 + 7
    if total < m:
        print(total)
    else:
        print(total % m)


if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
l = [int(x) for x in input().split()]
num_of_1 = [0] * 60
for i in range(N):
  S = str(format(l[i], 'b'))
  for i in range(len(S)):
    if S[-i-1] == '1':
      num_of_1[i] += 1
ans = 0
for i in range(60):
  ans += num_of_1[i] * (N - num_of_1[i]) * 2 ** i
  ans %= 1000000007
print(ans)

Submission status: Time Limit Exceeded

Solution code:
int_i = int(input())
result = list()
s_x = input().split(' ')
i_x = list([int(n) for n in s_x])
for i in range(int_i):
    for hoge in i_x[i + 1:]:
        if i_x[i] == hoge:
            continue
        result.append(int(bin(i_x[i] ^ hoge), 2))
print(sum(result) % (10 ** 9 + 7))

Submission status: Time Limit Exceeded

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

num = 0

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

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

Submission status: Time Limit Exceeded

Solution code:
def xor_sum_4(N: int, A: list)->int:
    MOD = 10**9 + 7
    MAX_POW = 60

    # bit_sum[i] := 2 進表記で i 桁目の値の和
    bit_sum = [sum((a >> i) & 1 for a in A) for i in range(MAX_POW)]

    ans = 0
    for a in A:
        N -= 1
        for i in range(MAX_POW):
            bit_sum[i] -= (a >> i) & 1
            if (a >> i) & 1 == 1:
                ans += ((1 << i) * (N-bit_sum[i])) % MOD
            else:
                ans += ((1 << i) * bit_sum[i]) % MOD
            ans %= MOD
    return ans


if __name__ == "__main__":
    N = int(input())
    A = list(map(int, input().split()))
    ans = xor_sum_4(N, A)
    print(ans)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

result = 0
for b in range(60):
  a = [(e >> b) & 1 for e in A]
  bs = [0] * N
  bs[N - 1] = a[N - 1]
  for i in range(N - 2, -1, -1):
    bs[i] = bs[i + 1] + a[i]

  for i in range(N - 1):
    if a[i] == 0:
      t = bs[i + 1]
    else:
      t = (N - (i + 1)) - bs[i + 1]
    result = (result + t * (1 << b)) % 1000000007
print(result)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

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

print(sum_a % 1000000007)

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 = [[0 for _ in range(msb) ] for _ in range(n)]

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

for i in range(1, n):
    for s in range(msb):
        t[i][s] = 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:
mod = 10**9+7
n = int(input())
a = [int(x) for x in input().split()]
count = 0


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

count = count%(mod)
print(count)

Submission status: Time Limit Exceeded

Solution code:
import copy
"""
n = int(input())
a = []
x = []
y = []
x_dash = []
y_dash = []
for i in range(n):
	a.append(int(input()))
	for _ in range(a[i]):
		x_dash_dash, y_dash_dash = map(int,input().split())
		x_dash.append(x_dash_dash)
		y_dash.append(y_dash_dash)
	tmp_x = copy.deepcopy(x_dash)
	tmp_y = copy.deepcopy(y_dash)
	x.append(tmp_x)
	y.append(tmp_y)
	x_dash.clear()
	y_dash.clear()

for i in range(n):
	A = [-1 for _ in range(n)]
	A[i] = 1
	for j in range(x[i]):
		A[x[i][j]] == y[i][j]
	c = 1
	while c == n:
		for k in range(x[i+c]):
			if A[i+c] == :

		if A[i+c] != -1:
			c += 1"""

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:
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):
    if temp[j]=='1':
      onekazu[j]+=1
    
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:
#!/usr/bin/env python3

N = int(input().split()[0])
a_list = list(map(int, input().split()))
t = 0
mod = 10 ** 9 + 7

for i in range(N - 1):
    for j in range(i + 1, N):
        t += a_list[i] ^ a_list[j]
        t = t % mod
ans = t

print(ans)

Submission status: Time Limit Exceeded

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

def calc(a,b):
	ans = int(bin(a^b),2)
	return ans
	
for i in range(N):
	for j in range(i+1,N):
		total += calc(int(A[i]),int(A[j]))
		
		
print(total % (1000000007))

Submission status: Time Limit Exceeded

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

ans = 0
for i, a in enumerate(A[:-1]):
    for b in A[i+1:]:
        ans = (ans + (a^b))%M

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-1):
    k=i+1
    for j in range(k,n):
        sum  += a[i]^a[j]
print(sum%(10**9+7))

Submission status: Time Limit Exceeded

Solution code:
a = int(input())
b=list(map(int,input().split()))
sum1=0
num = []
for i in range(a-1):
  for j in range(i+1,a):
    num.append(b[i]^b[j])
sum1=sum(num)
 
if sum1>=1000000007:
  sum1=sum1%1000000007

print(sum1)

Submission status: Time Limit Exceeded

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

MOD = 10**9+7

sum_num = 0
for i in range(60):
    o = 0
    for a in A:
        o += (a>>i)%2
    z = N - o
    sum_num = (sum_num + (o*z)*(1<<i)) % MOD

print(sum_num)

Submission status: Time Limit Exceeded

Solution code:
import collections
def main():

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

    ones = [0 for _ in range(60)]

    for i in range(N):
        for j in range(60):
            if (A[i] >> j) % 2 == 1:
                ones[j] += 1
    ans = 0
    for j in range(60):
        ans += pow(2, j) * ones[j] * (N - ones[j])
        ans %= mod

    return ans % mod


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

Submission status: Time Limit Exceeded

Solution code:

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 += a[i]^a[j]
print(sum%(10**9+7))

Submission status: Time Limit Exceeded

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

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]

for i, j in combinations(range(n), 2):
    # print(str(i)+str(j))
    ans += l[i] ^ l[j]

print(ans%1000000007)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
A = list(map(int, input().split()))
B = list()
ans = 0
for i in range(n - 1):
    for j in range(n - i - 1):
        b = A[i] ^ A[j + i + 1]
        B.append(b)
for i in range(len(B)):
    if ans + B[i] < 1000000007:
        ans += B[i]
    else:
        ans = (ans + B[i]) % 1000000007
print(ans)

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=bin(a)
    for i in range(60):
        if a_2[-i-1]=="1":
            l[i]+=1
        if a_2[-i-1]=="b":
            break
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:
import itertools

MOD = 10**9 + 7
n = int(input())
a = list(map(int, input().split()))
l = [i for i in range(n)]
com_l = list(itertools.combinations(l, 2))

ans = 0
for i in range(len(com_l)):
    ans += a[com_l[i][0]] ^ a[com_l[i][1]]
    ans = ans % MOD
print(ans)

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

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

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) :
		tmp = operator.xor(a[i], a[j])
		while tmp > 1000000007 :
			tmp -= 1000000007
		sum += tmp
while sum > 1000000007 :
	sum -= 1000000007
print(sum)

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):
        #print(a[i] ^ a[j])
        ans += (a[i] ^ a[j]) % mod

print(ans % mod)

Submission status: Time Limit Exceeded

Solution code:
import sys
import collections


def solve():
    readline = sys.stdin.buffer.readline
    mod = 10 ** 9 + 7
    n = int(readline())
    a = list(map(int, readline().split()))
    d = collections.defaultdict(int)
    for i in range(n):
        d[a[i]] += 1
    t = 0
    for v in a:
        d[v] -= 1
        if d[v] == 0:
            d.pop(v)
        for k2, v2 in d.items():
            t += (v ^ k2) * v2
            t %= mod
    print(t)


if __name__ == '__main__':
    solve()

Submission status: Time Limit Exceeded

Solution code:
# -*- coding: utf-8 -*-
import bisect
import heapq
import math
import random
import sys
from collections import Counter, defaultdict, deque
from decimal import ROUND_CEILING, ROUND_HALF_UP, Decimal
from functools import lru_cache, reduce
from itertools import combinations, combinations_with_replacement, product, permutations
from operator import add, mul, sub

sys.setrecursionlimit(100000)
input = sys.stdin.readline
INF = 2**62-1

def read_int():
    return int(input())


def read_int_n():
    return list(map(int, input().split()))


def read_float():
    return float(input())


def read_float_n():
    return list(map(float, input().split()))


def read_str():
    return input().strip()


def read_str_n():
    return list(map(str, input().split()))


def error_print(*args):
    print(*args, file=sys.stderr)


def mt(f):
    import time

    def wrap(*args, **kwargs):
        s = time.time()
        ret = f(*args, **kwargs)
        e = time.time()

        error_print(e - s, 'sec')
        return ret

    return wrap


class Mod:
    def __init__(self, m):
        self.m = m

    def add(self, a, b):
        return (a + b) % self.m

    def sub(self, a, b):
        return (a - b) % self.m

    def mul(self, a, b):
        return ((a % self.m) * (b % self.m)) % self.m

    def div(self, a, b):
        return self.mul(a, pow(b, self.m-2, self.m))

    def pow(self, a, b):
        return pow(a, b, self.m)

@mt
def slv(N, A):
    ans = 0
    M = Mod(10**9+7)
    for i in range(0, 60):
        m = 1 << i
        b0 = []
        b1 = []
        for j, a in enumerate(A):
            if m & a > 0:
                b1.append(j)
            else:
                b0.append(j)
        for j, a in enumerate(A):
            c = m & a
            if c > 0:
                d = b0
            else:
                d = b1
            k = bisect.bisect_left(d, j)

            ans = M.add(M.mul(len(d)-k, (1<<i)), ans)
    return ans


def main():
    N = read_int()
    A = read_int_n()
    print(slv(N, A))


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

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
A = [int(x) for x in input().split()]
res = 0
for i in range(N-1):
    for j in range(i+1, N):
        x1 = [0]*61
        y1 = bin(A[i])[2:]
        for n in range(len(y1)):
            x1[n] = int(y1[len(y1)-1-n])
        x1 = x1[::-1]
        x2 = [0]*61
        y2 = bin(A[j])[2:]
        for n in range(len(y2)):
            x2[n] = int(y2[len(y2)-1-n])
        x2 = x2[::-1]
        new_ = "0b"
        t = False
        for k in range(61):
            u = (x2[k]+x1[k])%2
            if u == 1:
                t = True
            if t:
                new_ += str(u)
        if new_ != "0b":
            res = (res + int(new_,2))%(10**9+7)
print(res)

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
a_lis=list(map(int,input().split()))
ans=0
for i in range(1,n):
    for j in range(i+1,n+1):
        a1=a_lis[i-1]
        a2=a_lis[j-1]
        c=a1^a2
        ans+=c
print(ans%1000000007)

Submission status: Time Limit Exceeded

Solution code:
import itertools

waru = 10**9 + 7
ans = 0
_ = input()
a = list(map(int,input().split()))
for i,j in itertools.combinations(a,2):
    ans = (ans + (i^j)) % waru
print(ans)

Submission status: Time Limit Exceeded

Solution code:
num = int(input())

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

ans = 0

for i in range(0,num-1):
    for j in range(i+1,num):
        c = arr[i] ^ arr[j]
       
        ans += (c % 1000000007)
        

print(ans% 1000000007)