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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
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()
    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]*(2**j))%mod
                else:
                    ans=(ans+num*(2**j))%mod
            x[j]+=z[j]
    print(ans)


if __name__ == "__main__":
    main()

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])
        ans = ans % (10 ** 9 + 7)
print(ans)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
A_list = input().split()
int_list = []
append = int_list.append
for v in A_list:
    append(int(v))

sum = 0

for m in range(N-1):
    for n in range(m+1,N):
        sum += (int_list[m]^int_list[n])

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

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
l=list(map(int,input().split()))
ans=0
MOD=10**9+7
la=[0 for i in range(61)]
for i in range(61):
    la[60-i]=sum([j//2**(60-i) for j in l])
    l=[j%2**(60-i) for j in l]
for num,i in enumerate(la):
    ans+=2**num*i*(n-i)
    ans%=MOD
print(ans)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

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

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

Submission status: Time Limit Exceeded

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

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

print(rst)

Submission status: Time Limit Exceeded

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

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

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

Submission status: Time Limit Exceeded

Solution code:
Q = 10**9 + 7
def main():
    N = int( input())
    A = list( map( int, input().split()))
    T = [[0]*60 for _ in range(N)]
    for i in range(N):
        a = A[i]
        for j in range(60):
            T[i][j] = a%2
            a //= 2
    ans = 0
    for i in range(60):
        plus = sum( [1 for j in range(N) if T[j][i] == 1])
        minus = N - plus
        ans = (ans + plus*minus%Q*pow(2,i,Q))%Q
    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]"):
    zeros = [0 for _ in range(60)]
    ones = [0 for _ in range(60)]
    for a in A:
        for i in range(60):
            if (a >> i) & 1:
                ones[i] += 1
            else:
                zeros[i] += 1

    res = 0
    for a in A:
        for i in range(60):
            if (a >> i) & 1:
                res += zeros[i] << i
                res %= MOD
            else:
                res += ones[i] << i
                res %= MOD
    if res % 2 == 1:
        res = res + MOD
    print(res // 2)
        
    return


# Generated by 1.1.5 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
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:
N = int(input())
lst = list(map(int,input().split()))
ans = 0
for i in range(N-1):
  for j in range(i+1,N):
    ans += lst[i] ^ lst[j]
print(ans % (10**9+7))

Submission status: Time Limit Exceeded

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

ans=0
C=int(1e9+7)

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

Submission status: Time Limit Exceeded

Solution code:
from collections import defaultdict
def XOR( arr, n): 
	sumi = 0
	for i in range(0, 60): 
		zc = 0
		oc = 0
		# Individual sum at each bit position 
		idsum = 0
		for j in range(0, n): 
			if (arr[j] % 2 == 0): 
				zc = zc + 1
			else: 
				oc = oc + 1
			arr[j] = int(arr[j] // 2) 
		# calculating individual bit sum 
		idsum = oc * zc * (1 << i) 
		# final sum	 
		sumi = (sumi%mod + idsum%mod)%mod; 
	return sumi%mod
mod = 10**9+7
n = int(input())
ls = list(map(int,input().strip().split()))
print(XOR(ls, n))

Submission status: Time Limit Exceeded

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


L = [0]*61

for i in range(N):
    b = bin(A[i])
    for j in range(2, len(b)):
        if b[j] == "1":
            L[len(b)-j-1] += 1

ans = 0
mod = 10**9+7

for i in range(61):
    c = 2**i*(L[i]*(N-L[i]))
    ans += c
    ans %= mod
    
print(ans)

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

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:
N = int(input())
A = input().split()

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

Submission status: Time Limit Exceeded

Solution code:
import itertools

n = input()
l = list(map(int,input().split()))
c = itertools.combinations(l,2)

s = 0

for v in c:
    s += v[0]^v[1]
    if(s >= 10**9+7):
        s = s % (10**9+7)

print(s)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
n, *a = map(int, open(0).read().split())
ans = 0
mod = 10 ** 9 + 7
for k in range(61):
	m = 1 << k
	c = 0
	for x in a:
		if m & x:
			c += 1
	ans += (c) * (n - c) * m
	ans %= mod
print(ans)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
a = list(map(int, input().split()))
bit = [[n,0] for i in range(60)]
b = []
ans = 0
mod = 10 ** 9 + 7
for i in a:
  b.append(bin(i)[2:])
for i in b:
  for k,j in enumerate(i[::-1]):
    j = int(j)
    if j:
      bit[k][0] -= 1
      bit[k][1] += 1
for k,(z,o) in enumerate(bit):
  ans = (ans + (z * o) * ((2 ** k) % mod)) % mod
print(ans)

Submission status: Time Limit Exceeded

Solution code:
#import sys
#input = sys.stdin.readline
Q = 10**9 + 7
def main():
    N = int( input())
    A = list( map( int, input().split()))
    T = [[0]*60 for _ in range(N)]
    for i in range(N):
        a = A[i]
        for j in range(60):
            T[i][j] = a%2
            a //= 2
    ans = 0
    for i in range(60):
        plus = sum( [1 for j in range(N) if T[j][i] == 1])
        minus = N - plus
        ans = (ans + plus*minus%Q*pow(2,i,Q))%Q
    print(ans)
        
if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
A = [int(i) for i in input().split()]
mod = 10**9 + 7
bits = [0]*61

ans = 0
for i, a in enumerate(A):
    for b in range(60):
        if (a >> b) & 1:
            ans += (2**b)*(i-bits[b])
            bits[b] += 1
        else:
            ans += (2**b)*bits[b]
    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())

mod = 10**9+7

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

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

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

Submission status: Time Limit Exceeded

Solution code:
from itertools import combinations

mod = 10**9 + 7

n = int(input())
a = [int(x) for x in input().split()]

# xor = [x^y for x, y in combinations(a, 2)]
# print(sum(xor) % mod)

res = 0
for x, y in combinations(a, 2):
    res += (x^y)
    res %= mod

print(res)

Submission status: Time Limit Exceeded

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

ans = ans % (INF + 7)
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import sys
sys.setrecursionlimit(10000000)
# input = sys.stdin.readline
from bisect import *
from collections import *
from heapq import *
import functools
import itertools
import math
INF = float('inf')
MOD = 10**9+7

M = 60
N = int(input())
A = [int(x) for x in input().split()]
f = [[0] * M for i in range(N+1)]
for i in range(N):
    a = A[i]
    for j in range(M):
        f[i+1][j] = f[i][j] + (a & 1)
        a >>= 1
ans = 0
for i in range(N):
    k = 1
    for j in range(M):
        if (A[i]>>j) & 1:
            ans += k * (N - i - 1 - f[N][j] + f[i+1][j])
        else:
            ans += k * (f[N][j] - f[i+1][j])
        ans %= MOD
        k <<= 1
        k %= MOD
print(ans)

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

Submission status: Time Limit Exceeded

Solution code:
#!/usr/bin/env python3
import sys
sys.setrecursionlimit(10**6)
input = sys.stdin.readline
MOD = 10**9 + 7

def pairORSum(arr, n) : 
    ans = 0
    for i in range(0, n) : 
        for j in range(i + 1, n) : 
            ans = ans + (arr[i] ^ arr[j]) 
            ans %= MOD
    return ans 
  
n = int(input())
a = [int(item) for item in input().split()]
  
print(pairORSum(a, n))

Submission status: Time Limit Exceeded

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

def pairORSum(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(pairORSum(nums, N) % (10**9+7))

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
A_list = list(input().split())
output = 0
for i in range(N):
  A =int(A_list[i])
  for j in range(i+1,N):
    B = int(A_list[j])
    output += int(bin(A^B),2)
    
    #print(i,j)
output %= 1000000000+7
print(output)

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%1000000007)

Submission status: Time Limit Exceeded

Solution code:
#import heapq
#import itertools
#import math
#import numpy as np
#import sys

N = int(input())
A = list(map(int, input().split()))
#S = [input() for _ in range(H)]
# T = [list(map(int,input().split())) for _ in range(N)]
# sys.exit()
#print(A)
ans = 0
for i in range(1,N) :
    for j in range(i+1, N+1) :
        #print(i,j)
        ans += A[i - 1] ^ A[j - 1]

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

Submission status: Time Limit Exceeded

Solution code:
def solve():
    from itertools import combinations
    
    mod = 10 ** 9 + 7
    N = int(input())
    A = tuple(map(int, input().split()))
    
    ans = sum(ai ^ aj for ai, aj in combinations(A, 2)) % mod
    
    print(ans)

solve()

Submission status: Time Limit Exceeded

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

# p[n]: 最下位ビットからnビット目が1になっている数字の個数
p=[0] * 60
for a in A:
  for i in range(60):
    p[i] += (a>>i)&1

#print(p)
ans = 0
for i in range(60):
  # nビット目同士を足したときの合計
  sn = (N-p[i]) * p[i]
  ans = (ans + (sn << i)) % MOD

print(ans)

Submission status: Time Limit Exceeded

Solution code:
def XOR( arr, n): 
	sumi = 0
	for i in range(0, 61): 
		zc = 0
		oc = 0
		# Individual sum at each bit position 
		idsum = 0
		for j in range(0, n): 
			if (arr[j] % 2 == 0): 
				zc = zc + 1
			else: 
				oc = oc + 1
			arr[j] = int(arr[j] // 2) 
		# calculating individual bit sum 
		idsum = oc * zc * (1 << i) 
		# final sum	 
		sumi = (sumi%mod + idsum%mod)%mod; 
	return sumi%mod
mod = 10**9+7
n = int(input())
ls = list(map(int,input().strip().split()))
print(XOR(ls, n))

Submission status: Time Limit Exceeded

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

print(sum)

Submission status: Time Limit Exceeded

Solution code:
def main():
    N = int(input())
    A = list(map(int, input().split()))
    sum = 0
    for i in range(N):
        for j in range(i,N):
            sum += A[i]^A[j]
    print(sum%1000000007)
 
if __name__ == '__main__':
    main()

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

Submission status: Time Limit Exceeded

Solution code:
# D - Xor Sum 4
N = input()
A = list(map(int, input().split()))

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

print(result % 1000000007)

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

mod = 10**9+7

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

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

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

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, n):
    c += a[i] ^ a[j]
print(c % (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
BIN=[0]*N
for h in range(N):
    BIN[h]=bin(A[h])[2:].zfill(60)

for i in range(N-1):
    for j in range(i+1,N):
        ans+=A[i]^A[j]
print(ans%P)

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

    kari = 0
    for j,b in enumerate(B):
        if b[i] == "1":
            kari+=(N-j-1)-(rui[N]-rui[j+1])
        else:
            kari+=(rui[N]-rui[j+1])
    #print(kari)
    ans+=kari*(2**(59-i))
    ans%=mod
print(ans)

Submission status: Time Limit Exceeded

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

total = 0
for i in range(n) :
  for j in range(i+1,n) :
    total += ais[i]^ais[j]
    if 100000 < total : total = total % m
    
print(total)

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()
    A = lmis()
    maxA = max(A)
    ans = 0
    for i in count():
        b = 1<<i
        if b > maxA:
            break
        S1 = sum(bool(a & b) for a in A)
        S0 = N - S1
        ans += (S1*S0) * (b%N1097)
        ans %= N1097
    print(ans)

main()

Submission status: Time Limit Exceeded

Solution code:
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)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

ans = 0
for i in range(n-1):
  for j in range(i + 1, 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()))
count = 0

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

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

Submission status: Time Limit Exceeded

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

xorsum = 0;

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


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

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
A = list(int(a) for a in input().split())

ans = 0
for i in range(N-1):
    for j in range(i+1, 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()))


final_ans = 0
num = 1000000007
a.sort()

for i in range(n-1):
    if i != 0:
        if a[i] == a[i-1]:
            final_ans += ans
            final_ans %= num
            continue
        else:
            ans = 0
            for j in range(i+1, n):
                ans += (a[i] ^ a[j])
                ans %= num
            final_ans += ans
            final_ans %= num
    else:
        ans = 0
        for j in range(i+1, n):
            ans += (a[i] ^ a[j])
            ans %= num
        final_ans += ans
        final_ans %= num

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

m = int(10 ** 9 + 7)

print(s % m)

Submission status: Time Limit Exceeded

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

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

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


if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

Solution code:
def XOR( arr, n): 
	sumi = 0
	for i in range(0, 64): 
		zc = 0
		oc = 0
		# Individual sum at each bit position 
		idsum = 0
		for j in range(0, n): 
			if (arr[j] % 2 == 0): 
				zc = zc + 1
			else: 
				oc = oc + 1
			arr[j] = int(arr[j] // 2) 
		# calculating individual bit sum 
		idsum = oc * zc * (1 << i) 
		# final sum	 
		sumi = (sumi%mod + idsum%mod)%mod; 
	return sumi%mod
mod = 10**9+7
n = int(input())
ls = list(map(int,input().strip().split()))
print(XOR(ls, n))

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
As = list(map(int, input().split()))
r = 0
#for i in range(N):
#  for j in range(i+1, N):
#    r = (r+(As[i]^As[j]))%1000000007
for i in range(64):
  n = 0
  for A in As:
    if A&(1<<i) != 0:
      n += 1
  #print(i, n)
  d = n*(N-n)%1000000007
  d2 = (d<<i)%1000000007
  r = (r+d2)%1000000007
print(r)

Submission status: Time Limit Exceeded

Solution code:
'''import math
def count_total(s1,s2):
    f = 0
    s = 0
    cnt = 0
    while s2>0:
        #print(bin(s1).replace("0b",""),bin(s2).replace("0b",""))
        #print(s1,s2)
        f = s1 ^ s2
        s = s1 & s2
        s1 = f
        s2 = s<<1
        cnt+=1
    return cnt
t = int(input())
for _ in range(0,t):
    s1 = int(input(),2)
    s2 = int(input(),2)
    if(len(str(s2))<=500): 
        print(count_total(s1,s2))
    else:
        print(-1)
'''

n=int(input())
a=list(map(int,input().split(' ')))
sum=0
m=1000000007
for i in range(0,62):
    z=0
    o=0
    cr=0
    for j in range(0,n):
        if(a[j]%2==0):
            z+=1
        else:
            o+=1
        a[j]//=2
    
    cr = (((o%m * z%m)%m)%m * (1<<i)%m)%m
    sum+=cr
print(sum%1000000007)

Submission status: Time Limit Exceeded

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

c = [0] * 60

const = 10 ** 9 + 7

ans = 0

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

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

print(ans % const)

Submission status: Time Limit Exceeded

Solution code:
from itertools import combinations
from operator import xor

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

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

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])
    
    kari = 0
    for j in range(N):
        b = B[j]
        if b[i] == "1":
            kari+=(N-j-1)-(rui[N]-rui[j+1])
        else:
            kari+=(rui[N]-rui[j+1])
    #print(kari)
    ans+=kari*(2**(59-i))
    ans%=mod
