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: Wrong Answer

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

sum = 0
for i in range(0, 32):
    zc = 0
    oc = 0

    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)

    idsum = oc * zc * (2 ** i)

    sum = sum + idsum

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

Submission status: Wrong Answer

Solution code:
import numpy as np

n=int(input())



a= list(map(int,input().split()))
a=np.array(a,np.int64)

print(a)
max=60
mod=10**9+7
ans=0
cnt1=0
cnt0=0


for i in range(max):
    new_a=(a>>i & 1)

    cnt1=np.count_nonzero(new_a)
    cnt0=n-cnt1
    ans=(ans+cnt1*cnt0*(2**i))%mod
    cnt1=0
    cnt0=0
print(ans)

Submission status: Wrong Answer

Solution code:
def solve():
    n = int(input())
    a = list(map(int,input().split()))
    v = [0 for _ in range(70)]
    mx = 0
    mod = 1e9+7
    for i in a:
        for j in range(70):
            if i%2:
                mx = max(mx,j)
            v[j]+=i%2
            i//=2
    ans = 0
    base = 1
    for j in range(mx+1):
        ans += base*v[j]*(n-v[j])
        base*=2
    print(int(ans%mod))

if __name__ == "__main__":
    solve()

Submission status: Wrong Answer

Solution code:
import numpy as np

n = int(input())
lst = np.array([int(i) for i in input().split()])
mod = 10 ** 9 + 7
c = []

while lst.any():
    c1 = sum(lst & 1)
    c.append(c1 * (n - c1))
    lst >>= 1
print(sum([v * 2 ** i for i, v in enumerate(c)]))

Submission status: Wrong Answer

Solution code:
def solve():
    n = int(input())
    a = list(map(int,input().split()))
    v = [0 for _ in range(70)]
    mx = 0
    mod = 1e9+7
    for i in a:
        for j in range(70):
            if i%2:
                mx = max(mx,j)
            v[j]+=i%2
            i//=2
    ans = 0
    base = 1
    for j in range(mx+1):
        ans += base*v[j]*(n-v[j])
        ans%=mod
        base*=2
        base%=mod
    print(int(ans))

if __name__ == "__main__":
    solve()

Submission status: Wrong Answer

Solution code:
def solve():
    n = int(input())
    a = list(map(int,input().split()))
    v = [0 for _ in range(70)]
    mod = 1e9+7
    for i in a:
        for j in range(70):
            v[j]+=i%2
            i//=2
    ans = 0
    base = 1
    for j in range(70):
        ans += base*v[j]*(n-v[j])
        ans%=mod
        base*=2
        base%=mod
    print(int(ans))

if __name__ == "__main__":
    solve()

Submission status: Wrong Answer

Solution code:
def solve():
    n = int(input())
    a = list(map(int,input().split()))
    v = [0 for _ in range(70)]
    mod = 1e9+7
    ans = sum(a)*n//1%mod
    for i in a:
        for j in range(70):
            v[j]+=i%2
            i//=2
    for i in a:
        base = 1
        for j in range(70):
            if i%2==1:
                ans = (ans+mod-(base*v[j])%mod)%mod
            i//=2
            base*=2
            base%=mod
    print(int(ans))

if __name__ == "__main__":
    solve()

Submission status: Wrong Answer

Solution code:
def solve():
    n = int(input())
    a = list(map(int,input().split()))
    v = [0 for _ in range(70)]
    mod = 1e9+7
    ans = sum(a)*n//1%mod
    for i in a:
        for j in range(62):
            v[j]+=i%2
            i//=2
    for i in a:
        base = 1
        for j in range(62):
            if i%2==1:
                ans = (ans+mod-(base*v[j])%mod)%mod
            i//=2
            base*=2
            base%=mod
    print(int(ans))

if __name__ == "__main__":
    solve()

Submission status: Wrong Answer

Solution code:
N = int(input())
L = [0 for i in range(60)]
As = list(map(int, input().split()))
mod = 1000000007
ans = 0
 
for i in range(N):
    tmp = format(As[i], 'b').zfill(60)
    for j in range(60):
        L[j] += int('1')
 
