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())
l=map(int,input().split())
dic=dict(zip(range(n),l))
ans=0
for i in range(n):
    for j in range(i,n):
        if i == j:
            continue
        ans+=dic[i]^dic[j]
print(ans%(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(1,n):
    for j in range(i+1, n+1):
        total += A[i-1] ^ A[j-1]
print(total%(10**9+7))

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

sums = 0
k = {}
for x in itertools.combinations(a, 2):
    if ((x[0], x[1]) in k.values()):
        sums += k[x[0], x[1]]
    else:
        r =int(bin(x[0] ^ x[1]), 2)
        k.setdefault((x[0], x[1]), r)
        sums += r

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

Submission status: Time Limit Exceeded

Solution code:
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**8)
mod = 10**9+7
 

def main():
    n=int(input())
    a=list(map(int, input().split()))
    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]
        for k in range(60,-1,-1):
            if y>=pre[k]:
                y-=pre[k]
                z[k]+=1
        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:
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 = bin(A_i)
        for j in range(len(A_bit)-2):
            if A_bit[len(A_bit)-1-j] == '1':
                count[j] += 1
    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:
import itertools
def main():
    S = int(input())
    a = [int(i) for i in input().split()]
    x = 10 ** 9
    
    xor = 0
    patern = list(itertools.combinations(a, 2))
    for p in patern:
        xor += p[0] ^ p[1]
    if xor >= x:
        print(xor % (x + 7))
    else:
        print(xor)
 
if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
MOD=10**9+7

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

#print(alist)
blist=[0]*64
for a in alist:
  bblist=[]
  acopy=a
  while(acopy>0):
    bblist.append(acopy%2)
    acopy//=2
    
  #print(bblist)
  for b in range(len(bblist)):
    blist[-1-b]+=bblist[b]
      
blist.reverse()
#print(blist)
answer=0
pow=1
for i in range(64):
  answer+=blist[i]*(N-blist[i])*pow
  pow*=2
  
print(answer%MOD)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
li_a = list(map(int, input().split()))
li_b = []
for x in reversed(li_a):
  li_b.append(x)
a = 0
mod = 10**9 + 7
for i in range(n-1):
  b = li_b.pop()
  for x in li_b:
    a += b^x
print(a%mod)

Submission status: Time Limit Exceeded

Solution code:
from scipy.misc import comb
mod = 10 ** 9 + 7
n = int(input())
lis = list(map(int, input().split()))
ans = 0
x = comb(n, 2, exact=True)
for i in range(60):
    temp = 0
    for j in range(n):
        if format(lis[j],'060b')[i] == "1":
            temp += 1
    ans += 2**(59-i)*(x - comb(n-temp, 2, exact=True)-comb(temp, 2, exact=True))
ans %= mod
print(ans)

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
s=list(map(int,input().split()))
mod=1000000007
goukei=0
for i in s:
  l=[i^k for k in s]
  goukei+=sum(l)
kotae=(goukei//2)%mod
print(kotae)

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

Submission status: Time Limit Exceeded

Solution code:
N = int(raw_input())
s = raw_input().split()
A = [0 for i in range(N)]
for i in range(N):
    A[i] = int(s[i])

#print A

M = 1000000007

#print M

xor = 0
for i in range(N-1):
    for j in range(i+1,N):
        #print i,j
        #print A[i],A[j]
        xor += A[i]^A[j] #(bin(A[i])^bin(A[j]))

print xor % M

Submission status: Time Limit Exceeded

Solution code:
from itertools import combinations
n = int(input())
ans = 0
for i, j in list(combinations(list(map(int, input().split())), 2)):
    ans += i ^ j
print(ans % (10 ** 9 + 7))

Submission status: Time Limit Exceeded

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

dp = [[0 for i in range(61)] for i in range(n)]
for i in range(n):
  for j in range(61):
    if (a[i] >> j) & 1: dp[i][j] = 1


ans = 0
for j in range(61):
  cnt_0 = 0
  cnt_1 = 0
  cnt = 0
  for i in range(n):
    if dp[i][j] == 0:
      cnt += cnt_1
      cnt_0 += 1
    else:
      cnt += cnt_0
      cnt_1 += 1
    
  p = 2**j
  ans = (ans + cnt*p) % 1000000007

print(ans)

Submission status: Time Limit Exceeded

Solution code:
import numpy as np

N = int(input())
A = list(input().split())
d_to_num1 = {}
len_a = []
for i in range(N):
    a = list(bin(int(A[i]))[2:])
    len_a.append(len(a))
    for j,b in enumerate(reversed(a)):
        if b=='1':
            if not(j in d_to_num1.keys()):
                d_to_num1[j]=1
            else:
                d_to_num1[j]+=1 
max_len = max(len_a)
        
if __name__ == "__main__":

    res = 0
    mod = 10**9+7

    for i in range(max_len):
        if not(i in d_to_num1.keys()):
            num_1 = 0
        else:
            num_1 = d_to_num1[i]
        num_0 = N-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())