print(ans)

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)):
            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:
MOD = 10 ** 9 + 7
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 % MOD)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
A = [int(i) for i in input().split()]
from itertools import combinations as comb
ans = 0
for v in comb(A,2):
    ans += v[0]^v[1]
print(ans % (10**9+7))

Submission status: Time Limit Exceeded

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


from itertools import combinations

ans = 0
for _a, _b in combinations(a, 2):
    ans += _a ^ _b

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

Submission status: Time Limit Exceeded

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

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

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

Submission status: Time Limit Exceeded

Solution code:
import itertools


N = int(input())
A = list(map(lambda x: int(x),input().split()))
x = itertools.combinations(A,2)
y = map(lambda i:i[0]^i[1], x) 
print(sum(y)%(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 A[i+1:]:
        ans += A[i] ^ j

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

Submission status: Time Limit Exceeded

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

t = 0
m = 7 + 10**9 
for i in range(n-1):
  for j in range(i+1,n):
    temp = 0
    temp = int(format(a[i], 'b')) + int(format(a[j], 'b'))
    temp_s = str(temp).replace('2', '0')
    t += int(temp_s, 2)
    t = t%m
print(t)

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%1000000007)

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

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

    b = [[0] * 60]

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

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


if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
from itertools import combinations

mod = 10**9 + 7

n = int(input())
a = [int(x) for x in input().split()]

xor = [x^y for x, y in combinations(a, 2)]
print(sum(xor) % mod)

# res = 0
# for x, y in combinations(a, 2):
#     res += (x^y) % mod

# print(res)

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
a=list(map(int,input().split()))
M=10**9+7
s=0
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())
mod = 10**9 + 7
a = list(map(int, input().split()))
b = [sum(1 for x in a if x&(1<<i)) for i in range(60)]
ans = 0
for i in range(60):
  t = b[i]*(n-b[i])
  m = (1<<i)%mod
  ans = (ans + t*m%mod)%mod
print(ans)

Submission status: Time Limit Exceeded

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

if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

counts = [0] * 60
for a in A:
    for i in range(60):
        counts[i] += (a >> i) % 2

power2 = [1]
for _ in range(59):
    power2.append((power2[-1] * 2) % MOD)


ans = sum(c * (N - c) * power2[i] for i, c in enumerate(counts))

print(ans % MOD)