acc = 1
tmps = []
for i in range(60):
    tmps.append(acc)
    acc = acc * 2 % mod
 
for i in range(60):
    tmp = tmps[-(i + 1)]
    a = L[i] % mod
    b = (N - a) % mod
    ans += (tmp * a * b) % mod
 
ans = ans % mod
print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
a = list(map(int, input().split()))
import numpy as np
c = np.array([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 = np.array(list('0' * (len_c - len(b)) + b)).astype('int64')
  c += binlist 
for i in range(len_c):
  ans += 2 ** (len_c-i-1) * c[i] * (n - c[i])
  ans %= mod
print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
n=int(input())
a=list(map(int,input().split()))
MOD=10**9+7
m=max(a)
s=bin(m)
l=len(s[2:])
h=[0]*l
for i in range(n):
    buf=a[i]
    for j in range(l):
        h[j]+=buf%2
        buf//=2
#print(h)
count=0
for i in range(n):
    buf=a[i]
    for j in range(l):
        k=pow(2,j,MOD)
        if buf%2==1:
            count+=k*(n-h[j]-i)
        else:
            count+=k*h[j]
        count%=MOD
        h[j]-=buf%2
        buf//=2
        if buf==0:
            break
    #print(count)
print(count)

Submission status: Wrong Answer

Solution code:
N = int(input())
L = [0 for i in range(60)]
As = list(map(int, input().split()))
mod = 1000000007
ans = 0

for i in range(N):
    tmp = format(As[i], 'b').zfill(60)
    for j in range(60):
        L[j] += 1

acc = 1
tmps = []
for i in range(60):
    tmps.append(acc)
    acc = acc * 2 % mod

for i in range(60):
    tmp = tmps[-(i + 1)]
    a = L[i] % mod
    b = (N - a) % mod
    ans += (tmp * a * b) % mod

ans = ans % mod
print(ans)

Submission status: Wrong Answer

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

MOD = 10**9+7
N = int(input())
A = list(map(int, input().split()))
B = [0]*60
C = [0]*60

for i in range(60):
    for j in range(N):
        if (A[j]>>i)&1 == 0:
            C[i] += 1
        else:
            B[i] += 1

ans = 0
for i in range(60):
    ans += B[i]*C[i]*2**i%MOD
print(ans)

Submission status: Wrong Answer

Solution code:
import numpy as np

n = input()
l = np.array(list(map(int,input().split())) ,dtype='uint64')

s = 0

for i in range(61):
    z=0
    o=0
    for n in l:
        if (n >> np.uint64(i))%2 == 0:
            z += 1
        else:
            o += 1
    s += (z*o)*(2**i)

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

Submission status: Wrong Answer

Solution code:
MOD = int(1e9) + 7

n = int(input())
a = list(map(int, input().split()))
ans = 0
for b in range(60)[::-1]:
    ans <<=1
    print(ans)
    c = sum(a[i]>>b & 1 for i in range(n))
    ans = (ans + c*(n-c))%MOD
print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
from collections import defaultdict as dd

def main():
  N = int(input())
  A = list(map(int, input().split()))
  MOD = 10 ** 9 + 7
  ones = dd(int)
  for a in A:
    for i in range(60):
      if (a >> i) & 1 == 1:
        ones[i] += 1

  res = 0
  for a in A:
    for i in range(60):
      if (a >> i) & 1 == 0:
        res += ones[i] * 2 ** i
      else:
        res += (N-ones[i]+1) * 2 ** i
        ones[i] -= 1
      res %= MOD
  
  print(res)
if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
from collections import defaultdict as dd

def main():
  N = int(input())
  A = list(map(int, input().split()))
  MOD = 10 ** 9 + 7
  ones = dd(int)
  for a in A:
    for i in range(60):
      if (a >> i) & 1 == 1:
        ones[i] += 1

  res = 0
  for a in A:
    for i in range(60):
      if (a >> i) & 1 == 0:
        res += ones[i] * 2 ** i
      else:
        res += (N-ones[i]) * 2 ** i
        ones[i] -= 1
      res %= MOD
  
  print(res)
if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
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])) %(1e9+7)
  return ans

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