x = list(map(int, input().split()))

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

print(res%1000000007)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

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

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

Submission status: Time Limit Exceeded

Solution code:
import sys
F = 10**9+7
n = int(input())
s = sys.stdin.readline().split()
s_ = [int(i) for i in s]
ss = [bin(i) for i in s_]
ans = 0
for i in range(n-1):
  for j in range(n-1-i):
    ans+=(int(s[i])^int(s[i+j+1]))
    
print(ans%F)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

B =[]
answer = 0
for i in range(N):
    n = list(bin(A[i]))
    del n[0]
    del n[0]
    B.append(n)

for i in range(N):
    for j in range(i+1,N):
        if len(B[i]) > len(B[j]):
            sa = len(B[i]) - len(B[j])
            for n in range(len(B[j])):
            #print(m-n)
                #print(B[i][n+sa],B[j][n])
                if B[i][n+sa]!=B[j][n]:
                    answer += 2**(len(B[j])-n-1)
            for l in range(sa):
                answer += int(B[i][l])*(2**(len(B[i])-l-1))
        if len(B[i]) < len(B[j]):
            sa = len(B[j]) - len(B[i])
            for n in range(len(B[i])):
            #print(m-n)
            #print(B[i][m-n],B[j][m-n])
                #print(i,j,n,sa,B[j][n+sa],B[i][n])
                if B[j][n+sa]!=B[i][n]:
                    answer += 2**(len(B[i])-n-1)
            for l in range(sa):
                answer += int(B[j][l])*(2**(len(B[j])-l-1))
        if len(B[i]) == len(B[j]):
            for n in range(len(B[i])):
                if B[j][n]!=B[i][n]:
                    answer += 2**(len(B[i])-n-1)


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

Submission status: Time Limit Exceeded

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

if __name__ == '__main__':
    main()

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]) % MOD for i in range(N-1) for j in range(i+1, N))

print(ans % MOD)

Submission status: Time Limit Exceeded

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

def xor(x, y):
    X = bin(max(x, y))[2:]
    Y = bin(min(x, y))[2:]
    w = str(int(X)+int(Y))
    ans = 0
    for i in reversed(range(len(w))):
        if w[i] == "1":
            ans += 2**(len(w)-1-i)
    return ans % mod


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

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
A = list(map(int, input().split()))
ans = 0
t = 0
u = 0
for i in range(60):
    if max(A) >= 2**i:
        u += 1
    else: break
for i in range(u):
    for j in range(N):
        if A[j] >= 2 ** i:
            t += ((A[j]%(2**(i+1)))//(2**i))
    ans += (t * (N-t)) * 2**i
    t = 0
print(ans%1000000007)

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]*64
        for num in arr:
            b = reversed(bin(num)[2:])
            for i, s in enumerate(b):
                if i != "0":
                    bitcount[i] += int(s)
        for i, b in enumerate(bitcount):
            if b == 0:
                continue
            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))
    sys.exit()


if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

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

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

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

Submission status: Time Limit Exceeded

Solution code:
import itertools

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

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

cmb = itertools.combinations(A, 2)

ans = 0
for item in cmb:

    if item[0] == item[1]:
        ans += 0
    else:
        bfirst = format(item[0], '0{}b'.format(n_bmaxA))
        blast = format(item[1], '0{}b'.format(n_bmaxA))

        cXOR = 0
        for i in range(len(bfirst)):
            if bfirst[i] != blast[i]:
                cXOR += 2**(len(bfirst)-1 -i)
        ans += cXOR


base = 1000000000 + 7
print(ans % base)

Submission status: Time Limit Exceeded

Solution code:
def main():
    n = int(input())
    a = list(map(int, input().split()))
    mod = int(10e8+7)
    ans = 0
    for i in range(n):
        for j in range(i+1,n):
            s = a[i]
            t = a[j]
            s ^= t
            ans += s%mod
    ans = ans%mod
    print(ans)



if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

Solution code:
#!/usr/bin/env python3
import sys

MOD = 1000000007  # type: int

def solve(N: int, A: "List[int]"):
    mLEN = len(format(max(A),'b'))
    bA = [[0]*N for _ in range(mLEN)]

    for i in range(N):
        a = format(A[i],'b').zfill(mLEN)
        for k in range(mLEN):
            bA[k][i] = a[k]

    answer = 0
    for keta in range(mLEN):
        zero = bA[keta].count('0')
        one = N-zero
        a = 0

        for i in range(N):
            if bA[keta][i] == '1':
                one -= 1
            else:
                zero -= 1

            if bA[keta][i] == '1':
                a += zero
            else:
                a += one
        answer += a*2**(mLEN-1-keta)
        answer %= MOD
    
    print(answer%MOD)
    return


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    A = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    solve(N, A)

if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

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

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

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

if __name__ == '__main__':
    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:
n=int(input())

l=10**9+7
numlist=[format(int(i),"060b") for i in input().split(" ")]
# print(numlist)


def xor(a,b):
    c=[]
    for i in range(60):
        if a[i]!=b[i]:
            c.append("1")
        else:
            c.append("0")
    c="".join(c)
    c=int(c, 2)
    return c
    
        

ans=0
for i in range(n-1):
    for j in range(i+1,n):
        ans+=xor(numlist[i],numlist[j])
    ans=ans%l
print(ans)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
a = list(map(int, input().split()))
a.reverse()
mod = 7 + 10**9
leng = 61
data = [[0 for i in range(leng+1)]for j in range(n)]
#pre
for i in range(n):
    k = bin(a[i])
    k = k[::-1]
    for j in range(1, leng+1):
        if j - 1 >= len(k):
            data[i][j] = data[i - 1][j]
            continue
        if k[j - 1] == "1":
            data[i][j] = data[i - 1][j] + 1
        else:
            data[i][j] = data[i-1][j]
ans = 0
a.reverse()
data.reverse()
for i in range(n-1):
    k = bin(a[i])
    k = list(map(int, list(k[:1:-1])))
    k = k + [0 for i in range(leng - len(k))]
    for j in range(leng):
        if k[j] == 1:
            ans += ((n - i - 1) - data[i+1][j+1]) * (2**j)
            ans %= mod
        else:
            ans += data[i+1][j+1] * (2**j)
            ans %= mod
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import itertools

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

total = 0
for x, y in itertools.combinations(a, 2):
    total += x ^ y
    
result = total % (10 ** 9 + 7)

print(result)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
a = list(map(int, input().split()))
L = len(format(max(a), 'b'))
x = [[0 for j in range(2)] for i in range(L)]
ans = 0
MOD = 10 ** 9 + 7
for i in a:
    i_str = list(format(i, '0' + str(L) + 'b'))[::-1]
    for j, s in enumerate(i_str):
        x[j][int(s)] += 1
b = 1
for i, (x0, x1) in enumerate(x):
    ans += x0 * x1 * b % MOD
    ans %= MOD
    b *= 2
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(n-i-1):
        s=s+(a[i] ^ a[j+i+1])
print (s%(10**9+7))

Submission status: Time Limit Exceeded

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

z=0
m=10**9+7

for i in range(0,N-1):
  for j in range(i+1,N):
#    print(i,j)
#    print(a[i],a[j])
    z+=(int(a[i])^int(a[j]))
print(z%m)

Submission status: Time Limit Exceeded

Solution code:
MOD = 10**9 + 7
n = int(input())
a = list(map(int, input().split()))
for i in range(n):
    a[i] = format(a[i], '060b')
s = 0
for i in range(60):
    c = 0
    for j in range(n):
        if a[j][i] == '0':
            c += 1
    s += pow(2,59-i,MOD)*c*(n-c)%MOD
print(s%MOD)

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
n = int(input())
A_list = np.array([[i for i in bin(int(A))[2:].zfill(61)] for A in input().split()])
ans = 0

for i in range(61):
  one = np.count_nonzero(A_list[:,i]=="1")
  ans += 2**(60-i) * one * (n-one)
  ans %= 10**9+7

print(ans)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
A = tuple(map(int,input().split()))
b = 0
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
if b >= num:
    print(b%num)
else:
    print(b)

Submission status: Time Limit Exceeded