Submission status: Wrong Answer

Solution code:
N = int(input())
L = [[0 for i in range(N)] for j in range(60)]
As = list(map(int, input().split()))
mod = 1000000007
ans = 0

for i in range(N):
    tmp = format(As[i], 'b').zfill(60)
    for j in range(60):
        L[j][i] = int(tmp[j])

Submission status: Wrong Answer

Solution code:
mod = int(1e9 + 7)
N = int(input())
A = list(map(int, input().split()))
S = 0
j = 0
while A != []:
  m = 0
  n = len(A)
  k = []
  for i in range(n):
    if A[i] % 2 == 1:
      m += 1
    A[i] //= 2
    if A[i] == 0:
      k.append(i)
  for g in range(len(k)):
    A.remove(A[k[len(k)-1-g]])
  S += (m * (N - m)) * (2 ** j)
  j += 1
S %= mod
print(S)

Submission status: Wrong Answer

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

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

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

Submission status: Wrong Answer

Solution code:
import numpy as np

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

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

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

Submission status: Wrong Answer

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

answer=0
sum=0
base=0
for j in range(N):
    A[j]=str(bin(A[j])).rjust(60,"0")
B=list(itertools.combinations(A,2))

for i in range(len(B)):
    for k in range(60):
        if B[i][0][59-k]=="0" and B[i][1][59-k]=="1":
            base+=2**k
        elif B[i][0][59-k]=="1" and B[i][1][59-k]=="0":
            base+=2**k
        elif B[i][0][59-k]=="b" and B[i][1][59-k]=="1":
            base+=2**k
        elif B[i][0][59-k]=="1" and B[i][1][59-k]=="b":
            base+=2**k
    sum+=base
    base=0
print(sum%(10**9+7))

Submission status: Wrong Answer

Solution code:
import numpy as np
def sumXOR( arr,  n): 
      
    sum = 0
    for i in range(0, 62): 
  
       
        zc = 0
        oc = 0
           
        
        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) 
          
           
          
        idsum = oc * zc * (1 << i) 
   
      
        sum = sum + idsum;  
      
    return sum
n = int(input())
arr = np.array([int(a) for a in input().split()])
ans = sumXOR(arr,n)
print(ans%1000000007)

Submission status: Wrong Answer

Solution code:

mod = 10**9 + 7


def main():
    n = int(input())
    A = [int(a) for a in input().split()]
    ans = 0
    for k in range(60):
        a = 0
        for i in range(n):
            a += A[i] & 1
            A[i] <<= 1
        da = (1 << k) % mod
        da *= (n - a)*a
        da %= mod
        ans += da
        ans %= mod
    print(ans)


main()

Submission status: Wrong Answer

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

def Base_10_to_n(X, n):
    X_dumy = X
    out = ''
    while X_dumy>0:
        out = str(X_dumy%n)+out
        X_dumy = int(X_dumy/n)
    return out

L = len(Base_10_to_n(A[-1],2))

cnt = [0] * L
ans = 0
for i in range(1,N):
	tmp = A[0]^A[i]
	ans += tmp
	tt = Base_10_to_n(tmp,2).rjust(L,"0")
	for j in range(L):
		if tt[j] == "1":
			cnt[j] += 1
T= ans
ans %= mod

for i in range(1,N):
	TT = T
	tmp=0
	t = A[0]^A[i]
	tt = Base_10_to_n(t,2).rjust(L,"0")
	ttt = list(map(int, tt))
	for j in range(L):
		if ttt[j] == 1:
			tmp -= 2**(L-1-j) * cnt[j]
			tmp += 2**(L-1-j) * (N-cnt[j])
	TT += tmp
	ans += TT
	ans %= mod

ans *= pow(2,mod-2, mod)
ans %= mod

print(ans)

Submission status: Wrong Answer

Solution code:
mod = 10**9+7

def Base_10_to_n(X, n):
    X_dumy = X
    out = ''
    while X_dumy>0:
        out = str(X_dumy%n)+out
        X_dumy = int(X_dumy/n)
    return out