Solution code:
def main():
    n=int(input())
    ans=0
    bit=[0]*60
    seki=10**9+7
    a=list(map(int,input().split()))
    for i in range(n):
        for j in range(60):
            if a[i]%2==1:
                bit[j]+=1
            a[i]=a[i]>>1
    for i in range(60):
        ans+=(bit[i]*(n-bit[i]))*(2**i)
    print(ans%seki)
main()

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
a = list(map(int, input().split()))
c = [0 for _ in range(len(bin(max(a))) - 2)]
len_c = len(c)
ans = 0
mod = 10**9 + 7
for i in range(n):
  b = bin(a[i])[2:]
  binlist = list('0' * (len_c - len(b)) + b)
  for j in range(len_c):
    power = 2**(len_c-j-1)
    if binlist[j] == '0':
      ans = (ans + c[j] * power) % mod
    else:
      ans = (ans + (i - c[j]) * power) % mod
      c[j] += 1
print(ans)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
A = list(map(int, input().split()))
one = [0 for _ in range(60)]

for a in A:
    for i in range(60):
        if a & 1 << i:
            one[i] += 1
ans = 0
for j, a in enumerate(A):
    n -= 1
    if n == 0:
        break
    for i in range(60):
        if a & 1 << i:
            one[i] -= 1
    # print(one)

    for i in range(60):
        if a & 1 << i:
            ans += (1 << i) * (n - one[i])
        else:
            ans += (1 << i) * one[i]


print(ans % 1000000007)

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
mod=10**9+7
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]
  ans%=mod
print(ans)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
a = list(map(int, input().split()))
L = len(format(max(a), 'b'))
x = [[0 for j in range(2)] for i in range(L)]
ans = 0
MOD = 10 ** 9 + 7
for i in a:
    i_str = list(format(i, '0' + str(L) + 'b'))[::-1]
    for j, s in enumerate(i_str):
        x[j][int(s)] += 1
for i, (x0, x1) in enumerate(x):
    ans += x0 * x1 * 2 ** i % MOD
    ans %= MOD
print(ans)

Submission status: Time Limit Exceeded

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


def xor(x, y):
    X = bin(max(x, y))[2:]
    Y = bin(min(x, y))[2:]
    w = str(int(X)+int(Y))
    ans = 0
    for i in reversed(range(len(w))):
        if w[i] == "1":
            ans += 2**(len(w)-1-i)
    return ans


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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Num = 10**9 +7

ans = 0

for i in range(n-1):
    for j in range(i, n):
        ans += ls_a[i] ^ ls_a[j]
    
print(ans % Num)

Submission status: Time Limit Exceeded

Solution code:
import itertools

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

s = [0]*10**5
p = itertools.combinations(a,2)
s = [v[0]^v[1] for v in p]
  
t = sum(s)
print(t%mod)

Submission status: Time Limit Exceeded

Solution code:
MOD = 1000000007
s = 0
n = int(input())
a = list(map(int, input().split()))
last = n - 1
for i in range(last):
	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())
l=list(map(int,input().split()))
dic=dict(zip(range(n),l))
ans=0
for i in range(n):
    for j in range(i,n):
        if i == j:
            continue
        ans+=dic[i]^dic[j]
print(ans%(10**9+7))

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(bin(num)[2:])
            for i, s in enumerate(b):
                if i != "0":
                    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 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):
        if a <= 0:
            break
        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])
    hikaku = counts([0 for i in range(61)], A[i + 1])
    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())
a = list(map(int, input().split()))

res = 0

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

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
A = input().split()
total = 0
import itertools
		
		
for i in itertools.combinations(A,r=2):
	total += int(bin(int(i[0])^int(i[1])),2)
	
print(total % (1000000007))

Submission status: Time Limit Exceeded

Solution code:
import itertools
def main():
    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)

if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
#!/usr/bin/env python3
MOD = 10**9 + 7
n = int(input())
a = list(map(int, input().split()))
o = [[0] * (n + 1) for _ in range(100)]
x = [[0] * (n + 1) for _ in range(100)]
for b in range(100):
    for i in range(n):
        o[b][i + 1] += o[b][i]
        x[b][i + 1] += x[b][i]
        if a[i] >> b & 1 == 1:
            o[b][i + 1] += 1
        else:
            x[b][i + 1] += 1
li = []
nxt = 0
for b in range(100):
    c = 0
    for i in range(n):
        if a[i] >> b & 1 == 1:
            c += x[b][i]
        else:
            c += o[b][i]
    li.append((nxt + c) % 2)
    nxt = (nxt + c) // 2