N = int(input())
A = list(map(int, input().split()))
A_max = max(A)
L = len(Base_10_to_n(A_max, 2))
bit_cnt = [0] * L
wa = 0
for i in range(1,N):
	tmp = A[0] ^ A[i]
	wa += tmp
	wa %= mod
	tmp_bit = Base_10_to_n(tmp,2).rjust(L,"0")
	for j in range(L):
		if tmp_bit[j] == "1":
			bit_cnt[j] += 1
add = [0] * L
for i in range(1,N):
	tmp = A[0]^A[i]
	tmp_bit = Base_10_to_n(tmp,2).rjust(L,"0")
	for j in range(L):
		if tmp_bit[j] == "1":
			add[j] += (N-bit_cnt[j]*2)

wa *= N
wa %= mod

for i in range(L):
	tmp = add[i]*(2**(L-1-i))
	if tmp < 0:
		tmp *= (-1)
		tmp %= mod
		tmp = mod - tmp

	wa += tmp
	wa %= mod

wa *= pow(2,mod-2,mod)
wa %= mod

print(wa)

Submission status: Wrong Answer

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

def sumXOR(arr, n, MOD):
    s = 0
    for i in range(0, 62):
        zc = 0
        oc = 0
        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)
        idsum = oc * zc * (1 << i)
        idsum %= MOD
        s = s + idsum
        s %= MOD
    return s

print (sumXOR(A, N, 10**9 + 7))

Submission status: Wrong Answer

Solution code:
import numpy as np
mod = 10 ** 9 + 7

if __name__ == "__main__":
	N = int(input())
	L = list(map(int, input().split()))
	L = np.array(L, np.int64)
	ans = 0
	for i in range(60):
		A = L % 2
		L = L // 2
		ans += np.sum(A) * (N - np.sum(A)) * (2 ** i) % mod
	print(ans % mod)

Submission status: Wrong Answer

Solution code:
def getXor(x, y): 
    return ((x | y) & (~x | ~y))

def determineResult(num, num_arr, counter, result, length):
  if counter > length:
    print(result)
    return

  for num2 in num_arr[counter:]:
    result += getXor(int(num), int(num2))

  old_count = counter
  counter += 1
  determineResult(num_arr[old_count], num_arr, counter, result, length)

if __name__ == "__main__":
    count = int(input())
    num_string = input()
    num_arr = num_string.split()
    determineResult(num_arr[0], num_arr, 1, 0, count-1)

Submission status: Wrong Answer

Solution code:
import numpy as np

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

ans = 0
for i in range(N - 1):
    xj = np.array([A[i] for i in range(i + 1, N)])
    ans += sum(A[i] ^ xj)

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

Submission status: Wrong Answer

Solution code:
import sys

def solve():
    readline = sys.stdin.buffer.readline
    mod = 10 ** 9 + 7
    n = int(readline())
    a = list(map(int, readline().split()))
    ls = [0] * 40
    for v in a:
        tt = bin(v)
        for i in range(min(len(tt)-2, 40)):
            ls[i] += int(tt[-i-1])
    t = 0
    for i in range(len(ls)):
        t += pow(2, i, mod) * (n - ls[i]) * ls[i]
        t %= mod
    print(t)


if __name__ == '__main__':
    solve()

Submission status: Wrong Answer

Solution code:
import sys

def solve():
    readline = sys.stdin.buffer.readline
    mod = 10 ** 9 + 7
    n = int(readline())
    a = list(map(int, readline().split()))
    ls = [0] * 35
    for v in a:
        tt = bin(v)
        for i in range(min(len(tt)-2, 35)):
            ls[i] += int(tt[-i-1])
    t = 0
    for i in range(len(ls)):
        t += pow(2, i, mod) * (n - ls[i]) * ls[i]
        t %= mod
    print(t)


if __name__ == '__main__':
    solve()

Submission status: Wrong Answer

Solution code:
n = int(input())
t = list(map(int,input().split()))
ans = 0

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

print(ans)

Submission status: Wrong Answer

Solution code:
import numpy as np
mod = 10 ** 9 + 7