ans = 0
for b in range(100)[::-1]:
    ans *= 2
    ans += li[b]
    ans %= MOD
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import sys
N = int(sys.stdin.readline())
A = list(map(int, sys.stdin.readline().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:
def main():
    # input
    import sys
    input = sys.stdin.readline
    MAX = 10**9+7

    n = int(input())
    a = tuple(map(int, input().split()))
    ans = 0
    for first, i in enumerate(a[:n-1]):
        for j in a[first:n]:
            ans += i^j
    print(ans%MAX)



    # calc


if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

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

b = 0
for i in range(n-1):
  for j in range(i+1,n):
    c = int(bin(int(bin(a[i]),0) ^ int(bin(a[j]),0)),0)
    b += c
  

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

Submission status: Time Limit Exceeded

Solution code:
MOD=10**9+7
def XOR(x,y):
  ans=bin(x^y)
  return int(ans,2)
n=int(input())
d=list(map(int,input().split()))
m=1
a=0
for j in range(n):
  for i in range(m,n):
    a+=XOR(d[j],d[i])
  m+=1
print(a%MOD)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

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

memo = {}

for i in range(N):
    for j in range(i+1,N):
        #print(str(i) + " : " + str(j))

        if (i,j) in memo:
            ans += memo[(i,j)]

        else:
            a = A[i]^A[j]
            memo[(i,j)] = a
            ans+= a

#print(ans)
print(ans%div)

Submission status: Time Limit Exceeded

Solution code:
num = int(input())
num_list = [int(x) for x in input().split(" ")]
taken_list = num_list.copy()
count = 0
for x in num_list:
    taken_list.remove(taken_list[0])
    for y in taken_list:
        count += x ^ y
print(count%(pow(10, 9)+7))

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
#O(nm) = O(60n)で解けるはず・・・！
n = int(input())
*l, = map(int,input().split())
#2進数の桁の出現数をカウントする。
lone = [0]*60
for i in range(n):
  m = l[i]
  tmpl = []
  for j in range(59,-1,-1):
    if m >= 2**j:
      m -= 2**j
      lone[j] += 1
ans = 0
for i in range(len(lone)):
  ans += 2**i*lone[i]*(n-lone[i])
print(ans%(10**9+7))

Submission status: Time Limit Exceeded

Solution code:
import itertools

mod = 10 ** 9 + 7
n = int(input())
a = list(map(int, input().split()))
l = [0 for i in range(len(str(bin(max(a)))) - 2)]
a = [bin(i)[2:] for i in a]

for i in a:
    for j, k in enumerate(i[::-1]):
        if k == "1":
            l[j] += 1
ans = 0
for i, j in enumerate(l):
    ans = (ans + (j * (n - j)) * (2 ** i)) % mod
print(ans)

Submission status: Time Limit Exceeded

Solution code:
#!/usr/bin/env python3
import sys

MOD = 1000000007  # type: int

def solve(N: int, A: "List[int]"):
    mLEN = len(format(max(A),'b'))
    bA = [[0]*N for _ in range(mLEN)]

    for i in range(N):
        a = format(A[i],'b').zfill(mLEN)
        for k in range(mLEN):
            bA[k][i] = a[k]

    answer = 0
    for keta in range(mLEN):
        zero = bA[keta].count('0')
        one = bA[keta].count('1')
        a = 0

        for i in range(N):
            if bA[keta][i] == '1':
                one -= 1
            else:
                zero -= 1

            if bA[keta][i] == '1':
                a += zero
            else:
                a += one

        answer += a*2**(mLEN-1-keta)
        answer %= MOD
    
    print(answer%MOD)
    return


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    A = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    solve(N, A)

if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
import itertools
N = input()
sum = 0
for v in itertools.combinations(sorted(list(map(int, input().split()))), 2):
  sum += v[0] ^ v[1]
print(sum % 1000000007)

Submission status: Time Limit Exceeded

Solution code:
N=int(input())
A=list(map(int,input().split()))
S=0
mod=10**9+7
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:
N = int(input())
A = list(map(int,input().split()))
lst = [0 for i in range(60)]
q = 0
for i in A:
    a = list(str(format(i, '08b')))
    a.reverse()
    for j in range(len(a)):
        lst[j]+=int(a[j])
for i in range(60):
    k = lst[i]
    l = k*(k-1)
    q+=(2**i)*l
p = sum(A)*(N-1)
print((p-q)%((10**9)+7))