if __name__ == "__main__":
	N = int(input())
	L = list(map(int, input().split()))
	L = np.array(L)
	ans = 0
	for i in range(60 + 2):
		A = L % 2
		L = L // 2
		ans += np.sum(A) * (N - np.sum(A)) * (2 ** i) % mod
	print(ans % mod)

Submission status: Wrong Answer

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

def sumXOR(arr, n, MOD):
    sum = 0
    for i in range(0, 62):
        zc = 0
        oc = 0
        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)
        idsum = oc * zc * (1 << i)
        idsum %= MOD
        sum = sum + idsum
        sum %= MOD
    return sum

print (sumXOR(A, N, 10**9 + 7))

Submission status: Wrong Answer

Solution code:
def sumXOR( arr,  n): 
      
    sum = 0
    for i in range(0, 65): 
    
        #  Count of zeros and ones 
        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     
        sum = sum + idsum;  
      
    return sum%(1000000007)
  
  
  
# driver function  
sum = 0
n = int(input())
arr = list(map(int,input().split()))
sum = sumXOR(arr, n); 
print (sum)

Submission status: Wrong Answer

Solution code:
import numpy as np
N = int(input())

A=np.array([int(i) for i in 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: Wrong Answer

Solution code:
import numpy as np
mod = 10 ** 9 + 7

if __name__ == "__main__":
	N = int(input())
	L = list(map(int, input().split()))
	L = np.array(L)
	ans = 0
	for i in range(60 + 1):
		A = L % 2
		L = L // 2
		ans += np.sum(A) * (N - np.sum(A)) * (2 ** i) % mod
	print(ans % mod)

Submission status: Wrong Answer

Solution code:
def sumXOR( arr,  n): 
      
    sum = 0
    for i in range(0, 61): 
  
        #  Count of zeros and ones 
        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     
        sum = (sum + idsum);  
      
    return sum%(1000000007)
  
  
  
# driver function  
sum = 0
n = int(input())
arr = list(map(int,input().split()))
sum = sumXOR(arr, n); 
print (sum)

Submission status: Wrong Answer

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

print(A.count(1)*A.count(0))

Submission status: Wrong Answer

Solution code:
mod=10**9 + 7
#print(bin(9))
N=int(input())
A=list(map(int,input().split()))
A=[bin(i)[2:] for i in A]
#print(A)
nowdata=[0 for i in range(60)]
data=[0 for i in range(60)]

#print(A)

for i in range(N-1):
    S=A[i]
    #print(nowdata)
    for a in range(len(S)):
        nowdata[a]+=int(S[-a-1])
    S=A[i+1]
    for a in range(len(S)):
        if S[-a-1]=="0":
            data[a]+=nowdata[a]
        else:
            data[a]+=i+1-nowdata[a]


num=0
#print(data)
for i in range(60):
    num+=data[i]* (2**i)
    num%=mod

print(num)

Submission status: Wrong Answer

Solution code:
N=int(input())
L=list(map(int,input().split()))
for i in range(N):
  L[i]='{0:061d}'.format(int(format(L[i],"b")))
print(L)
d=0
for i in range(61):  
  c=0
  for j in range(N):    
    c+=int(L[j][-i-1])    
  d+=(c*(N-c))*2**i  
print(d%(10**9+7))

Submission status: Wrong Answer

Solution code:
def sumXOR( arr,  n): 
  sum = 0
  for i in range(0, 60): 
    #  Count of zeros and ones 
    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     
    sum += idsum
    sum %= 1000000007
      
  return sum
  
n = int(input())
arr = [int(i) for i in input().split()]
# driver function  
sum=0
sum = sumXOR(arr, n); 
print (int(sum % (1000000007)))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

count = 0
for i in range(N):
    for j in range(N):
        if i < j:
            print(A[i], A[j])
            count += (A[i] ^ A[j])

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

Submission status: Wrong Answer

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

def sumXOR(arr, n, MOD):
    sum = 0
    for i in range(0, 64):
        zc = 0
        oc = 0
        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)
        idsum = oc * zc * (1 << i)
        sum = sum + idsum
        sum %= MOD
    return sum

print(sumXOR(A, N, 10**9 + 7))

Submission status: Wrong Answer

Solution code:
import numpy as np

MAX_DIGIT = 60
MOD = 1e9 + 7

N = int(input())
A = np.array([int(a) for a in input().split()])

answer = 0
for d in range(MAX_DIGIT + 1):
    A, r = (A>>1), A % 2
    s = int(r.sum())
    base = (1<<d) % MOD #this may be key
    answer += (base * s * (N - s)) % MOD

answer %= MOD
print(answer)

Submission status: Wrong Answer

Solution code:
N = int(input())
A = list(map(int, input().split()))
MOD = 10 ** 9 + 7
ones = [0] * 60
zeros = [0] * 60
for i in range(N):
  x = A[i]
  x = bin(x)[2:]
  x = x.zfill(60)
  j = 0
  for j in range(59, -1, -1):
    if x[j] == '0':
      zeros[j] += 1
    else:
      ones[j] += 1
# print(ones)
# print(zeros)

res = 0
for i in range(N):
  x = A[i]
  x = bin(x)[2:]
  x = x.zfill(60)
  for j in range(60):
    if x[-j - 1] == '0':
      res += ones[-j - 1] * 2 ** j
      res &= MOD
      zeros[-j - 1] -= 1
    else:
      res += zeros[-j - 1] * 2 ** j
      res %= MOD
      ones[-j - 1] -= 1
  
print(res)

Submission status: Wrong Answer

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

def sumXOR(arr, n, MOD):
    sum = 0
    for i in range(0, 64):
        zc = 0
        oc = 0
        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)
        idsum = oc * zc * (1 << i)
        idsum %= MOD
        sum = sum + idsum
        sum %= MOD
    return sum

print(sumXOR(A, N, 10**9 + 7))

Submission status: Wrong Answer

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

for i in range(l-1):
    for j in range(i+1,l):
        k = A[i]^A[j]
        c = c+k

ans = c&(10**9+6)
print(c)

Submission status: Wrong Answer

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


def read_ints():
    return list(map(int, read().split()))


def read_a_int():
    return int(read())


def read_matrix(H):
    '''
    H is number of rows
    '''
    return [list(map(int, read().split())) for _ in range(H)]


def read_map(H):
    '''
    H is number of rows
    文字列で与えられた盤面を読み取る用
    '''
    return [read()[:-1] for _ in range(H)]


def read_col(H, n_cols):
    '''
    H is number of rows
    n_cols is number of cols

    A列、B列が与えられるようなとき
    '''
    ret = [[] for _ in range(n_cols)]
    for _ in range(H):
        tmp = list(map(int, read().split()))
        for col in range(n_cols):
            ret[col].append(tmp[col])

    return ret


n = 60
N = read_a_int()
A = read_ints()
MOD = 10**9 + 7
A = [a % MOD for a in A]


def ret_binary(a: int):  # 逆順で返すことに注意
    tmp = bin(a)[2:]
    ret_r = [0] * n
    for i, t in enumerate(tmp[::-1]):
        ret_r[i] = int(t)
    return ret_r


def calc_sum(a, n_1_ls, n_1_max):
    '''
    aはxorしてから和を取りたい数
    n_1_lsは各桁の1の数
    n_1_maxは最大1は何個あり得るか
    '''
    a_binary = ret_binary(a)
    ret = 0
    for i, (aa, n_1) in enumerate(zip(a_binary, n_1_ls)):
        if aa == 0:
            ret += (((2**i) % MOD) * (n_1 % MOD)) % MOD
        else:
            ret += (((2**i) % MOD) * ((n_1_max - n_1) % MOD)) % MOD
    return ret


def add_koko(lsa, lsb):
    return [a + b for a, b in zip(lsa, lsb)]


n_1_max = 0
n_1_ls = [0] * n
ans = 0
a_pre = A[N - 1]
for i in range(N - 2, -1, -1):
    a = A[i]
    n_1_ls = add_koko(n_1_ls, ret_binary(a_pre))
    n_1_max += 1
    tmp = calc_sum(a, n_1_ls, n_1_max)
    ans += tmp
    ans %= MOD
    a_pre = a

print(ans)

Submission status: Wrong Answer

Solution code:
from heapq import heappush, heappop, heapify
from collections import deque, defaultdict, Counter
import itertools
from itertools import permutations, combinations, accumulate
import sys
import bisect
import string
import math
import time
from fractions import gcd
#import random


def I(): return int(input())


def MI(): return map(int, input().split())


def LI(): return [int(i) for i in input().split()]


def LI_(): return [int(i)-1 for i in input().split()]


def StoI(): return [ord(i)-97 for i in input()]


def ItoS(nn): return chr(nn+97)


def input(): return sys.stdin.readline().rstrip()


def show(*inp, end='\n'):
    if show_flg:
        print(*inp, end=end)


YN = ['No', 'Yes']
MOD = 10**9+7
inf = float('inf')
IINF = 10**10
l_alp = string.ascii_lowercase
u_alp = string.ascii_uppercase
ts = time.time()
sys.setrecursionlimit(10**6)
nums = ['1', '2', '3', '4', '5', '6', '7', '8', '9', '10']


# show_flg = True
show_flg = False


def sumXOR(arr, n):
    _sum = 0
    for i in range(0, 60):

        #  Count of zeros and ones
        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
        # idsum %= MOD
        _sum = _sum + idsum
        _sum %= MOD

    return _sum


def main():
    N = I()
    A = list(MI())
    print(sumXOR(A, len(A)))


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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):
    print(x, y, x^y)
    res += x^y
    res %= mod

print(res)

Submission status: Wrong Answer

Solution code:
from heapq import heappush, heappop, heapify
from collections import deque, defaultdict, Counter
import itertools
from itertools import permutations, combinations, accumulate
import sys
import bisect
import string
import math
import time
from fractions import gcd
#import random


def I(): return int(input())


def MI(): return map(int, input().split())


def LI(): return [int(i) for i in input().split()]


def LI_(): return [int(i)-1 for i in input().split()]


def StoI(): return [ord(i)-97 for i in input()]


def ItoS(nn): return chr(nn+97)


def input(): return sys.stdin.readline().rstrip()


def show(*inp, end='\n'):
    if show_flg:
        print(*inp, end=end)


YN = ['No', 'Yes']
MOD = 10**9+7
inf = float('inf')
IINF = 10**10
l_alp = string.ascii_lowercase
u_alp = string.ascii_uppercase
ts = time.time()
sys.setrecursionlimit(10**6)
nums = ['1', '2', '3', '4', '5', '6', '7', '8', '9', '10']


# show_flg = True
show_flg = False


def sumXOR(arr, n):
    _sum = 0
    for i in range(0, 60):

        #  Count of zeros and ones
        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
        idsum %= MOD
        _sum = _sum + idsum
        _sum %= MOD

    return _sum


def main():
    N = I()
    A = list(MI())
    print(sumXOR(A, len(A)))


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

Solution code:
# An efficient Python3 program to compute 
# sum of bitwise OR of all pair 

# Returns sum of bitwise OR 
# of all pairs 
def sumXOR( arr, n): 
	
	sum = 0
	for i in range(0, 64): 

		# Count of zeros and ones 
		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	 
		sum = sum + idsum; 
	
	return sum



# driver function 
n = int(input())
arr = list(map(int,input().split()))

sum = sumXOR(arr, n);
e = 1e9+7
print (int(sum%e))

Submission status: Wrong Answer

Solution code:
import time

def add(a,b):
  return (a ^ b) % 1000000007

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

start = time.time()
###
ans2 = [add(A[y],A[x]) for y in range(N) for x in range(y+1,N)]
print(sum(ans2)%1000000007)
###
elapsed_time = time.time() - start
print ("2重for文time:{0}".format(elapsed_time) + "[sec]")


start = time.time()
###
ans2 = [(A[y] ^ A[x]) % 1000000007 for y in range(N) for x in range(y+1,N)]
print(sum(ans2)%1000000007)
###
elapsed_time = time.time() - start
print ("2重for文time:{0}".format(elapsed_time) + "[sec]")